Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-event-queue

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-event-queue - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

.npmignore

91

can-event-queue.js

@@ -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": "",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc