-
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
Wrap nested objects with setters #110
Comments
I think that already works today. |
nvm, it works for arrays and not "strings" http://jsfiddle.net/ygQd6/ |
Yeah, there was a discussion about this on Hacker News - I'll copy and paste what I wrote there: It's definitely something I've thought about. There are a few reasons I still prefer ractive.set( keypath, value ), which I'll try and articulate:
As for emn13's suggestion of Knockout-style observables, my own experience is that having to inherit from custom observable classes gets cumbersome quite quickly. But different strokes for different folks! So at the moment I don't foresee this ever being the default setting. But maybe there could be a |
3 & 5 don't concern me much- I don't see much reason to ever set properties that are neither referenced in the template nor present in the initial data. For all the rest, I totally agree! There are lots of situations where I want to use .set() instead of an implicit setter, and if only for performance I would never consider getting rid of that option (and I'm not a big fan of Knockout observables, either). But I like this as an additional option for interacting with the data. A |
Okay, I've had a go at this. Fair warning: I've only tested it in Chrome, and I haven't done any tests to see what the performance impact is (if you do But I've tried it out and it seems to do the trick. Let me know how you get on. As mentioned earlier in the thread, this will only work with properties that are already extant on the model (if you can think of a non-hacky workaround, I'm all ears). |
…apped once, even if a property is referenced by multiple ractives on multiple keypaths
Magic mode is now documented on the wiki - closing this issue |
Inspired by https://github.com/Rich-Harris/Ractive/issues/74
Just like arrays are wrapped so that array mutator methods are replaced by versions that properly update ractive data, it would be nice if all nested property objects had getter/setter methods defined, so that
ractive.data.someProperty = 'foo'
would act the same asractive.set('someProperty','foo')
,ractive.data.someProperty.subProperty = 'foo'
would act the same asractive.set('someProperty.subProperty','foo')
, etc.The .set and .get functions would still be around for those who need to ensure support for older browsers.
This would allow one to extract a subset of the data model to pass off to some other part of the application that doesn't need access to the entire ractive and still have changes properly reflected (which one currently can do with arrays, but nothing else).
The text was updated successfully, but these errors were encountered: