Comparing version 0.29.1 to 0.30.0
export var APP_NAME_PATTERN = /^[-a-z]+$/; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
export var APP_NAME_PATTERN = /^[-a-z.]+$/; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
@@ -9,0 +9,0 @@ export var MODULE_NAME_PATTERN = /^(@[-a-z]+\/)?[-a-z]+$/; |
@@ -18,11 +18,21 @@ import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray'; | ||
this.listeners = {}; | ||
this.namespace = ''; | ||
} | ||
_createClass(Emitter, [{ | ||
key: 'createEventName', | ||
value: function createEventName(name) { | ||
if (this.namespace && !name.startsWith(this.namespace)) { | ||
return this.namespace + '.' + name; | ||
} | ||
return name; | ||
} | ||
}, { | ||
key: 'emit', | ||
value: function emit(eventName) { | ||
value: function emit(name) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var initialValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var event = new Event(eventName, initialValue); | ||
var event = new Event(this.createEventName(name), initialValue); | ||
@@ -39,7 +49,7 @@ Array.from(this.getListeners(event.name)).some(function (listener) { | ||
key: 'emitCascade', | ||
value: function emitCascade(eventName) { | ||
value: function emitCascade(name) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var initialValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var event = new Event(eventName, initialValue); | ||
var event = new Event(this.createEventName(name), initialValue); | ||
var listeners = Array.from(this.getListeners(event.name)); | ||
@@ -84,3 +94,3 @@ var index = 0; | ||
if (!eventName.match(APP_NAME_PATTERN)) { | ||
throw new Error('Invalid event name "' + eventName + '". ' + 'May only contain dashes and lowercase characters.'); | ||
throw new Error('Invalid event name "' + eventName + '". ' + 'May only contain dashes, periods, and lowercase characters.'); | ||
} | ||
@@ -112,2 +122,16 @@ | ||
} | ||
}, { | ||
key: 'setEventNamespace', | ||
value: function setEventNamespace(namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
}, { | ||
key: 'removeEventNamespace', | ||
value: function removeEventNamespace() { | ||
this.namespace = ''; | ||
return this; | ||
} | ||
}]); | ||
@@ -114,0 +138,0 @@ |
@@ -6,7 +6,7 @@ 'use strict'; | ||
}); | ||
var APP_NAME_PATTERN = exports.APP_NAME_PATTERN = /^[-a-z]+$/; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var APP_NAME_PATTERN = exports.APP_NAME_PATTERN = /^[-a-z.]+$/; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
@@ -13,0 +13,0 @@ var MODULE_NAME_PATTERN = exports.MODULE_NAME_PATTERN = /^(@[-a-z]+\/)?[-a-z]+$/; |
@@ -37,11 +37,21 @@ 'use strict'; | ||
this.listeners = {}; | ||
this.namespace = ''; | ||
} | ||
(0, _createClass3.default)(Emitter, [{ | ||
key: 'createEventName', | ||
value: function createEventName(name) { | ||
if (this.namespace && !name.startsWith(this.namespace)) { | ||
return this.namespace + '.' + name; | ||
} | ||
return name; | ||
} | ||
}, { | ||
key: 'emit', | ||
value: function emit(eventName) { | ||
value: function emit(name) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var initialValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var event = new _Event2.default(eventName, initialValue); | ||
var event = new _Event2.default(this.createEventName(name), initialValue); | ||
@@ -58,7 +68,7 @@ Array.from(this.getListeners(event.name)).some(function (listener) { | ||
key: 'emitCascade', | ||
value: function emitCascade(eventName) { | ||
value: function emitCascade(name) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var initialValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var event = new _Event2.default(eventName, initialValue); | ||
var event = new _Event2.default(this.createEventName(name), initialValue); | ||
var listeners = Array.from(this.getListeners(event.name)); | ||
@@ -103,3 +113,3 @@ var index = 0; | ||
if (!eventName.match(_constants.APP_NAME_PATTERN)) { | ||
throw new Error('Invalid event name "' + eventName + '". ' + 'May only contain dashes and lowercase characters.'); | ||
throw new Error('Invalid event name "' + eventName + '". ' + 'May only contain dashes, periods, and lowercase characters.'); | ||
} | ||
@@ -131,2 +141,16 @@ | ||
} | ||
}, { | ||
key: 'setEventNamespace', | ||
value: function setEventNamespace(namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
}, { | ||
key: 'removeEventNamespace', | ||
value: function removeEventNamespace() { | ||
this.namespace = ''; | ||
return this; | ||
} | ||
}]); | ||
@@ -133,0 +157,0 @@ return Emitter; |
{ | ||
"name": "boost", | ||
"version": "0.29.1", | ||
"version": "0.30.0", | ||
"description": "Robust pipeline for creating build tools that separate logic into routines and tasks.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -9,3 +9,3 @@ /** | ||
export const APP_NAME_PATTERN: RegExp = /^[-a-z]+$/; | ||
export const APP_NAME_PATTERN: RegExp = /^[-a-z.]+$/; | ||
export const MODULE_NAME_PATTERN: RegExp = /^(@[-a-z]+\/)?[-a-z]+$/; | ||
@@ -12,0 +12,0 @@ export const PLUGIN_NAME_PATTERN: RegExp = /^[a-z]+:[-a-z]+$/; |
@@ -15,7 +15,20 @@ /** | ||
namespace: string = ''; | ||
/** | ||
* Create an event name with optional namespace. | ||
*/ | ||
createEventName(name: string): string { | ||
if (this.namespace && !name.startsWith(this.namespace)) { | ||
return `${this.namespace}.${name}`; | ||
} | ||
return name; | ||
} | ||
/** | ||
* Syncronously execute listeners for the defined event and arguments. | ||
*/ | ||
emit(eventName: string, args?: EventArguments = [], initialValue?: * = null): Event { | ||
const event = new Event(eventName, initialValue); | ||
emit(name: string, args?: EventArguments = [], initialValue?: * = null): Event { | ||
const event = new Event(this.createEventName(name), initialValue); | ||
@@ -35,4 +48,4 @@ Array.from(this.getListeners(event.name)).some((listener) => { | ||
*/ | ||
emitCascade(eventName: string, args?: EventArguments = [], initialValue?: * = null): Event { | ||
const event = new Event(eventName, initialValue); | ||
emitCascade(name: string, args?: EventArguments = [], initialValue?: * = null): Event { | ||
const event = new Event(this.createEventName(name), initialValue); | ||
const listeners = Array.from(this.getListeners(event.name)); | ||
@@ -80,3 +93,3 @@ let index = 0; | ||
`Invalid event name "${eventName}". ` + | ||
'May only contain dashes and lowercase characters.', | ||
'May only contain dashes, periods, and lowercase characters.', | ||
); | ||
@@ -113,2 +126,20 @@ } | ||
} | ||
/** | ||
* Set the namespace. | ||
*/ | ||
setEventNamespace(namespace: string): this { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
/** | ||
* Remove the namespace. | ||
*/ | ||
removeEventNamespace(): this { | ||
this.namespace = ''; | ||
return this; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
373685
4629