-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf9b423
commit 49a6001
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
- Start Date: 2014-19-30 | ||
- RFC PR: (leave this empty) | ||
- Ember Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
Improve computed property syntax | ||
|
||
# Motivation | ||
|
||
Today, the setter variant of CP's is both confusing, and looks scary as sin. | ||
(To many concepts must be taught and it is to easy to screw it up.) | ||
|
||
# Detailed design | ||
|
||
today: | ||
------ | ||
|
||
```js | ||
fullName: Ember.computed('firstName', 'lastName', function(key, value) { | ||
if (arguments.length > 1) { | ||
var names = value.split(' '); | ||
this.setProperties({ | ||
firstName: names[0], | ||
lastName: names[1] | ||
}); | ||
return value; | ||
} | ||
|
||
return this.get('firstName') + ' ' + this.get('lastName'); | ||
}); | ||
``` | ||
|
||
Tomorrow: | ||
--------- | ||
|
||
```js | ||
fullName: Ember.computed('firstName', 'lastName', { | ||
get(keyName) { | ||
return this.get('firstName') + ' ' + this.get('lastName'); | ||
}, | ||
|
||
set(keyName, fullName) { | ||
var names = fullName.split(' '); | ||
|
||
this.setProperties({ | ||
firstName: names[0], | ||
lastName: names[1] | ||
}); | ||
|
||
return fullName; | ||
} | ||
}); | ||
``` | ||
|
||
|
||
Notes: | ||
------ | ||
|
||
* we should likely keep `Ember.computed(fn);` as shorthand for getter only | ||
Migration: | ||
* Also, `get` xor `set` variants would also be possible. | ||
* `{ get() { } }` is es6 syntax for `{ get: function() { } )` | ||
|
||
Migration | ||
--------- | ||
|
||
* 1.x support both, detect new behaviour by testing if the last arg is not null and typeof object | ||
* 1.x+1 deprecate if last arg is a function and its arity is greater then 1 | ||
|
||
|
||
# Drawbacks | ||
|
||
N/A | ||
|
||
# Alternatives | ||
|
||
N/A | ||
|
||
# Unresolved questions | ||
|
||
* do setters with the new syntax get the 3rd arg of `oldValue` provided? |