-
-
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
RFC: Improved CP Syntax #11
Conversation
No mention of |
@jayphelps I suspect it will continue to work for the I suppose the explicitly writable case without a pojo, just a FN, on set, should check arity and either call FN with 2 arguments (like today's setter CP) or stomp the CP. This should be handled by my compatibility mode and I suspect this will be deprecated for 2.0 |
|
||
# Motivation | ||
|
||
Today, the setter variant of CP's is both confusing, and looks scary as sinn. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/sinn/sin/
Very happy about this proposal. 👍 |
49a6001
to
3ff96da
Compare
3ff96da
to
1ab7ff4
Compare
I don't know how I missed this. There is something I can do to help from ember-cpm? Maybe betatest this syntax now? function EmberCPM_computed(){
var args = Array.prototype.slice(arguments, 0, -2);
var opts = Array.prototype.slice(arguments.length - 1)
args.push(function(){
if (arguments.length > 1){
opts.set.apply(this, arguments);
} else {
opts.get.apply(this, arguments);
}
});
return Ember.computed(this, args)
} |
Honestly you could just pr it to ember :) let iterate in a pr and release as soon as it's good :) |
I've got a PR in the works. Should be opening it in a couple of hours |
Ok, I've got something working now :) One part of the RFC that's going to cause some problems for people (myself included)
I take this to mean that if I'd written something like this today (which results in a writable computed property) var MyType = Ember.Object.extend({
a: 6,
b: 12,
half: Ember.computed('a', 'b', function (key, val, oldVal) {
if (arguments.length < 2) {
return 0.5*(this.get('a') + this.get('b'));
}
else {
this.setProperties({
a: val/2,
b: val/2
});
return val;
}
})
}); Once this proposed improvement is made, the function (3rd argument passed to Is there any reason we can't continue to support both?
|
@igorT This could be a good replacement for |
@truenorth agreed re: not breaking the existing setter approach. deprecating it would reasonable/helpful if possible. |
Yes please. I love this idea!! |
I'd much rather see this, a la ember-auto, because as it currently stands, it's very repetitive to specify the dependent properties both in the call to fullName: Ember.computed('firstName', 'lastName', {
get: function(firstName, lastName) {
return firstName + ' ' + lastName;
},
// ...
}); |
Dogpile! https://github.com/jayphelps/ember-computed-smart-property fullName: Ember.computed.smartProperty({
get: function () {
return this.get('firstName') + ' ' + this.get('lastName');
}
}) |
To support this functionality with less code for properties that are only getters and not setters, but in a backwards-compatible way, maybe an argument could be added to the fullName: function(firstName, lastName) {
return firstName + ' ' + lastName;
}.property('firstName', 'lastName', {args: true}), Or even a whole new fullName: function(firstName, lastName) {
return firstName + ' ' + lastName;
}.properties('firstName', 'lastName'), Or the way ember-computed-smart-property does it, which is also awesome! |
fullName: function(firstName, lastName) {
return firstName + ' ' + lastName;
}.properties('firstName', 'lastName'), is interesting when a 1:1 between DK and inputs exists forsure. This type of CP macro would make a great community add-on. The specific RFC existed to primarily remove the arity check from the current CP's as that is obviously mega terrible. |
I like the general idea, but am concerned about it creating such a difference between I'm not sure how That concern aside, 👍 |
@awj The |
No description provided.