-
-
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
default readOnly CP #9290
Comments
Nice, looking forward to this. |
Tertiary to this, and maybe this is fixed in a newer version... but I've noticed this behavior in components: willNotSurvive: function() {
return this.get('a') + this.get('b');
}.property('a', 'b'),
// magic here: adding key, value arguments seem to keep the computed property
// from being overwritten
willSurvive: function(key, value) {
return this.get('a') + this.get('b');
}.property('a', 'b'), When you set them both, {{my-component willSurvive=foo willNotSurvive=foo}} Relevant JSBin: http://emberjs.jsbin.com/dowah/1/edit?html,js,output |
works as expected, but yes odd for someone not aware. |
Whoa! That's expected? TIL. I was genuinely surprised by this behavior. Generally, when I think of a function in JavaScript, I don't expect it to behave differently based on the presence of argument variables. I guess I just wouldn't expect something to be analyzing that part of the function to see if it's somehow different. Then again, I never really liked the "implicit injection" thing with Angular, either. JSHint actually hates what I did above, because I'm not using Seems like something like what you're proposing could solve this:
But it still isn't very descriptive as to why I'm making it "writable". Really I'm trying to make it "untrampleable" or "unoverwriteable". |
this feature was meant as an interim step to allow backwards compatibility, but we never transitioned out. I hope to get us out for 2.0. plan: // writable
fullName: Ember.computed('firstName', 'lastName', {
get: function(key) {
return this.get('firstName') + ' ' + this.get('lastName');
},
set: function(key, value) {
var name = value.split(' ');
this.setProperties({
firstName: name[0],
lastName: name[1]
});
}
}); // readOnly
fullName: Ember.computed('firstName', 'lastName', {
get: function(key) {
return this.get('firstName') + ' ' + this.get('lastName');
}
}
}); // writable
fullName: Ember.computed('firstName', 'lastName', {
get: function(key) {
return this.get('firstName') + ' ' + this.get('lastName');
}
}
}).writable(); // writable for now, future readOnly
fullName: Ember.computed('firstName', 'lastName', function(key) {
return this.get('firstName') + ' ' + this.get('lastName');
}
); // writable always
fullName: Ember.computed('firstName', 'lastName', function(key) {
return this.get('firstName') + ' ' + this.get('lastName');
}).writable(); |
+1 |
@stefanpenner Have you seen this? #9489 |
In my understanding, if a computed property is initialized with an object with CPs are the piece of the codebase I understand better. I can this things in that very PR if you want so you can focus in HTMLBars. |
@cibernox nice! I will review this weekend. https://github.com/emberjs/rfcs/pull/12/files is the RFC, core decided we need to do some last refinements before it gets merged. But i would love help implementing. |
@cibernox also, your feedback on the RFC would be wonderful |
After reading the RFC, I think my PR is perfectly aligned. Steps done:
Steps pending:
|
@cibernox nice, do you mind moving your checklist to your PR, (it will make it easier to track) I have added it to my queue to review.:) |
Regarding: key as first argument. I've been digging all around GH issues and the ember source trying to figure out why the key is the first argument. Perhaps it is needed internally; but what would a typical user typically be using the key for? Could we hide the key in |
@devinrhode2 the descriptor can be shared between multiple properties, and |
@devinrhode2 - Think of computed property generators like |
this is likely not going to happen due to making stubbing mocking in tests trickier |
The text was updated successfully, but these errors were encountered: