Comparing version 4.0.0-pre.5 to 4.0.0-pre.6
@@ -540,4 +540,4 @@ var List = require('can-list'); | ||
var PATCHES = [ | ||
[ { deleteCount: 2, index: 0 } ], | ||
[ { index: 0, insert: ["A", "B"], deleteCount: 0 } ] | ||
[ { deleteCount: 2, index: 0, type: "splice" } ], | ||
[ { index: 0, insert: ["A", "B"], deleteCount: 0, type: "splice" } ] | ||
]; | ||
@@ -559,1 +559,51 @@ | ||
}); | ||
QUnit.test("can.onInstancePatches basics", function(){ | ||
var People = List.extend({}); | ||
var calls = []; | ||
function handler(obj, patches) { | ||
calls.push([obj, patches]); | ||
} | ||
People[canSymbol.for("can.onInstancePatches")](handler); | ||
var list = new People([1,2]); | ||
list.push(3); | ||
list.attr("count", 8); | ||
People[canSymbol.for("can.offInstancePatches")](handler); | ||
list.push(4); | ||
list.attr("count", 7); | ||
QUnit.deepEqual(calls,[ | ||
[list, [{type: "splice", index: 2, deleteCount: 0, insert: [3]} ] ], | ||
[list, [{type: "set", key: "count", value: 8} ] ] | ||
]); | ||
}); | ||
QUnit.test("can.onInstanceBoundChange basics", function(){ | ||
var People = List.extend({}); | ||
var calls = []; | ||
function handler(obj, patches) { | ||
calls.push([obj, patches]); | ||
} | ||
People[canSymbol.for("can.onInstanceBoundChange")](handler); | ||
var people = new People([]); | ||
var bindHandler = function(){}; | ||
canReflect.onKeyValue(people,"length", bindHandler); | ||
canReflect.offKeyValue(people,"length", bindHandler); | ||
People[canSymbol.for("can.offInstanceBoundChange")](handler); | ||
canReflect.onKeyValue(people,"length", bindHandler); | ||
canReflect.offKeyValue(people,"length", bindHandler); | ||
QUnit.deepEqual(calls,[ | ||
[people, true ], | ||
[people, false ] | ||
]); | ||
}); |
@@ -73,17 +73,22 @@ /* jshint -W079 */ | ||
_triggerChange: function (attr, how, newVal, oldVal) { | ||
Map.prototype._triggerChange.apply(this, arguments); | ||
// `batchTrigger` direct add and remove events... | ||
var index = +attr; | ||
var index = +attr, patches; | ||
// Make sure this is not nested and not an expando | ||
if (!~(""+attr).indexOf('.') && !isNaN(index)) { | ||
if(bubble.isBubbling(this, "change")) { | ||
canEvent.dispatch.call(this, { | ||
type: "change", | ||
target: this | ||
}, [attr, how, newVal, oldVal]); | ||
} | ||
if (how === 'add') { | ||
canEvent.dispatch.call(this, how, [newVal, index]); | ||
patches = [{insert: newVal, index: index, deleteCount: 0, type: "splice"}]; | ||
canEvent.dispatch.call(this, {type: how, patches: patches}, [newVal, index]); | ||
canEvent.dispatch.call(this, 'length', [this.length]); | ||
canEvent.dispatch.call(this, 'can.onPatches', [[{insert: newVal, index: index, deleteCount: 0}]]); | ||
canEvent.dispatch.call(this, 'can.onPatches', [patches]); | ||
} else if (how === 'remove') { | ||
canEvent.dispatch.call(this, how, [oldVal, index]); | ||
patches = [{index: index, deleteCount: oldVal.length, type: "splice"}]; | ||
canEvent.dispatch.call(this, {type: how, patches: patches}, [oldVal, index]); | ||
canEvent.dispatch.call(this, 'length', [this.length]); | ||
canEvent.dispatch.call(this, 'can.onPatches', [[{index: index, deleteCount: oldVal.length}]]); | ||
canEvent.dispatch.call(this, 'can.onPatches', [patches]); | ||
} else { | ||
@@ -93,2 +98,4 @@ canEvent.dispatch.call(this, how, [newVal, index]); | ||
} else { | ||
Map.prototype._triggerChange.apply(this, arguments); | ||
} | ||
@@ -95,0 +102,0 @@ |
{ | ||
"name": "can-list", | ||
"version": "4.0.0-pre.5", | ||
"version": "4.0.0-pre.6", | ||
"description": "Observable lists", | ||
@@ -50,3 +50,3 @@ "homepage": "http://canjs.com", | ||
"can-queues": "<2.0.0", | ||
"can-map": "^4.0.0-pre.0" | ||
"can-map": "^4.0.0-pre.5" | ||
}, | ||
@@ -53,0 +53,0 @@ "devDependencies": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
69758
1307
0
21
Updatedcan-map@^4.0.0-pre.5