-
Notifications
You must be signed in to change notification settings - Fork 396
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
Different keypath resolutions between template and Ractive.set #1958
Comments
I remember struggling with this too. Basically restricted references are only for templates and api calls always go from the root of the instance down. The caveat to this is apis that find data ( I think there are two things to do:
|
I just bumped into this too. I was wondering about two things:
|
I think it's quite ok to leave the getters/setters like this, always relative to the root. Once you know it it's ok, and changing it would probably break lots of users code out there. On the other hand, issuing a warning would definitely be great when you use @evs-chris hi, I think that would mislead the user even more in the sense that they'll think the getters/setters will behave like references in template. Which they do not, and would just add confusion. On the other hand, changing/extending the getter/setters behavior would break lots of existing code. Therefore, I'm definitely more in favor of just issuing a warning rather than tweaking the getter/setters. |
I like the idea of shouting a warning (or even throwing an error) too - I'm really into the idea of using errors and warnings as a way to guide people in these potentially confusing situations towards documentation that explains design decisions. That way people get a clearer understanding of how Ractive thinks about the world. Of course, that's predicated on there being decent documentation! So 👍 to ractivejs/v0.x#208. @evs-chris yes, keypath join helper might be a good idea: // could work like path.resolve in node...
Ractive.join( 'foo', 'bar' ); // 'foo.bar'
Ractive.join( 'foo', './bar' ); // 'foo.bar'
Ractive.join( 'foo', '../bar' ); // 'bar'
Ractive.join( 'foo', 'bar', '~/baz' ); 'baz'
Ractive.join( 'items', 4 ); 'items.4'
// but could also shortcut the Ractive.getNodeInfo use case - this...
Ractive.join( element, 'active' );
// could be equivalent to this:
Ractive.join( Ractive.getNodeInfo( element ).keypath, 'active' ); |
Hi,
Something like
set('~/foo', 'bar')
actually sets a variable named~/foo
while on the other hand templates consider~/foo
to be thefoo
of the root scope.It leads to akward situations like this:
http://jsfiddle.net/2wkrx8ye/1/
The text was updated successfully, but these errors were encountered: