-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Improve CPs ergonomics by changing caching strategy #79
Improve CPs ergonomics by changing caching strategy #79
Conversation
…-spellcheck Correct a few typos in more-friendly-cp-caching.md
i like this approach, upgrade path seems kinda rough though:( |
@stefanpenner I added a 4th idea involving decorators that can be a real option. Having the |
True |
I personally like the idea that calling the setter would clear the cache and mark as dirty. I believe we can and likely should fix this within the 2.x cycle. I propose the following path:
Following the above path, we satisfy both our SemVer requirements and our requirement that 3.0.0 not have any non-deprecated changes. |
If I hear another positive voice from anyone else on the core I'll start a spike of the implementation. |
@rwjblue I'm unconvinced we can actually make this change in app CP as docs/guides/learning hazards would likely prevail not to mention addons that want to work in both worlds, now need to do special magic, but i do think we can use the decorators as a signal for a refresh. If we can do the switch on a per CP basis, it could work though. This would also enable the required changes for decorators to opt-in. |
FWIW, this exact path was followed by the
Our guides are already properly versioned, and our API docs are being actively worked on to support this versioning. I believe the current state is a much larger learning hazzard than providing a helpful deprecation + education process.
The majority of new features in the last few cycles have also implemented a nice polyfill-like addon that addon authors can use to get the new behavior across versions. This has been a pretty successful technique, and includes things like
Sure, I do not disagree, but I think that the path forward is fairly simple/straightforward as I laid out in #79 (comment). |
@rwjblue the polyfil approach, and enabling on a per computed property basis would address my concerns totally. |
Ya, this is a great idea. Using the polyfill would already allow upgrading on a per CP basis, but we could also add an option flag to be used to force the setters return value to be cached (the existing/older behavior) even when the feature flag is enabled. Something like: goldenRation: computed('height', {
cacheSetterReturnValue: true,
get() {
return this.get('height') * 1.618;
},
set(_, value) {
return this.set('height', value / 1.618);
} I would envision the feature flag would simply change the default value of |
@stefanpenner The behaviour of the new CPs is more or less a subset of the original one. I might be wrong, but seems compatible enough. Also, what about something like foo: computed('bar', 'baz', {
get() { /* ... */ },
set() { /* ... */ }
}).uncachedSetter(); // Enables the new behaviour when globally disabled
foo: computed('bar', 'baz', {
get() { /* ... */ },
set() { /* ... */ }
}).cachedSetter(); // Restores the old behaviour when globally enabled This perhaps is pollyfillable. |
I agree that the proposed approach would make the lessen the learning curve, though I'm quite sure there is a lot of code out there that relies on the current behavior. If we decide not to change the behavior but want to improve user education, one idea would be to use the function.toString() approach mentioned in development builds to warn on setters that don't contain |
@lukemelia - Yes, agreed, even if we do not want to change the go forward behavior (which I personally do want to change) we should make development ergonomics better. |
Yes, this. I know for a fact, large swaths of code depend on this (accidentally or intentionally). Many scenarios the get/set are not symmetric, and changes this would be quite painful. Incrementally upgrading via new syntax and on a per-cp basis could mitigate these concerns. I would love to get @tomdale / @wycats input early though. |
I absolutely agree. We have a few macros that have very complex CP logic for validating and marshalling data. In some cases we end up having to make a 3rd function that just calculates the return value so it's reusable for |
This bit me again today lol. Here's my example in case it helps. I've actually been afraid to use get/set in the past because its behavior was always surprising to me - I suspect it's exactly because of this situation. ES6 getter/setter docs suggest we don't use a return value during I ended up with this silly code
I also tried I'd rather have done this, with no return value:
|
@caseywatts do you think https://guides.emberjs.com/v3.0.0/object-model/computed-properties/#toc_setting-computed-properties could be updated to make the behaviour clearer? |
@locks good thinking!
|
We reviewed this RFC today in the core team meeting and realized that these are the semantics that we ended up adopting during the Decorators RFC. In classic usage, the old semantics still apply, but in native classes the new semantics take over. Given it's been implemented, we decided to move this RFC into FCP to close. Thanks for working on it @cibernox! |
🙌🏻 |
Thank you for helping push this forward! |
Link to rendered