can-event-queue
Advanced tools
Comparing version 0.9.1 to 0.10.0
{ | ||
"name": "can-event-queue", | ||
"main": "./can-event-queue.js", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"description": "A event mixin that uses queues to dispatch handlers", | ||
@@ -47,3 +47,3 @@ "homepage": "", | ||
"can-queues": "<2.0.0", | ||
"can-reflect": "^1.4.5", | ||
"can-reflect": "^1.10.2", | ||
"can-symbol": "^1.2.0", | ||
@@ -50,0 +50,0 @@ "can-util": "^3.10.11" |
@@ -1,2 +0,3 @@ | ||
var QUnit = require('steal-qunit'); | ||
var steal = require("@steal"); | ||
var QUnit = require("steal-qunit"); | ||
var valueEventBindings = require("./value"); | ||
@@ -6,25 +7,77 @@ var canReflect = require("can-reflect"); | ||
QUnit.module('can-event-queue/value',{ | ||
setup: function(){ }, | ||
teardown: function(){ } | ||
var skipProductionTest = steal.isEnv("production") ? QUnit.skip : QUnit.test; | ||
QUnit.module("can-event-queue/value", { | ||
setup: function() {}, | ||
teardown: function() {} | ||
}); | ||
QUnit.test("basics", function(){ | ||
QUnit.test("basics", function() { | ||
var observable = valueEventBindings(valueEventBindings.addHandlers({})); | ||
var values = []; | ||
var values = []; | ||
canReflect.onValue(observable, function(newVal, oldVal){ | ||
values.push(["onValue",newVal, oldVal]); | ||
}); | ||
canReflect.onValue(observable, function(newVal, oldVal) { | ||
values.push(["onValue", newVal, oldVal]); | ||
}); | ||
observable.on(function(newVal, oldVal){ | ||
values.push(["on",newVal, oldVal]); | ||
},"notify"); | ||
observable.on(function(newVal, oldVal) { | ||
values.push(["on", newVal, oldVal]); | ||
}, "notify"); | ||
observable[canSymbol.for("can.dispatch")](1,2); | ||
observable[canSymbol.for("can.dispatch")](1, 2); | ||
QUnit.deepEqual(values,[ | ||
["on",1, 2], | ||
["onValue",1, 2] | ||
],"dispatched worked"); | ||
QUnit.deepEqual( | ||
values, | ||
[["on", 1, 2], ["onValue", 1, 2]], | ||
"dispatched worked" | ||
); | ||
}); | ||
skipProductionTest("getWhatIChange", function(assert) { | ||
var getChangesSymbol = canSymbol.for("can.getChangesDependencyRecord"); | ||
var observable = valueEventBindings(valueEventBindings.addHandlers({})); | ||
var getWhatIChange = observable[canSymbol.for("can.getWhatIChange")].bind( | ||
observable | ||
); | ||
assert.equal( | ||
typeof getWhatIChange(), | ||
"undefined", | ||
"should return undefined if handlers is empty" | ||
); | ||
var getChanges = function(value) { | ||
return function() { | ||
return { valueDependencies: new Set([value]) }; | ||
}; | ||
}; | ||
var mutateHandler = function mutateHandler() {}; | ||
var domUIHandler = function domUIHandler() {}; | ||
var notifyHandler = function notifyHandler() {}; | ||
// faux observables to set as being changed by the handlers in the queues | ||
var a = function a() {}; | ||
var b = function b() {}; | ||
mutateHandler[getChangesSymbol] = getChanges(a); | ||
domUIHandler[getChangesSymbol] = getChanges(b); | ||
notifyHandler[getChangesSymbol] = getChanges(a); | ||
observable.handlers.add(["mutate", mutateHandler]); | ||
observable.handlers.add(["domUI", domUIHandler]); | ||
observable.handlers.add(["notify", notifyHandler]); | ||
var whatIChange = getWhatIChange(); | ||
assert.deepEqual( | ||
whatIChange.mutate, | ||
{ valueDependencies: new Set([a, b]) }, | ||
"domUI and mutate queues handlers deps should be included in .mutate" | ||
); | ||
assert.deepEqual( | ||
whatIChange.derive, | ||
{ valueDependencies: new Set([a]) }, | ||
"notify queue handlers deps should be included in .derive" | ||
); | ||
}); |
var queues = require("can-queues"); | ||
var KeyTree = require("can-key-tree"); | ||
var canReflect = require("can-reflect"); | ||
var KeyTree = require("can-key-tree"); | ||
var mergeDependencyRecords = require("./merge-dependency-records"); | ||
var properties = { | ||
on: function(handler, queue){ | ||
this.handlers.add([queue|| "mutate", handler]); | ||
on: function(handler, queue) { | ||
this.handlers.add([queue || "mutate", handler]); | ||
}, | ||
off: function(handler, queueName){ | ||
if(handler === undefined) { | ||
if(queueName === undefined) { | ||
off: function(handler, queueName) { | ||
if (handler === undefined) { | ||
if (queueName === undefined) { | ||
this.handlers.delete([]); | ||
@@ -22,14 +24,17 @@ } else { | ||
var symbols = { | ||
"can.onValue": properties.on, | ||
"can.onValue": properties.on, | ||
"can.offValue": properties.off, | ||
"can.dispatch": function(value, old) { | ||
queues.enqueueByQueue(this.handlers.getNode([]), this, [value, old] | ||
"can.dispatch": function(value, old) { | ||
queues.enqueueByQueue( | ||
this.handlers.getNode([]), | ||
this, | ||
[value, old] | ||
//!steal-remove-start | ||
/* jshint laxcomma: true */ | ||
, null | ||
, [ canReflect.getName(this), "changed to", value, "from", old ] | ||
, [canReflect.getName(this), "changed to", value, "from", old] | ||
/* jshint laxcomma: false */ | ||
//!steal-remove-end | ||
); | ||
//!steal-remove-start | ||
//!steal-remove-start | ||
if (typeof this._log === "function") { | ||
@@ -39,16 +44,57 @@ this._log(old, value); | ||
//!steal-remove-end | ||
} | ||
}, | ||
"can.getWhatIChange": function getWhatIChange() { | ||
//!steal-remove-start | ||
var whatIChange = {}; | ||
var notifyHandlers = this.handlers.get(["notify"]); | ||
var mutateHandlers = [].concat( | ||
this.handlers.get(["mutate"]), | ||
this.handlers.get(["domUI"]) | ||
); | ||
if (notifyHandlers.length) { | ||
notifyHandlers.forEach(function(handler) { | ||
var changes = canReflect.getChangesDependencyRecord(handler); | ||
if (changes) { | ||
var record = whatIChange.derive; | ||
if (!record) { | ||
record = (whatIChange.derive = {}); | ||
} | ||
mergeDependencyRecords(record, changes); | ||
} | ||
}); | ||
} | ||
if (mutateHandlers.length) { | ||
mutateHandlers.forEach(function(handler) { | ||
var changes = canReflect.getChangesDependencyRecord(handler); | ||
if (changes) { | ||
var record = whatIChange.mutate; | ||
if (!record) { | ||
record = (whatIChange.mutate = {}); | ||
} | ||
mergeDependencyRecords(record, changes); | ||
} | ||
}); | ||
} | ||
return Object.keys(whatIChange).length ? whatIChange : undefined; | ||
//!steal-remove-end | ||
} | ||
}; | ||
var mixinValueEventBindings = function(obj){ | ||
canReflect.assign(obj, properties); | ||
canReflect.assignSymbols(obj, symbols); | ||
return obj; | ||
var mixinValueEventBindings = function(obj) { | ||
canReflect.assign(obj, properties); | ||
canReflect.assignSymbols(obj, symbols); | ||
return obj; | ||
}; | ||
mixinValueEventBindings.addHandlers = function(obj){ | ||
obj.handlers = new KeyTree([Object, Array]); | ||
return obj; | ||
mixinValueEventBindings.addHandlers = function(obj) { | ||
obj.handlers = new KeyTree([Object, Array]); | ||
return obj; | ||
}; | ||
module.exports = mixinValueEventBindings; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
0
50149
25
1267
Updatedcan-reflect@^1.10.2