Skip to content
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

Receives old value #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default function newComputed() {

var func;
if (config.set) {
func = function(key, value) {
func = function(key, value, oldValue) {
if (arguments.length > 1) {
return config.set.call(this, key, value);
return config.set.call(this, key, value, oldValue);
} else {
return config.get.call(this, key);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/new-computed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ test('can specify a setter', function(assert) {
assert.equal(get(object, 'last'), 'jackson');
});

test('receives the old value', function(assert) {
var object = Ember.Object.extend({
first: null,
last: null,
old: null,
name: computed({
set: function(key, value, oldValue) {
set(this, 'old', oldValue);
return value;
}
})
}).create();

set(object, 'name', 'elaine jackson');
assert.equal(get(object, 'old'), null);

set(object, 'name', 'jacquie jackson');
assert.equal(get(object, 'old'), 'elaine jackson');

});

test('has a copy of all the cp helpers on the Ember.computed namespace', function(assert) {
for (let key in Ember.computed) {
assert.equal(computed[key], Ember.computed[key], `${key} exists on both`);
Expand Down