@boost/event
Advanced tools
Comparing version 1.3.1 to 2.0.0-alpha.1
@@ -7,3 +7,3 @@ "use strict"; | ||
const BaseEvent_1 = __importDefault(require("./BaseEvent")); | ||
const constants_1 = require("./constants"); | ||
const debug_1 = __importDefault(require("./debug")); | ||
class BailEvent extends BaseEvent_1.default { | ||
@@ -16,6 +16,6 @@ /** | ||
emit(args, scope) { | ||
constants_1.debug('Emitting "%s%s" as bail', this.name, scope ? `:${scope}` : ''); | ||
return Array.from(this.getListeners(scope)).some(listener => listener(...args) === false); | ||
debug_1.default('Emitting "%s%s" as bail', this.name, scope ? `:${scope}` : ''); | ||
return Array.from(this.getListeners(scope)).some((listener) => listener(...args) === false); | ||
} | ||
} | ||
exports.default = BailEvent; |
import { Listener, WildstarScope } from './types'; | ||
export default abstract class BaseEvent<Return, Args extends unknown[], Scope extends string = string> { | ||
listeners: Map<Scope | WildstarScope, Set<Listener<Args, Return>>>; | ||
listeners: Map<"*" | Scope, Set<Listener<Args, Return>>>; | ||
name: string; | ||
@@ -5,0 +5,0 @@ constructor(name: string); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const internal_1 = require("@boost/internal"); | ||
const EventError_1 = __importDefault(require("./EventError")); | ||
const debug_1 = __importDefault(require("./debug")); | ||
const constants_1 = require("./constants"); | ||
@@ -9,3 +13,3 @@ class BaseEvent { | ||
this.name = this.validateName(name, 'name'); | ||
constants_1.debug('New %S created: %s', this.constructor.name, name); | ||
debug_1.default('New %S created: %s', this.constructor.name, name); | ||
} | ||
@@ -44,3 +48,3 @@ /** | ||
listen(listener, scope) { | ||
constants_1.debug('Registering "%s" listener', this.name); | ||
debug_1.default('Registering "%s" listener', this.name); | ||
this.getListeners(scope).add(this.validateListener(listener)); | ||
@@ -64,3 +68,3 @@ return this; | ||
unlisten(listener, scope) { | ||
constants_1.debug('Unregistering "%s" listener', this.name); | ||
debug_1.default('Unregistering "%s" listener', this.name); | ||
this.getListeners(scope).delete(listener); | ||
@@ -74,3 +78,3 @@ return this; | ||
if (typeof listener !== 'function') { | ||
throw new internal_1.RuntimeError('event', 'EV_INVALID_LISTENER', [this.name]); | ||
throw new EventError_1.default('LISTENER_INVALID', [this.name]); | ||
} | ||
@@ -87,3 +91,3 @@ return listener; | ||
if (!name.match(constants_1.EVENT_NAME_PATTERN)) { | ||
throw new internal_1.RuntimeError('event', 'EV_INVALID_NAME', [type, name]); | ||
throw new EventError_1.default('NAME_INVALID', [type, name]); | ||
} | ||
@@ -90,0 +94,0 @@ return name; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const BaseEvent_1 = __importDefault(require("./BaseEvent")); | ||
const constants_1 = require("./constants"); | ||
const debug_1 = __importDefault(require("./debug")); | ||
class ConcurrentEvent extends BaseEvent_1.default { | ||
@@ -15,6 +15,6 @@ /** | ||
emit(args, scope) { | ||
constants_1.debug('Emitting "%s%s" as concurrent', this.name, scope ? `:${scope}` : ''); | ||
return Promise.all(Array.from(this.getListeners(scope)).map(listener => listener(...args))); | ||
debug_1.default('Emitting "%s%s" as concurrent', this.name, scope ? `:${scope}` : ''); | ||
return Promise.all(Array.from(this.getListeners(scope)).map((listener) => listener(...args))); | ||
} | ||
} | ||
exports.default = ConcurrentEvent; |
@@ -1,5 +0,3 @@ | ||
/// <reference types="debug" /> | ||
export declare const debug: import("debug").Debugger; | ||
export declare const WILDCARD_SCOPE = "*"; | ||
export declare const EVENT_NAME_PATTERN: RegExp; | ||
//# sourceMappingURL=constants.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const internal_1 = require("@boost/internal"); | ||
exports.debug = internal_1.createInternalDebugger('event'); | ||
exports.EVENT_NAME_PATTERN = exports.WILDCARD_SCOPE = void 0; | ||
exports.WILDCARD_SCOPE = '*'; | ||
exports.EVENT_NAME_PATTERN = /^[a-z]{1}[-.a-z0-9]*[a-z]{1}$/u; |
@@ -12,3 +12,3 @@ "use strict"; | ||
emit(args, scope) { | ||
Array.from(this.getListeners(scope)).forEach(listener => { | ||
Array.from(this.getListeners(scope)).forEach((listener) => { | ||
listener(...args); | ||
@@ -15,0 +15,0 @@ }); |
/** | ||
* @copyright 2017-2019, Miles Johnson | ||
* @copyright 2020, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
@@ -8,2 +8,3 @@ */ | ||
import Event from './Event'; | ||
import EventError, { EventErrorCode } from './EventError'; | ||
import ConcurrentEvent from './ConcurrentEvent'; | ||
@@ -13,3 +14,3 @@ import WaterfallEvent from './WaterfallEvent'; | ||
export * from './types'; | ||
export { BailEvent, BaseEvent, Event, ConcurrentEvent, WaterfallEvent }; | ||
export { BailEvent, BaseEvent, Event, EventError, EventErrorCode, ConcurrentEvent, WaterfallEvent }; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
/** | ||
* @copyright 2017-2019, Miles Johnson | ||
* @copyright 2020, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -13,2 +20,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WaterfallEvent = exports.ConcurrentEvent = exports.EventError = exports.Event = exports.BaseEvent = exports.BailEvent = void 0; | ||
const BailEvent_1 = __importDefault(require("./BailEvent")); | ||
@@ -20,2 +28,4 @@ exports.BailEvent = BailEvent_1.default; | ||
exports.Event = Event_1.default; | ||
const EventError_1 = __importDefault(require("./EventError")); | ||
exports.EventError = EventError_1.default; | ||
const ConcurrentEvent_1 = __importDefault(require("./ConcurrentEvent")); | ||
@@ -25,2 +35,3 @@ exports.ConcurrentEvent = ConcurrentEvent_1.default; | ||
exports.WaterfallEvent = WaterfallEvent_1.default; | ||
__export(require("./constants")); | ||
__exportStar(require("./constants"), exports); | ||
__exportStar(require("./types"), exports); |
@@ -7,3 +7,3 @@ "use strict"; | ||
const BaseEvent_1 = __importDefault(require("./BaseEvent")); | ||
const constants_1 = require("./constants"); | ||
const debug_1 = __importDefault(require("./debug")); | ||
class WaterfallEvent extends BaseEvent_1.default { | ||
@@ -15,3 +15,3 @@ /** | ||
emit(arg, scope) { | ||
constants_1.debug('Emitting "%s%s" as waterfall', this.name, scope ? `:${scope}` : ''); | ||
debug_1.default('Emitting "%s%s" as waterfall', this.name, scope ? `:${scope}` : ''); | ||
return Array.from(this.getListeners(scope)).reduce((nextValue, listener) => listener(nextValue), arg); | ||
@@ -18,0 +18,0 @@ } |
{ | ||
"name": "@boost/event", | ||
"version": "1.3.1", | ||
"description": "A type-safe event system. Designed for Boost applications.", | ||
"version": "2.0.0-alpha.1", | ||
"release": "1592788092197", | ||
"description": "A strict event system with multiple emitter patterns.", | ||
"keywords": [ | ||
@@ -13,5 +14,4 @@ "boost", | ||
"types": "./lib/index.d.ts", | ||
"nonce": "1579986563745", | ||
"engines": { | ||
"node": ">=8.9.0" | ||
"node": ">=10.17.0" | ||
}, | ||
@@ -24,3 +24,3 @@ "repository": "https://github.com/milesj/boost/tree/master/packages/event", | ||
"dependencies": { | ||
"@boost/internal": "^1.2.0" | ||
"@boost/internal": "^2.0.0-alpha.1" | ||
}, | ||
@@ -36,3 +36,3 @@ "tsconfig": { | ||
}, | ||
"gitHead": "c77dc723462d054d8b7bbe927e99efd7e4f75084" | ||
"gitHead": "3fffbcf3231b86592d2083902b8c39a2ed1b2e4c" | ||
} |
@@ -1,2 +0,2 @@ | ||
# Boost Event | ||
# Event - Boost | ||
@@ -7,3 +7,3 @@ [](https://github.com/milesj/boost/actions?query=branch%3Amaster) | ||
A strict type-safe event system with multiple emitter patterns. | ||
A strict event system with multiple emitter patterns. | ||
@@ -10,0 +10,0 @@ ```ts |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23786
34
319
2
+ Added@boost/internal@2.2.3(transitive)
- Removed@boost/internal@1.2.0(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedchalk@3.0.0(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)