backbone-esnext-events
Advanced tools
Comparing version 0.3.2 to 0.3.3
var code = ` | ||
/** | ||
* @external {Events} https://docs.typhonjs.io/typhonjs-backbone-esnext/backbone-esnext-events/class/src/Events.js~Events.html | ||
*/ | ||
/** | ||
* @external {EventProxy} https://docs.typhonjs.io/typhonjs-backbone-esnext/backbone-esnext-events/class/src/EventProxy.js~EventProxy.html | ||
@@ -4,0 +8,0 @@ */ |
@@ -0,1 +1,8 @@ | ||
## 0.3.3 (2017-03-09) | ||
- Added eventCount to TyphonEvents and EventProxy. | ||
- Added getEventNames to TyphonEvents and EventProxy. | ||
- Added forEachEvent to TyphonEvents and EventProxy. | ||
- Added createEventProxy to EventProxy. | ||
- Removed once from EventProxy. | ||
## 0.3.2 (2017-03-06) | ||
@@ -2,0 +9,0 @@ - Fixed EventProxy for not properly unregistering events. |
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
var _getIterator2 = require('babel-runtime/core-js/get-iterator'); | ||
@@ -71,4 +75,5 @@ | ||
/** | ||
* Unregisters all proxied events from the target eventbus and removes any local references. All subsequent calls | ||
* after `destroy` has been called result in a ReferenceError thrown. | ||
* Creates a new EventProxy from the target eventbus of this proxy. | ||
* | ||
* @returns {EventProxy} | ||
*/ | ||
@@ -78,2 +83,13 @@ | ||
(0, _createClass3.default)(EventProxy, [{ | ||
key: 'createEventProxy', | ||
value: function createEventProxy() { | ||
return new EventProxy(this._eventbus); | ||
} | ||
/** | ||
* Unregisters all proxied events from the target eventbus and removes any local references. All subsequent calls | ||
* after `destroy` has been called result in a ReferenceError thrown. | ||
*/ | ||
}, { | ||
key: 'destroy', | ||
@@ -121,15 +137,17 @@ value: function destroy() { | ||
}, { | ||
key: 'forEachEvent', | ||
key: 'getEventNames', | ||
/** | ||
* Iterates over all proxied events invoking a callback with the event data stored. | ||
* Returns the event names of proxied event listeners. | ||
* | ||
* @param {function} callback - Callback invoked for each proxied event stored. | ||
* @returns {string[]} | ||
*/ | ||
value: function forEachEvent(callback) { | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('\'callback\' is not a \'function\'.'); | ||
value: function getEventNames() { | ||
if (!this._events) { | ||
return []; | ||
} | ||
var eventNames = {}; | ||
var _iteratorNormalCompletion2 = true; | ||
@@ -142,3 +160,3 @@ var _didIteratorError2 = false; | ||
var event = _step2.value; | ||
callback(event.name, event.callback, event.context); | ||
eventNames[event.name] = true; | ||
} | ||
@@ -159,5 +177,45 @@ } catch (err) { | ||
} | ||
return (0, _keys2.default)(eventNames); | ||
} | ||
/** | ||
* Iterates over all proxied events invoking a callback with the event data stored. | ||
* | ||
* @param {function} callback - Callback invoked for each proxied event stored. | ||
*/ | ||
}, { | ||
key: 'forEachEvent', | ||
value: function forEachEvent(callback) { | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('\'callback\' is not a \'function\'.'); | ||
} | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator3 = (0, _getIterator3.default)(this._events), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var event = _step3.value; | ||
callback(event.name, event.callback, event.context); | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Returns the target eventbus name. | ||
@@ -209,22 +267,22 @@ * | ||
if (!hasName && !hasCallback && !hasContext) { | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator3 = (0, _getIterator3.default)(this._events), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var event = _step3.value; | ||
for (var _iterator4 = (0, _getIterator3.default)(this._events), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var event = _step4.value; | ||
this._eventbus.off(event.name, event.callback, event.context); | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
@@ -301,33 +359,2 @@ } | ||
/** | ||
* Just like `on`, but causes the bound callback to fire only once before being removed. Handy for saying "the next | ||
* time that X happens, do this". When multiple events are passed in using the space separated syntax, the event | ||
* will fire once for every event you passed in, not once for a combination of all events | ||
* | ||
* This is proxied through `listenToOnce` of an internal Events instance instead of directly modifying the target | ||
* eventbus. | ||
* | ||
* Please see {@link Events#once}. | ||
* | ||
* @param {string} name - Event name(s) | ||
* @param {function} callback - Event callback function | ||
* @param {object} context - Event context | ||
* | ||
* @returns {EventProxy} | ||
*/ | ||
}, { | ||
key: 'once', | ||
value: function once(name, callback) { | ||
var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : void 0; | ||
if (this._eventbus === null) { | ||
throw new ReferenceError('This EventProxy instance has been destroyed.'); | ||
} | ||
this._eventbus.once(name, callback, context); | ||
return this; | ||
} | ||
/** | ||
* Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be | ||
@@ -334,0 +361,0 @@ * passed along to the event callbacks. |
@@ -200,3 +200,3 @@ 'use strict'; | ||
* @type {*} | ||
* @private | ||
* @protected | ||
*/ | ||
@@ -203,0 +203,0 @@ this._events = s_EVENTS_API(s_OFF_API, this._events, name, callback, { context: context, listeners: this._listeners }); |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
@@ -20,2 +16,10 @@ | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
var _getIterator2 = require('babel-runtime/core-js/get-iterator'); | ||
var _getIterator3 = _interopRequireDefault(_getIterator2); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
@@ -49,2 +53,6 @@ | ||
var _EventProxy = require('./EventProxy.js'); | ||
var _EventProxy2 = _interopRequireDefault(_EventProxy); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -84,5 +92,6 @@ | ||
/** | ||
* Returns the current eventbusName. | ||
* Creates an EventProxy wrapping this events instance. An EventProxy proxies events allowing all listeners added | ||
* to be easily removed from the wrapped Events instance. | ||
* | ||
* @returns {string|*} | ||
* @returns {EventProxy} | ||
*/ | ||
@@ -92,3 +101,69 @@ | ||
(0, _createClass3.default)(TyphonEvents, [{ | ||
key: 'createEventProxy', | ||
value: function createEventProxy() { | ||
return new _EventProxy2.default(this); | ||
} | ||
/** | ||
* Iterates over all stored events invoking a callback with the event data stored. | ||
* | ||
* @param {function} callback - Callback invoked for each proxied event stored. | ||
*/ | ||
}, { | ||
key: 'forEachEvent', | ||
value: function forEachEvent(callback) { | ||
/* istanbul ignore if */ | ||
if (!this._events) { | ||
return; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('\'callback\' is not a \'function\'.'); | ||
} | ||
for (var name in this._events) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(this._events[name]), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var event = _step.value; | ||
callback(name, event.callback, event.ctx); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Returns the current proxied event count. | ||
* | ||
* @returns {Number} | ||
*/ | ||
}, { | ||
key: 'getEventbusName', | ||
/** | ||
* Returns the current eventbusName. | ||
* | ||
* @returns {string|*} | ||
*/ | ||
value: function getEventbusName() { | ||
@@ -99,2 +174,19 @@ return this._eventbusName; | ||
/** | ||
* Returns the event names of registered event listeners. | ||
* | ||
* @returns {string[]} | ||
*/ | ||
}, { | ||
key: 'getEventNames', | ||
value: function getEventNames() { | ||
/* istanbul ignore if */ | ||
if (!this._events) { | ||
return []; | ||
} | ||
return (0, _keys2.default)(this._events); | ||
} | ||
/** | ||
* Sets the eventbus name. | ||
@@ -192,2 +284,13 @@ * | ||
} | ||
}, { | ||
key: 'eventCount', | ||
get: function get() { | ||
var count = 0; | ||
for (var name in this._events) { | ||
count += this._events[name].length; | ||
} | ||
return count; | ||
} | ||
}]); | ||
@@ -194,0 +297,0 @@ return TyphonEvents; |
{ | ||
"name": "backbone-esnext-events", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"homepage": "https://github.com/typhonjs-backbone-esnext/backbone-esnext-events", | ||
@@ -5,0 +5,0 @@ "description": "Separates 'events' support from Backbone in addition to adding TyphonJS extensions.", |
@@ -49,2 +49,12 @@ import TyphonEvents from './TyphonEvents.js'; | ||
/** | ||
* Creates a new EventProxy from the target eventbus of this proxy. | ||
* | ||
* @returns {EventProxy} | ||
*/ | ||
createEventProxy() | ||
{ | ||
return new EventProxy(this._eventbus); | ||
} | ||
/** | ||
* Unregisters all proxied events from the target eventbus and removes any local references. All subsequent calls | ||
@@ -75,2 +85,18 @@ * after `destroy` has been called result in a ReferenceError thrown. | ||
/** | ||
* Returns the event names of proxied event listeners. | ||
* | ||
* @returns {string[]} | ||
*/ | ||
getEventNames() | ||
{ | ||
if (!this._events) { return []; } | ||
const eventNames = {}; | ||
for (const event of this._events) { eventNames[event.name] = true; } | ||
return Object.keys(eventNames); | ||
} | ||
/** | ||
* Iterates over all proxied events invoking a callback with the event data stored. | ||
@@ -188,30 +214,2 @@ * | ||
/** | ||
* Just like `on`, but causes the bound callback to fire only once before being removed. Handy for saying "the next | ||
* time that X happens, do this". When multiple events are passed in using the space separated syntax, the event | ||
* will fire once for every event you passed in, not once for a combination of all events | ||
* | ||
* This is proxied through `listenToOnce` of an internal Events instance instead of directly modifying the target | ||
* eventbus. | ||
* | ||
* Please see {@link Events#once}. | ||
* | ||
* @param {string} name - Event name(s) | ||
* @param {function} callback - Event callback function | ||
* @param {object} context - Event context | ||
* | ||
* @returns {EventProxy} | ||
*/ | ||
once(name, callback, context = void 0) | ||
{ | ||
if (this._eventbus === null) | ||
{ | ||
throw new ReferenceError('This EventProxy instance has been destroyed.'); | ||
} | ||
this._eventbus.once(name, callback, context); | ||
return this; | ||
} | ||
/** | ||
* Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be | ||
@@ -218,0 +216,0 @@ * passed along to the event callbacks. |
@@ -156,3 +156,3 @@ /** | ||
* @type {*} | ||
* @private | ||
* @protected | ||
*/ | ||
@@ -159,0 +159,0 @@ this._events = s_EVENTS_API(s_OFF_API, this._events, name, callback, { context, listeners: this._listeners }); |
@@ -1,2 +0,3 @@ | ||
import Events from './Events.js'; | ||
import Events from './Events.js'; | ||
import EventProxy from './EventProxy.js'; | ||
@@ -31,2 +32,49 @@ /** | ||
/** | ||
* Creates an EventProxy wrapping this events instance. An EventProxy proxies events allowing all listeners added | ||
* to be easily removed from the wrapped Events instance. | ||
* | ||
* @returns {EventProxy} | ||
*/ | ||
createEventProxy() | ||
{ | ||
return new EventProxy(this); | ||
} | ||
/** | ||
* Iterates over all stored events invoking a callback with the event data stored. | ||
* | ||
* @param {function} callback - Callback invoked for each proxied event stored. | ||
*/ | ||
forEachEvent(callback) | ||
{ | ||
/* istanbul ignore if */ | ||
if (!this._events) { return; } | ||
/* istanbul ignore if */ | ||
if (typeof callback !== 'function') { throw new TypeError(`'callback' is not a 'function'.`); } | ||
for (const name in this._events) | ||
{ | ||
for (const event of this._events[name]) | ||
{ | ||
callback(name, event.callback, event.ctx); | ||
} | ||
} | ||
} | ||
/** | ||
* Returns the current proxied event count. | ||
* | ||
* @returns {Number} | ||
*/ | ||
get eventCount() | ||
{ | ||
let count = 0; | ||
for (const name in this._events) { count += this._events[name].length; } | ||
return count; | ||
} | ||
/** | ||
* Returns the current eventbusName. | ||
@@ -42,2 +90,15 @@ * | ||
/** | ||
* Returns the event names of registered event listeners. | ||
* | ||
* @returns {string[]} | ||
*/ | ||
getEventNames() | ||
{ | ||
/* istanbul ignore if */ | ||
if (!this._events) { return []; } | ||
return Object.keys(this._events); | ||
} | ||
/** | ||
* Sets the eventbus name. | ||
@@ -44,0 +105,0 @@ * |
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
116744
2480