can-event-queue
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -8,10 +8,20 @@ var canDev = require("can-util/js/dev/dev"); | ||
// Ensure the "obj" passed as an argument has an object on @@can.meta | ||
var ensureMeta = function ensureMeta(obj) { | ||
var metaSymbol = canSymbol.for("can.meta"); | ||
var meta = obj[metaSymbol]; | ||
if (!meta) { | ||
meta = {}; | ||
canReflect.setKeyValue(obj, metaSymbol, meta); | ||
} | ||
return meta; | ||
}; | ||
// getHandlers returns a KeyTree used for event handling. | ||
// `handlers` will be on the `can.meta` symbol on the object. | ||
var metaSymbol = canSymbol.for("can.meta"); | ||
function getHandlers(obj) { | ||
var meta = obj[metaSymbol]; | ||
if(!meta) { | ||
canReflect.setKeyValue(obj, metaSymbol, meta = {}); | ||
} | ||
var meta = ensureMeta(obj); | ||
var handlers = meta.handlers; | ||
@@ -42,5 +52,5 @@ if(!handlers) { | ||
var props = { | ||
dispatch: function(event, args){ | ||
//!steal-remove-start | ||
if (arguments.length > 2) { | ||
dispatch: function(event, args){ | ||
//!steal-remove-start | ||
if (arguments.length > 2) { | ||
canDev.warn('Arguments to dispatch should be an array, not multiple arguments.'); | ||
@@ -56,33 +66,40 @@ args = Array.prototype.slice.call(arguments, 1); | ||
// Don't send events if initalizing. | ||
if (!this.__inSetup) { | ||
if(typeof event === 'string') { | ||
event = { | ||
type: event | ||
}; | ||
} | ||
var handlers = getHandlers(this); | ||
var handlersByType = handlers.getNode([event.type]); | ||
if(handlersByType) { | ||
queues.batch.start(); | ||
if(handlersByType.onKeyValue) { | ||
queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); | ||
} | ||
if(handlersByType.event) { | ||
if (!this.__inSetup) { | ||
if(typeof event === 'string') { | ||
event = { | ||
type: event | ||
}; | ||
} | ||
event.batchNum = queues.batch.number(); | ||
var eventAndArgs = [event].concat(args); | ||
queues.enqueueByQueue(handlersByType.event, this, eventAndArgs, event.makeMeta, event.reasonLog); | ||
} | ||
queues.batch.stop(); | ||
} | ||
} | ||
}, | ||
addEventListener: function(key, handler, queueName) { | ||
getHandlers(this).add([key, "event",queueName || "mutate", handler]); | ||
}, | ||
removeEventListener: function(key, handler, queueName) { | ||
getHandlers(this).delete([key, "event", queueName || "mutate", handler]); | ||
} | ||
//!steal-remove-start | ||
var meta = ensureMeta(this); | ||
if (typeof meta._log === "function") { | ||
meta._log.call(this, event, args); | ||
} | ||
//!steal-remove-end | ||
var handlers = getHandlers(this); | ||
var handlersByType = handlers.getNode([event.type]); | ||
if(handlersByType) { | ||
queues.batch.start(); | ||
if(handlersByType.onKeyValue) { | ||
queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); | ||
} | ||
if(handlersByType.event) { | ||
event.batchNum = queues.batch.number(); | ||
var eventAndArgs = [event].concat(args); | ||
queues.enqueueByQueue(handlersByType.event, this, eventAndArgs, event.makeMeta, event.reasonLog); | ||
} | ||
queues.batch.stop(); | ||
} | ||
} | ||
}, | ||
addEventListener: function(key, handler, queueName) { | ||
getHandlers(this).add([key, "event",queueName || "mutate", handler]); | ||
}, | ||
removeEventListener: function(key, handler, queueName) { | ||
getHandlers(this).delete([key, "event", queueName || "mutate", handler]); | ||
} | ||
}; | ||
@@ -89,0 +106,0 @@ props.on = props.addEventListener; |
{ | ||
"name": "can-event-queue", | ||
"main": "./can-event-queue.js", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A event mixin that uses queues to dispatch handlers", | ||
@@ -6,0 +6,0 @@ "homepage": "", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
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
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
16228
14
254
2