Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid field access : index #3

Open
zabojad opened this issue Aug 19, 2019 · 2 comments
Open

Invalid field access : index #3

zabojad opened this issue Aug 19, 2019 · 2 comments

Comments

@zabojad
Copy link

zabojad commented Aug 19, 2019

I cannot use the lodash build macro in one of my page component file. Here is the macro debug output:

/usr/local/lib/haxe/std/neko/_std/Type.hx:220: characters 17-24 : Invalid field access : index
/usr/local/lib/haxe/std/haxe/macro/Printer.hx:114: characters 39-41 : Called from
/usr/local/lib/haxe/std/neko/_std/Array.hx:275: characters 12-18 : Called from
/usr/local/lib/haxe/std/haxe/macro/Printer.hx:118: characters 20-38 : Called from
<builtin>:1: character 0 : Called from
/usr/local/lib/haxe/std/haxe/macro/Printer.hx:318: characters 82-86 : Called from
/usr/local/lib/haxe/std/haxe/macro/Printer.hx:144: characters 44-75 : Called from
/Users/thomasfetiveau/wksp_myproj/myproj-apps-rn59/.haxelib/haxe-lodash/git/./lib/lodash/Lodash.hx:177: characters 11-44 : Called from
src/myproj/view/page/MenuPage.hx:314: characters 1-7 : Called from
Aborted

And here is the code of the page:

typedef MenuPageViewState = {
	data:Array<Int>,
}
typedef MenuPageViewProps = {
	> react.native.navigation.NavProps,
	intl:IntlShape,
}
@:build(lib.lodash.Lodash.build())
class MenuPageView extends ReactComponentOf<MenuPageViewProps,MenuPageViewState> {
	static var styles = MenuPageStyles.value;
	function new(p){
		super(p);
		this.state = {data:[for(i in -10...10) i]};
	}

	private var _list:FlatList<Int>;
	function onListRef(r:FlatList<Int>){
		if(r==null) return;
		_list=r;
	}

	function keyExtractor(item:Int,_):String{
		return Std.string(item);
	}

	function scrollToOffset(v:Float){
		trace('scrollToOffset',v);
		if(_list==null) return;
		_list.scrollToOffset({animated:true,offset:v});
	}

	@:throttle(1000, {leading:true,trailing:false})
	function onEndReached(_){
		trace('onEndReached');
		setState({data:state.data.concat([for(i in state.data.length-10...state.data.length) i])});
	}
	
	function renderItem(v:{item:Int}){
		return null;
	}
	
	override function render() {
		return jsx('
			<>
				<View style=${styles.page}>
					<View style=${styles.titleView}>
						<Text style=${styles.title}>
							<FormattedMessage id="account_page_menus" mode=${Uppercase} />
						</Text>
					</View>
					<FlatList 
						ref=${onListRef}
						keyExtractor=${keyExtractor}
						style=${styles.scroller} 
						contentContainerStyle=${styles.scrollerContent}
						renderItem=${renderItem}
						onEndReached=${onEndReached}
						data=${state.data}
					/>
				</View>
			</>
		');
	}
}

Any idea?

@zabojad
Copy link
Author

zabojad commented Aug 19, 2019

@kiroukou it seems the issue happens because of the _ argument placeholder:

@:throttle(1000, {leading:true,trailing:false})
function onEndReached(_){
	// ...
}

Is there any way to support it?

kiroukou added a commit that referenced this issue Sep 3, 2019
@kiroukou
Copy link
Owner

kiroukou commented Sep 3, 2019

This one is a little bit complicated.
The current behaviour makes the parameters received by the throttled method sent to the "original" methods. Most of the time, we want the parameters to be passed.
Could we consider that an "unspecified" parameter, named after "_", could be ommited ?

I did an attempt to fix that scenario in the commit 5eb390b

Can you have a look in your test case ? (I did something very bad, a blind commit without testing... since I don't have the environment setup at the moment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants