Skip to content

Commit

Permalink
adds newValue and oldValue for canjs/canjs#4656
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer authored and matthewp committed Aug 8, 2019
1 parent d083eb9 commit 3b8a3dd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
36 changes: 25 additions & 11 deletions can-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ define.makeDefineInstanceKey = function(constructor) {
}

this.prototype.dispatch({
type: "can.keys",
action: "can.keys",
type: "can.keys", // TODO: Remove in 6.0
target: this.prototype
});
};
Expand Down Expand Up @@ -470,8 +471,12 @@ make = {
computeObj.oldValue = newVal;

map.dispatch({
type: prop,
target: map
action: "set",
key: "prop",
target: map,
newValue: newVal,
oldValue: oldValue,
type: prop, // TODO: Remove in 6.0
}, [newVal, oldValue]);
}
};
Expand Down Expand Up @@ -547,11 +552,15 @@ make = {
var dispatched;
setData.call(this, newVal);

dispatched = {
patches: [{type: "set", key: prop, value: newVal}],
type: prop,
target: this
};
dispatched = {
patches: [{type: "set", key: prop, value: newVal}],
target: this,
action: "set",
newValue: newVal,
oldValue: current,
key: prop,
type: prop // TODO: Remove in 6.0
};

//!steal-remove-start
if(process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -1141,13 +1150,18 @@ define.expando = function(map, prop, value) {
if(!map[inSetupSymbol]) {
queues.batch.start();
map.dispatch({
type: "can.keys",
target: map
action: "can.keys",
target: map,
type: "can.keys" // TODO: Remove in 6.0
});
if(Object.prototype.hasOwnProperty.call(map._data, prop)) {
map.dispatch({
type: prop,
action: "add",
target: map,
newValue: map._data[prop],
oldValue: undefined,
key: prop,
type: prop, // TODO: Remove in 6.0
patches: [{type: "add", key: prop, value: map._data[prop]}],
},[map._data[prop], undefined]);
} else {
Expand Down
9 changes: 7 additions & 2 deletions define-helpers/define-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,20 @@ var defineHelpers = {
delete instanceDefines[prop];
queues.batch.start();
this.dispatch({
type: "can.keys",
action: "can.keys",
type: "can.keys", // TODO: Remove in 6.0
target: this
});
var oldValue = this._data[prop];
if(oldValue !== undefined) {
delete this._data[prop];
//delete this[prop];
this.dispatch({
type: prop,
action: "delete",
key: prop,
newValue: undefined,
oldValue: oldValue,
type: prop, // TODO: Remove in 6.0
target: this,
patches: [{type: "delete", key: prop}],
},[undefined,oldValue]);
Expand Down
10 changes: 9 additions & 1 deletion list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ var DefineList = Construct.extend("DefineList",
patches = [{type: "splice", insert: newVal, index: index, deleteCount: 0}];
dispatched = {
type: how,
action: "splice",
insert: newVal,
index: index,
deleteCount: 0,
patches: patches
};

Expand All @@ -148,7 +152,10 @@ var DefineList = Construct.extend("DefineList",
patches = [{type: "splice", index: index, deleteCount: oldVal.length}];
dispatched = {
type: how,
patches: patches
patches: patches,
action: "splice",
index: index, deleteCount: oldVal.length,
target: this
};
//!steal-remove-start
if(process.env.NODE_ENV !== 'production') {
Expand All @@ -161,6 +168,7 @@ var DefineList = Construct.extend("DefineList",
this.dispatch(how, [ newVal, index ]);
}
} else {
console.log("list dispatching", attr, newVal, oldVal);
this.dispatch({
type: "" + attr,
target: this
Expand Down
6 changes: 5 additions & 1 deletion map/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ canTestHelpers.devOnlyTest("can.hasKey and can.hasOwnKey (#303) (#412)", functio
assert.equal(vm[hasOwnKeySymbol]("parentDerivedProp"), false, "vm.hasOwnKey('parentDerivedProp') false");

assert.equal(vm[hasOwnKeySymbol]("anotherProp"), false, "vm.hasOwnKey('anotherProp') false");

var map = new DefineMap({expandoKey: undefined});
assert.equal(map[hasKeySymbol]("expandoKey"), true, "map.hasKey('expandoKey') (#412)");
});
Expand Down Expand Up @@ -1633,3 +1633,7 @@ QUnit.test("'*' wildcard type definitions that use DefineMap constructors works
var foo = map.get( "foo" );
assert.ok(foo instanceof MyType);
});

require("can-reflect-tests/observables/map-like/instance/on-event-get-set-delete-key")("DefineMap", function(){
return new DefineMap();
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"can-symbol": "^1.0.0"
},
"devDependencies": {
"can-reflect-tests": "<0.3.0",
"can-reflect-tests": "^1.0.0",
"can-test-helpers": "^1.1.4",
"detect-cyclic-packages": "^1.1.0",
"jshint": "^2.9.1",
Expand Down

0 comments on commit 3b8a3dd

Please sign in to comment.