From 11be25b0096ccf9a4e2fdd83d16b44de0525d4cb Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Mon, 6 Nov 2017 18:52:31 -0800 Subject: [PATCH] 0.5.1 --- dist/amd/can-event-queue.js | 311 +++++++++++++++++++++++ dist/cjs/can-event-queue.js | 298 ++++++++++++++++++++++ dist/global/can-event-queue.js | 446 +++++++++++++++++++++++++++++++++ 3 files changed, 1055 insertions(+) create mode 100644 dist/amd/can-event-queue.js create mode 100644 dist/cjs/can-event-queue.js create mode 100644 dist/global/can-event-queue.js diff --git a/dist/amd/can-event-queue.js b/dist/amd/can-event-queue.js new file mode 100644 index 0000000..bd35588 --- /dev/null +++ b/dist/amd/can-event-queue.js @@ -0,0 +1,311 @@ +/*can-event-queue@0.5.0#can-event-queue*/ +define([ + 'require', + 'exports', + 'module', + 'can-util/js/dev', + 'can-util/js/assign', + 'can-queues', + 'can-reflect', + 'can-symbol', + 'can-key-tree', + 'can-util/dom/events' +], function (require, exports, module) { + var canDev = require('can-util/js/dev'); + var assign = require('can-util/js/assign'); + var queues = require('can-queues'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var KeyTree = require('can-key-tree'); + var domEvents = require('can-util/dom/events'); + var eventQueue; + var ensureMeta = function ensureMeta(obj) { + var metaSymbol = canSymbol.for('can.meta'); + var meta = obj[metaSymbol]; + if (!meta) { + meta = {}; + canReflect.setKeyValue(obj, metaSymbol, meta); + } + var handlers = meta.handlers; + if (!handlers) { + handlers = meta.handlers = new KeyTree([ + Object, + Object, + Object, + Array + ], { + onFirst: function () { + if (obj._eventSetup) { + obj._eventSetup(); + } + queues.enqueueByQueue(getLifecycleHandlers(obj).getNode([]), obj, [true]); + }, + onEmpty: function () { + if (obj._eventTeardown) { + obj._eventTeardown(); + } + queues.enqueueByQueue(getLifecycleHandlers(obj).getNode([]), obj, [false]); + } + }); + } + if (!meta.lifecycleHandlers) { + meta.lifecycleHandlers = new KeyTree([ + Object, + Array + ]); + } + if (!meta.listenHandlers) { + meta.listenHandlers = new KeyTree([ + Map, + Object, + Array + ]); + } + return meta; + }; + function getHandlers(obj) { + return ensureMeta(obj).handlers; + } + function getLifecycleHandlers(obj) { + return ensureMeta(obj).lifecycleHandlers; + } + var props = { + dispatch: function (event, args) { + if (!this.__inSetup) { + if (typeof event === 'string') { + event = { type: event }; + } + var meta = ensureMeta(this); + var handlers = meta.handlers; + 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) { + if (key === undefined) { + var handlers = getHandlers(this); + var keyHandlers = handlers.getNode([]); + Object.keys(keyHandlers).forEach(function (key) { + handlers.delete([ + key, + 'event' + ]); + }); + } else if (!handler && !queueName) { + getHandlers(this).delete([ + key, + 'event' + ]); + } else if (!handler) { + getHandlers(this).delete([ + key, + 'event', + queueName || 'mutate' + ]); + } else { + getHandlers(this).delete([ + key, + 'event', + queueName || 'mutate', + handler + ]); + } + }, + one: function (event, handler) { + var one = function () { + eventQueue.off.call(this, event, one); + return handler.apply(this, arguments); + }; + eventQueue.on.call(this, event, one); + return this; + }, + listenTo: function (other, event, handler) { + ensureMeta(this).listenHandlers.add([ + other, + event, + handler + ]); + eventQueue.on.call(other, event, handler); + }, + stopListening: function (other, event, handler) { + var listenHandlers = ensureMeta(this).listenHandlers; + function stopHandler(other, event, handler) { + eventQueue.off.call(other, event, handler); + } + function stopEvent(other, event) { + listenHandlers.get([ + other, + event + ]).forEach(function (handler) { + stopHandler(other, event, handler); + }); + } + function stopOther(other) { + canReflect.eachKey(listenHandlers.getNode([other]), function (handlers, event) { + stopEvent(other, event); + }); + } + if (other) { + if (event) { + if (handler) { + stopHandler(other, event, handler); + listenHandlers.delete([ + other, + event, + handler + ]); + } else { + stopEvent(other, event); + listenHandlers.delete([ + other, + event + ]); + } + } else { + stopOther(other); + listenHandlers.delete([other]); + } + } else { + canReflect.eachKey(listenHandlers.getNode([]), function (events, other) { + stopOther(other); + }); + listenHandlers.delete([]); + } + return this; + } + }; + props.bind = props.addEventListener; + props.unbind = props.removeEventListener; + var 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'); + props.on = function (eventName, handler, queue) { + var listenWithDOM = domEvents.canAddEventListener.call(this); + if (listenWithDOM) { + var method = typeof handler === 'string' ? 'addDelegateListener' : 'addEventListener'; + domEvents[method].call(this, eventName, handler, queue); + } else { + if ('addEventListener' in this) { + this.addEventListener(eventName, handler, queue); + } else if (this[onKeyValueSymbol]) { + canReflect.onKeyValue(this, eventName, handler, queue); + } else if (this[onEventSymbol]) { + this[onEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[onValueSymbol]) { + canReflect.onValue(this, handler); + } else { + throw new Error('can-event-queue: Unable to bind ' + eventName); + } + } + } + }; + props.off = function (eventName, handler, queue) { + var listenWithDOM = domEvents.canAddEventListener.call(this); + if (listenWithDOM) { + var method = typeof handler === 'string' ? 'removeDelegateListener' : 'removeEventListener'; + domEvents[method].call(this, eventName, handler, queue); + } else { + if ('removeEventListener' in this) { + this.removeEventListener(eventName, handler, queue); + } else if (this[offKeyValueSymbol]) { + canReflect.offKeyValue(this, eventName, handler, queue); + } else if (this[offEventSymbol]) { + this[offEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[offValueSymbol]) { + canReflect.offValue(this, handler); + } else { + throw new Error('can-control: Unable to unbind ' + eventName); + } + } + } + }; + var symbols = { + 'can.onKeyValue': function (key, handler, queueName) { + getHandlers(this).add([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.offKeyValue': function (key, handler, queueName) { + getHandlers(this).delete([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.onBoundChange': function (handler, queueName) { + getLifecycleHandlers(this).add([ + queueName || 'mutate', + handler + ]); + }, + 'can.offBoundChange': function (handler, queueName) { + getLifecycleHandlers(this).delete([ + queueName || 'mutate', + handler + ]); + }, + 'can.isBound': function () { + return getHandlers(this).size() > 0; + } + }; + eventQueue = function (obj) { + assign(obj, props); + canReflect.assignSymbols(obj, symbols); + return obj; + }; + function defineNonEnumerable(obj, prop, value) { + Object.defineProperty(obj, prop, { + enumerable: false, + value: value + }); + } + assign(eventQueue, props); + defineNonEnumerable(eventQueue, 'start', function () { + console.warn('use can-queues.batch.start()'); + queues.batch.start(); + }); + defineNonEnumerable(eventQueue, 'stop', function () { + console.warn('use can-queues.batch.stop()'); + queues.batch.stop(); + }); + defineNonEnumerable(eventQueue, 'flush', function () { + console.warn('use can-queues.flush()'); + queues.flush(); + }); + defineNonEnumerable(eventQueue, 'afterPreviousEvents', function (handler) { + console.warn('don\'t use afterPreviousEvents'); + queues.mutateQueue.enqueue(function afterPreviousEvents() { + queues.mutateQueue.enqueue(handler); + }); + queues.flush(); + }); + defineNonEnumerable(eventQueue, 'after', function (handler) { + console.warn('don\'t use after'); + queues.mutateQueue.enqueue(handler); + queues.flush(); + }); + module.exports = eventQueue; +}); \ No newline at end of file diff --git a/dist/cjs/can-event-queue.js b/dist/cjs/can-event-queue.js new file mode 100644 index 0000000..97b459f --- /dev/null +++ b/dist/cjs/can-event-queue.js @@ -0,0 +1,298 @@ +/*can-event-queue@0.5.0#can-event-queue*/ +var canDev = require('can-util/js/dev/dev'); +var assign = require('can-util/js/assign/assign'); +var queues = require('can-queues'); +var canReflect = require('can-reflect'); +var canSymbol = require('can-symbol'); +var KeyTree = require('can-key-tree'); +var domEvents = require('can-util/dom/events/events'); +var eventQueue; +var ensureMeta = function ensureMeta(obj) { + var metaSymbol = canSymbol.for('can.meta'); + var meta = obj[metaSymbol]; + if (!meta) { + meta = {}; + canReflect.setKeyValue(obj, metaSymbol, meta); + } + var handlers = meta.handlers; + if (!handlers) { + handlers = meta.handlers = new KeyTree([ + Object, + Object, + Object, + Array + ], { + onFirst: function () { + if (obj._eventSetup) { + obj._eventSetup(); + } + queues.enqueueByQueue(getLifecycleHandlers(obj).getNode([]), obj, [true]); + }, + onEmpty: function () { + if (obj._eventTeardown) { + obj._eventTeardown(); + } + queues.enqueueByQueue(getLifecycleHandlers(obj).getNode([]), obj, [false]); + } + }); + } + if (!meta.lifecycleHandlers) { + meta.lifecycleHandlers = new KeyTree([ + Object, + Array + ]); + } + if (!meta.listenHandlers) { + meta.listenHandlers = new KeyTree([ + Map, + Object, + Array + ]); + } + return meta; +}; +function getHandlers(obj) { + return ensureMeta(obj).handlers; +} +function getLifecycleHandlers(obj) { + return ensureMeta(obj).lifecycleHandlers; +} +var props = { + dispatch: function (event, args) { + if (!this.__inSetup) { + if (typeof event === 'string') { + event = { type: event }; + } + var meta = ensureMeta(this); + var handlers = meta.handlers; + 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) { + if (key === undefined) { + var handlers = getHandlers(this); + var keyHandlers = handlers.getNode([]); + Object.keys(keyHandlers).forEach(function (key) { + handlers.delete([ + key, + 'event' + ]); + }); + } else if (!handler && !queueName) { + getHandlers(this).delete([ + key, + 'event' + ]); + } else if (!handler) { + getHandlers(this).delete([ + key, + 'event', + queueName || 'mutate' + ]); + } else { + getHandlers(this).delete([ + key, + 'event', + queueName || 'mutate', + handler + ]); + } + }, + one: function (event, handler) { + var one = function () { + eventQueue.off.call(this, event, one); + return handler.apply(this, arguments); + }; + eventQueue.on.call(this, event, one); + return this; + }, + listenTo: function (other, event, handler) { + ensureMeta(this).listenHandlers.add([ + other, + event, + handler + ]); + eventQueue.on.call(other, event, handler); + }, + stopListening: function (other, event, handler) { + var listenHandlers = ensureMeta(this).listenHandlers; + function stopHandler(other, event, handler) { + eventQueue.off.call(other, event, handler); + } + function stopEvent(other, event) { + listenHandlers.get([ + other, + event + ]).forEach(function (handler) { + stopHandler(other, event, handler); + }); + } + function stopOther(other) { + canReflect.eachKey(listenHandlers.getNode([other]), function (handlers, event) { + stopEvent(other, event); + }); + } + if (other) { + if (event) { + if (handler) { + stopHandler(other, event, handler); + listenHandlers.delete([ + other, + event, + handler + ]); + } else { + stopEvent(other, event); + listenHandlers.delete([ + other, + event + ]); + } + } else { + stopOther(other); + listenHandlers.delete([other]); + } + } else { + canReflect.eachKey(listenHandlers.getNode([]), function (events, other) { + stopOther(other); + }); + listenHandlers.delete([]); + } + return this; + } +}; +props.bind = props.addEventListener; +props.unbind = props.removeEventListener; +var 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'); +props.on = function (eventName, handler, queue) { + var listenWithDOM = domEvents.canAddEventListener.call(this); + if (listenWithDOM) { + var method = typeof handler === 'string' ? 'addDelegateListener' : 'addEventListener'; + domEvents[method].call(this, eventName, handler, queue); + } else { + if ('addEventListener' in this) { + this.addEventListener(eventName, handler, queue); + } else if (this[onKeyValueSymbol]) { + canReflect.onKeyValue(this, eventName, handler, queue); + } else if (this[onEventSymbol]) { + this[onEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[onValueSymbol]) { + canReflect.onValue(this, handler); + } else { + throw new Error('can-event-queue: Unable to bind ' + eventName); + } + } + } +}; +props.off = function (eventName, handler, queue) { + var listenWithDOM = domEvents.canAddEventListener.call(this); + if (listenWithDOM) { + var method = typeof handler === 'string' ? 'removeDelegateListener' : 'removeEventListener'; + domEvents[method].call(this, eventName, handler, queue); + } else { + if ('removeEventListener' in this) { + this.removeEventListener(eventName, handler, queue); + } else if (this[offKeyValueSymbol]) { + canReflect.offKeyValue(this, eventName, handler, queue); + } else if (this[offEventSymbol]) { + this[offEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[offValueSymbol]) { + canReflect.offValue(this, handler); + } else { + throw new Error('can-control: Unable to unbind ' + eventName); + } + } + } +}; +var symbols = { + 'can.onKeyValue': function (key, handler, queueName) { + getHandlers(this).add([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.offKeyValue': function (key, handler, queueName) { + getHandlers(this).delete([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.onBoundChange': function (handler, queueName) { + getLifecycleHandlers(this).add([ + queueName || 'mutate', + handler + ]); + }, + 'can.offBoundChange': function (handler, queueName) { + getLifecycleHandlers(this).delete([ + queueName || 'mutate', + handler + ]); + }, + 'can.isBound': function () { + return getHandlers(this).size() > 0; + } +}; +eventQueue = function (obj) { + assign(obj, props); + canReflect.assignSymbols(obj, symbols); + return obj; +}; +function defineNonEnumerable(obj, prop, value) { + Object.defineProperty(obj, prop, { + enumerable: false, + value: value + }); +} +assign(eventQueue, props); +defineNonEnumerable(eventQueue, 'start', function () { + console.warn('use can-queues.batch.start()'); + queues.batch.start(); +}); +defineNonEnumerable(eventQueue, 'stop', function () { + console.warn('use can-queues.batch.stop()'); + queues.batch.stop(); +}); +defineNonEnumerable(eventQueue, 'flush', function () { + console.warn('use can-queues.flush()'); + queues.flush(); +}); +defineNonEnumerable(eventQueue, 'afterPreviousEvents', function (handler) { + console.warn('don\'t use afterPreviousEvents'); + queues.mutateQueue.enqueue(function afterPreviousEvents() { + queues.mutateQueue.enqueue(handler); + }); + queues.flush(); +}); +defineNonEnumerable(eventQueue, 'after', function (handler) { + console.warn('don\'t use after'); + queues.mutateQueue.enqueue(handler); + queues.flush(); +}); +module.exports = eventQueue; \ No newline at end of file diff --git a/dist/global/can-event-queue.js b/dist/global/can-event-queue.js new file mode 100644 index 0000000..561a417 --- /dev/null +++ b/dist/global/can-event-queue.js @@ -0,0 +1,446 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval) { + // jshint ignore:line + var origDefine = global.define; + + var get = function(name) { + var parts = name.split("."), + cur = global, + i; + for (i = 0; i < parts.length; i++) { + if (!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val) { + var parts = name.split("."), + cur = global, + i, + part, + next; + for (i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if (!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod) { + if (!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, default: true }; + for (var p in mod) { + if (!esProps[p]) return false; + } + return true; + }; + + var hasCjsDependencies = function(deps) { + return ( + deps[0] === "require" && deps[1] === "exports" && deps[2] === "module" + ); + }; + + var modules = + (global.define && global.define.modules) || + (global._define && global._define.modules) || + {}; + var ourDefine = (global.define = function(moduleName, deps, callback) { + var module; + if (typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for (i = 0; i < deps.length; i++) { + args.push( + exports[deps[i]] + ? get(exports[deps[i]]) + : modules[deps[i]] || get(deps[i]) + ); + } + // CJS has no dependencies but 3 callback arguments + if (hasCjsDependencies(deps) || (!deps.length && callback.length)) { + module = { exports: {} }; + args[0] = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args[1] = module.exports; + args[2] = module; + } else if (!args[0] && deps[0] === "exports") { + // Babel uses the exports and module object. + module = { exports: {} }; + args[0] = module.exports; + if (deps[1] === "module") { + args[1] = module; + } + } else if (!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if (globalExport && !get(globalExport)) { + if (useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }); + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function() { + // shim for @@global-helpers + var noop = function() {}; + return { + get: function() { + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load) { + doEval(__load.source, global); + } + }; + }); +})( + {}, + typeof self == "object" && self.Object == Object ? self : window, + function(__$source__, __$global__) { + // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); + } +); + +/*can-event-queue@0.5.0#can-event-queue*/ +define('can-event-queue', [ + 'require', + 'exports', + 'module', + 'can-util/js/dev/dev', + 'can-util/js/assign/assign', + 'can-queues', + 'can-reflect', + 'can-symbol', + 'can-key-tree', + 'can-util/dom/events/events' +], function (require, exports, module) { + var canDev = require('can-util/js/dev/dev'); + var assign = require('can-util/js/assign/assign'); + var queues = require('can-queues'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var KeyTree = require('can-key-tree'); + var domEvents = require('can-util/dom/events/events'); + var eventQueue; + var ensureMeta = function ensureMeta(obj) { + var metaSymbol = canSymbol.for('can.meta'); + var meta = obj[metaSymbol]; + if (!meta) { + meta = {}; + canReflect.setKeyValue(obj, metaSymbol, meta); + } + var handlers = meta.handlers; + if (!handlers) { + handlers = meta.handlers = new KeyTree([ + Object, + Object, + Object, + Array + ], { + onFirst: function () { + if (obj._eventSetup) { + obj._eventSetup(); + } + queues.enqueueByQueue(getLifecycleHandlers(obj).getNode([]), obj, [true]); + }, + onEmpty: function () { + if (obj._eventTeardown) { + obj._eventTeardown(); + } + queues.enqueueByQueue(getLifecycleHandlers(obj).getNode([]), obj, [false]); + } + }); + } + if (!meta.lifecycleHandlers) { + meta.lifecycleHandlers = new KeyTree([ + Object, + Array + ]); + } + if (!meta.listenHandlers) { + meta.listenHandlers = new KeyTree([ + Map, + Object, + Array + ]); + } + return meta; + }; + function getHandlers(obj) { + return ensureMeta(obj).handlers; + } + function getLifecycleHandlers(obj) { + return ensureMeta(obj).lifecycleHandlers; + } + var props = { + dispatch: function (event, args) { + if (!this.__inSetup) { + if (typeof event === 'string') { + event = { type: event }; + } + var meta = ensureMeta(this); + var handlers = meta.handlers; + 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) { + if (key === undefined) { + var handlers = getHandlers(this); + var keyHandlers = handlers.getNode([]); + Object.keys(keyHandlers).forEach(function (key) { + handlers.delete([ + key, + 'event' + ]); + }); + } else if (!handler && !queueName) { + getHandlers(this).delete([ + key, + 'event' + ]); + } else if (!handler) { + getHandlers(this).delete([ + key, + 'event', + queueName || 'mutate' + ]); + } else { + getHandlers(this).delete([ + key, + 'event', + queueName || 'mutate', + handler + ]); + } + }, + one: function (event, handler) { + var one = function () { + eventQueue.off.call(this, event, one); + return handler.apply(this, arguments); + }; + eventQueue.on.call(this, event, one); + return this; + }, + listenTo: function (other, event, handler) { + ensureMeta(this).listenHandlers.add([ + other, + event, + handler + ]); + eventQueue.on.call(other, event, handler); + }, + stopListening: function (other, event, handler) { + var listenHandlers = ensureMeta(this).listenHandlers; + function stopHandler(other, event, handler) { + eventQueue.off.call(other, event, handler); + } + function stopEvent(other, event) { + listenHandlers.get([ + other, + event + ]).forEach(function (handler) { + stopHandler(other, event, handler); + }); + } + function stopOther(other) { + canReflect.eachKey(listenHandlers.getNode([other]), function (handlers, event) { + stopEvent(other, event); + }); + } + if (other) { + if (event) { + if (handler) { + stopHandler(other, event, handler); + listenHandlers.delete([ + other, + event, + handler + ]); + } else { + stopEvent(other, event); + listenHandlers.delete([ + other, + event + ]); + } + } else { + stopOther(other); + listenHandlers.delete([other]); + } + } else { + canReflect.eachKey(listenHandlers.getNode([]), function (events, other) { + stopOther(other); + }); + listenHandlers.delete([]); + } + return this; + } + }; + props.bind = props.addEventListener; + props.unbind = props.removeEventListener; + var 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'); + props.on = function (eventName, handler, queue) { + var listenWithDOM = domEvents.canAddEventListener.call(this); + if (listenWithDOM) { + var method = typeof handler === 'string' ? 'addDelegateListener' : 'addEventListener'; + domEvents[method].call(this, eventName, handler, queue); + } else { + if ('addEventListener' in this) { + this.addEventListener(eventName, handler, queue); + } else if (this[onKeyValueSymbol]) { + canReflect.onKeyValue(this, eventName, handler, queue); + } else if (this[onEventSymbol]) { + this[onEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[onValueSymbol]) { + canReflect.onValue(this, handler); + } else { + throw new Error('can-event-queue: Unable to bind ' + eventName); + } + } + } + }; + props.off = function (eventName, handler, queue) { + var listenWithDOM = domEvents.canAddEventListener.call(this); + if (listenWithDOM) { + var method = typeof handler === 'string' ? 'removeDelegateListener' : 'removeEventListener'; + domEvents[method].call(this, eventName, handler, queue); + } else { + if ('removeEventListener' in this) { + this.removeEventListener(eventName, handler, queue); + } else if (this[offKeyValueSymbol]) { + canReflect.offKeyValue(this, eventName, handler, queue); + } else if (this[offEventSymbol]) { + this[offEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[offValueSymbol]) { + canReflect.offValue(this, handler); + } else { + throw new Error('can-control: Unable to unbind ' + eventName); + } + } + } + }; + var symbols = { + 'can.onKeyValue': function (key, handler, queueName) { + getHandlers(this).add([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.offKeyValue': function (key, handler, queueName) { + getHandlers(this).delete([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.onBoundChange': function (handler, queueName) { + getLifecycleHandlers(this).add([ + queueName || 'mutate', + handler + ]); + }, + 'can.offBoundChange': function (handler, queueName) { + getLifecycleHandlers(this).delete([ + queueName || 'mutate', + handler + ]); + }, + 'can.isBound': function () { + return getHandlers(this).size() > 0; + } + }; + eventQueue = function (obj) { + assign(obj, props); + canReflect.assignSymbols(obj, symbols); + return obj; + }; + function defineNonEnumerable(obj, prop, value) { + Object.defineProperty(obj, prop, { + enumerable: false, + value: value + }); + } + assign(eventQueue, props); + defineNonEnumerable(eventQueue, 'start', function () { + console.warn('use can-queues.batch.start()'); + queues.batch.start(); + }); + defineNonEnumerable(eventQueue, 'stop', function () { + console.warn('use can-queues.batch.stop()'); + queues.batch.stop(); + }); + defineNonEnumerable(eventQueue, 'flush', function () { + console.warn('use can-queues.flush()'); + queues.flush(); + }); + defineNonEnumerable(eventQueue, 'afterPreviousEvents', function (handler) { + console.warn('don\'t use afterPreviousEvents'); + queues.mutateQueue.enqueue(function afterPreviousEvents() { + queues.mutateQueue.enqueue(handler); + }); + queues.flush(); + }); + defineNonEnumerable(eventQueue, 'after', function (handler) { + console.warn('don\'t use after'); + queues.mutateQueue.enqueue(handler); + queues.flush(); + }); + module.exports = eventQueue; +}); +/*[global-shim-end]*/ +(function(global) { // jshint ignore:line + global._define = global.define; + global.define = global.define.orig; +} +)(typeof self == "object" && self.Object == Object ? self : window); \ No newline at end of file