-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
RFC: Improved CP Syntax #9527
RFC: Improved CP Syntax #9527
Conversation
Mostly looks fantastic Afew points:
Will review again when I'm back online later tonight Great work! |
d6498ff
to
d896a66
Compare
Great. I've cached the arity of the setter function, since is the only one we care about its number of arguments. |
Ok, it fails because I am raising a deprecations where I use the same function as getter and setter. |
such yay :-) |
59312cc
to
f67b259
Compare
27 files later ... green! |
f67b259
to
b3fa639
Compare
Rebased and squashed. |
this looks fantastic, @wycats / @tomdale does this need to be feature flagged? @krisselden i would love your review |
@cibernox good job !! |
b3fa639
to
ce0a26b
Compare
@stefanpenner / @wycats / @tomdale I really hope not need to flag this. |
If tests pass, it would be great to include it in the next release, it's not a breaking change, and the deprecation messages will prepare for the 2.0.0 ! |
All new features need to be feature flagged. That's how the train cycle works. The flag is removed by the build tools once a "Go" decision is reached. |
Also, just to be clear, the deprecations from #9489 should land without feature flags. |
The problem is that many of this changes are in not where the functionality is defined but where it's used (and its used all over the place). Options: 1 - What I can do is split this PR in 2, one containing the new syntax behind a FFlag and another updating ember internals to use it. The second will be on hold until the functionality passes the go/no-go decision (how many weeks can take that?). Downside is that we will be testing the feature but not using it in ember itself. Also the PR put on hold will need to be rebased often to keep it aligned with small changes that will mess with it. 2 - Flag every place of ember internals where we are using setter CPs to have both versions. Downsides are: A lot of work and a lot of churn in the code. I think option 1 is still more reasonable. |
@cibernox - Only public API changes need to be flagged. If we use the new syntax internally, but only expose the new API if the flag is "turned on" that should be just fine. We can upgrade everything to the new syntax internally and only expose the new public API when the flag is enabled. |
I'll try to figure out how do that later today. I don't even know if its possible since ember uses the public api internally too. 2014-11-13 17:51 GMT+00:00 Robert Jackson [email protected]:
|
ce0a26b
to
0d81ee9
Compare
@rwjblue I've been trying a few approaches to feature flag the changes in public API this and still use internally the getter/setter syntax but none of them seams acceptable. Code would be ugly as hell. The problem is that we use internally the same public api ( If we really want to feature flag this, we I would go with the idea of expose the new version behind a feature flag but don't use it internally until it receives a "go" decision. |
0d81ee9
to
51366f3
Compare
Updated. This PR only contains the new syntax behind a feature flat. I created another branch applying the new syntax all over the place that will stay on hold until this passes the go/no-go decision. |
51366f3
to
11eac28
Compare
@stefanpenner This is the next natural step after #9489 This adds the new syntax behind a feature flag, but does not refactor the internals, because it would be massively complicated to do it while the new syntax is flagged. I have another branch with all the CP's in ember using the new syntax, waiting. |
@krisselden r? |
Landed! @cibernox - Thank you for your hard work on this one! |
Yay! |
What's a good strategy for addons with CPs that want to support ember < 1.12.0 but avoid deprecation warnings when >= ? I thought the new syntax was backwards compatible. |
Use my ember-new-computed addon. ;) |
Sorry if this question is in the wrong place...
Many of my computeds don't require a setter (they're read only).
|
@jamiechong If your a computed property don't have a setter the syntax you're using is perfectly ok 😁 . Only properties with setter have to use the new syntax. |
@cibernox - Okay - that's good to know. Thanks! |
Depredations from ember data were fixed a while ago. What version of ED are you using? |
Aha that was it. Was using 1.0.0-beta.16.1 (bower update doesn't update ember-data automatically it seems). Using 1.0.0-beta.17 and now they've gone away. Thanks - I'm still new to Ember :) |
You're welcome. Remember to check the irc #emberjs channel and the slack community. |
why the need to return |
@samselikoff Because CPs memoize whatever you return from get/set. |
In theory we could memoize the value passed in by default if you don't provide an explicit return value. However, this closes the door on CPs that can ever become |
I think the return value is the least un-expected memoized value. |
Totally agree, I was just trying to enumerate the constraints for @samselikoff. |
I see. I do feel this is an additional conceptual jump for newbies, though. It's exposing internal implementation details to the public API ("why should I care that CPs memoize the return value? I just want to change some other attributes.") Would it make more sense to require users to |
given that:
I believe that returning the result from the setter makes sense. The memoizing is an merely an enhancement CP's provide. We should really also make
a PR exists to do this. |
IMHO, the whole concept of setter CP's is a non-newbie concept. Getter only CP's (the default) are massively more common, and solve the majority of use cases for non-expert users. |
it's also extremely easy to learn ;) |
I agree, but it isn't on the list of things needed to know to make an awesome application... |
Sounds good all. Thx for explaining :) |
Definitely makes more sense after reading the discussion. Thanks for posting the question: @samselikoff. I literally ran into this issue yesterday and had a look at ember internals to understand before seeing the rest of this discussion. Could we update the example given in the blog (http://emberjs.com/blog/2015/05/13/ember-1-12-released.html) and future 1.12 guides to show the explicit 'return' for setters? Or somewhere document this? |
yah I agree that guide needs to be updated, I keep looking at it for reference and forgetting about the return. |
Guys, I just got a very weird bug because my setter method does not return value. |
I've answered the same question a three times already, so that means that clearly we need to better document this somewhere, since people finds it confusing. The idea is that computed properties should be as aligned as possible to regular ES5 getters/setters (and just wrap the getter in a caching layer). ATM, your need to return a value from the setter function in order to be able to cache the value. I start to think that this should be changed to be less surprising, but I don't think it will be possible/easy until we have decorators. What we can do however is clarify this point in the documentation, although I'm not sure what is the best place to do it. |
This PR implements emberjs/rfcs#11
It is based on #9489, which will be merge soon. Also supersedes #9478 (I'll close it in a minute).
There is no feature flags for this because it mostly a refactor that does not change current semantics. It could be done though.
Tasks
Done in #9489
cacheable
orreadOnly
to the constructor. No extrictly necessary, but is not used anywhere in the code since 2012 and simplifies things.cacheable()
andreadOnly()
. Are the default.Done in this PR:
Steps in futures PRs: