can-event-queue
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -12,2 +12,3 @@ var canDev = require("can-util/js/dev/dev"); | ||
dispatchBoundChangeSymbol = canSymbol.for("can.dispatchInstanceBoundChange"), | ||
dispatchInstanceOnPatchesSymbol = canSymbol.for("can.dispatchInstanceOnPatches"), | ||
onKeyValueSymbol = canSymbol.for("can.onKeyValue"), | ||
@@ -109,7 +110,10 @@ offKeyValueSymbol = canSymbol.for("can.offKeyValue"), | ||
//!steal-remove-end | ||
var handlers = meta.handlers; | ||
var handlersByType = handlers.getNode([event.type]); | ||
if (handlersByType) { | ||
var dispatchPatches = event.patches && this.constructor[dispatchInstanceOnPatchesSymbol]; | ||
var batch = dispatchPatches || handlersByType; | ||
if ( batch ) { | ||
queues.batch.start(); | ||
} | ||
if(handlersByType) { | ||
if (handlersByType.onKeyValue) { | ||
@@ -119,3 +123,2 @@ queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); | ||
if (handlersByType.event) { | ||
event.batchNum = queues.batch.number(); | ||
@@ -125,2 +128,7 @@ var eventAndArgs = [event].concat(args); | ||
} | ||
} | ||
if(dispatchPatches) { | ||
this.constructor[dispatchInstanceOnPatchesSymbol](this, event.patches); | ||
} | ||
if ( batch ) { | ||
queues.batch.stop(); | ||
@@ -127,0 +135,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/*can-event-queue@0.6.0#can-event-queue*/ | ||
/*can-event-queue@0.7.0#can-event-queue*/ | ||
define([ | ||
@@ -21,3 +21,3 @@ 'require', | ||
var domEvents = require('can-util/dom/events'); | ||
var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); | ||
var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), dispatchInstanceOnPatchesSymbol = canSymbol.for('can.dispatchInstanceOnPatches'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); | ||
var eventQueue; | ||
@@ -73,4 +73,8 @@ var ensureMeta = function ensureMeta(obj) { | ||
var handlersByType = handlers.getNode([event.type]); | ||
var dispatchPatches = event.patches && this.constructor[dispatchInstanceOnPatchesSymbol]; | ||
var batch = dispatchPatches || handlersByType; | ||
if (batch) { | ||
queues.batch.start(); | ||
} | ||
if (handlersByType) { | ||
queues.batch.start(); | ||
if (handlersByType.onKeyValue) { | ||
@@ -84,2 +88,7 @@ queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); | ||
} | ||
} | ||
if (dispatchPatches) { | ||
this.constructor[dispatchInstanceOnPatchesSymbol](this, event.patches); | ||
} | ||
if (batch) { | ||
queues.batch.stop(); | ||
@@ -86,0 +95,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/*can-event-queue@0.6.0#can-event-queue*/ | ||
/*can-event-queue@0.7.0#can-event-queue*/ | ||
var canDev = require('can-util/js/dev/dev'); | ||
@@ -9,3 +9,3 @@ var assign = require('can-util/js/assign/assign'); | ||
var domEvents = require('can-util/dom/events/events'); | ||
var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); | ||
var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), dispatchInstanceOnPatchesSymbol = canSymbol.for('can.dispatchInstanceOnPatches'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); | ||
var eventQueue; | ||
@@ -61,4 +61,8 @@ var ensureMeta = function ensureMeta(obj) { | ||
var handlersByType = handlers.getNode([event.type]); | ||
var dispatchPatches = event.patches && this.constructor[dispatchInstanceOnPatchesSymbol]; | ||
var batch = dispatchPatches || handlersByType; | ||
if (batch) { | ||
queues.batch.start(); | ||
} | ||
if (handlersByType) { | ||
queues.batch.start(); | ||
if (handlersByType.onKeyValue) { | ||
@@ -72,2 +76,7 @@ queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); | ||
} | ||
} | ||
if (dispatchPatches) { | ||
this.constructor[dispatchInstanceOnPatchesSymbol](this, event.patches); | ||
} | ||
if (batch) { | ||
queues.batch.stop(); | ||
@@ -74,0 +83,0 @@ } |
@@ -130,3 +130,3 @@ /*[global-shim-start]*/ | ||
/*can-event-queue@0.6.0#can-event-queue*/ | ||
/*can-event-queue@0.7.0#can-event-queue*/ | ||
define('can-event-queue', [ | ||
@@ -151,3 +151,3 @@ 'require', | ||
var domEvents = require('can-util/dom/events/events'); | ||
var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); | ||
var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), dispatchInstanceOnPatchesSymbol = canSymbol.for('can.dispatchInstanceOnPatches'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); | ||
var eventQueue; | ||
@@ -203,4 +203,8 @@ var ensureMeta = function ensureMeta(obj) { | ||
var handlersByType = handlers.getNode([event.type]); | ||
var dispatchPatches = event.patches && this.constructor[dispatchInstanceOnPatchesSymbol]; | ||
var batch = dispatchPatches || handlersByType; | ||
if (batch) { | ||
queues.batch.start(); | ||
} | ||
if (handlersByType) { | ||
queues.batch.start(); | ||
if (handlersByType.onKeyValue) { | ||
@@ -214,2 +218,7 @@ queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); | ||
} | ||
} | ||
if (dispatchPatches) { | ||
this.constructor[dispatchInstanceOnPatchesSymbol](this, event.patches); | ||
} | ||
if (batch) { | ||
queues.batch.stop(); | ||
@@ -216,0 +225,0 @@ } |
{ | ||
"name": "can-event-queue", | ||
"main": "./can-event-queue.js", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "A event mixin that uses queues to dispatch handlers", | ||
@@ -6,0 +6,0 @@ "homepage": "", |
var QUnit = require('steal-qunit'); | ||
var eventQueue = require("can-event-queue"); | ||
var queues = require("can-queues"); | ||
var domEvents = require("can-util/dom/events/events"); | ||
var canSymbol = require("can-symbol"); | ||
var canReflect = require("can-reflect"); | ||
var addTypeEvents = require("./type-events"); | ||
@@ -69,1 +66,29 @@ | ||
}); | ||
test("can.dispatchInstanceOnPatches with patches on event object", function() { | ||
expect(1); | ||
var Type = function(){}; | ||
eventQueue(Type.prototype); | ||
addTypeEvents( Type ); | ||
var calls = []; | ||
var handler = function(obj, patches){ | ||
calls.push([obj, patches]); | ||
}; | ||
Type[canSymbol.for("can.onInstancePatches")](handler); | ||
var obj1 = new Type(); | ||
obj1.dispatch({ | ||
type: "b", | ||
patches: [{type: "add", key: "b", value: 1}] | ||
}); | ||
Type[canSymbol.for("can.offInstancePatches")](handler); | ||
obj1.dispatch({ | ||
type: "b", | ||
patches: [{type: "add", key: "b", value: 1}] | ||
}); | ||
QUnit.deepEqual(calls,[ | ||
[obj1, [{type: "add", key: "b", value: 1}]] | ||
]); | ||
}); |
66209
1642