@bigtest/effection
Advanced tools
Comparing version 0.1.1-1fb52a3 to 0.1.1-23f2461
@@ -6,6 +6,4 @@ "use strict"; | ||
function ensure(fn) { | ||
return ({ resume, context }) => { | ||
let targetContext = context.parent; | ||
targetContext.ensure(fn); | ||
resume(null); | ||
return ({ resume, spawn }) => { | ||
resume(spawn(({ ensure }) => ensure(fn))); | ||
}; | ||
@@ -12,0 +10,0 @@ } |
@@ -1,6 +0,4 @@ | ||
export { once } from './events'; | ||
export { Deferred } from './deferred'; | ||
export { Mailbox, SubscriptionMessage, subscribe } from './mailbox'; | ||
export { any } from './pattern'; | ||
export { suspend } from './suspend'; | ||
export { ensure } from './ensure'; | ||
export { monitorErrors } from './monitor-errors'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var events_1 = require("./events"); | ||
exports.once = events_1.once; | ||
var deferred_1 = require("./deferred"); | ||
exports.Deferred = deferred_1.Deferred; | ||
var mailbox_1 = require("./mailbox"); | ||
@@ -10,8 +10,4 @@ exports.Mailbox = mailbox_1.Mailbox; | ||
exports.any = pattern_1.any; | ||
var suspend_1 = require("./suspend"); | ||
exports.suspend = suspend_1.suspend; | ||
var ensure_1 = require("./ensure"); | ||
exports.ensure = ensure_1.ensure; | ||
var monitor_errors_1 = require("./monitor-errors"); | ||
exports.monitorErrors = monitor_errors_1.monitorErrors; | ||
//# sourceMappingURL=index.js.map |
@@ -12,8 +12,9 @@ /// <reference types="node" /> | ||
private messages; | ||
static subscribe(emitter: EventEmitter | EventTarget, events: string | string[]): Operation<Mailbox<SubscriptionMessage>>; | ||
static subscribe(source: EventEmitter | EventTarget, events: string | string[]): Operation<Mailbox<SubscriptionMessage>>; | ||
setMaxListeners(value: number): void; | ||
send(message: T): void; | ||
receive(pattern?: unknown): Operation<T>; | ||
pipe(other: Mailbox<T>): Generator<Operation<any>, void, unknown>; | ||
pipe(other: Mailbox<T>): Generator<Operation<unknown>, any, unknown>; | ||
map<R>(fn: (from: T) => R): Operation<Mailbox<R>>; | ||
} | ||
export declare function subscribe(mailbox: Mailbox<SubscriptionMessage>, emitter: EventEmitter | EventTarget, events: string | string[]): Operation; | ||
export declare function subscribe(mailbox: Mailbox<SubscriptionMessage>, source: EventEmitter | EventTarget, events: string | string[]): Operation; |
@@ -8,5 +8,3 @@ "use strict"; | ||
exports.any = pattern_2.any; | ||
const suspend_1 = require("./suspend"); | ||
const ensure_1 = require("./ensure"); | ||
function isEventTarget(target) { return typeof target.addEventListener === 'function'; } | ||
const events_2 = require("@effection/events"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -18,10 +16,12 @@ class Mailbox { | ||
} | ||
static *subscribe(emitter, events) { | ||
static *subscribe(source, events) { | ||
let mailbox = new Mailbox(); | ||
yield suspend_1.suspend(effection_1.monitor(subscribe(mailbox, emitter, events))); | ||
return mailbox; | ||
return yield effection_1.resource(mailbox, subscribe(mailbox, source, events)); | ||
} | ||
setMaxListeners(value) { | ||
this.subscriptions.setMaxListeners(value); | ||
} | ||
send(message) { | ||
this.messages.add(message); | ||
this.subscriptions.emit('message', message); | ||
setTimeout(() => this.subscriptions.emit('message', message), 0); | ||
} | ||
@@ -50,3 +50,3 @@ receive(pattern = undefined) { | ||
let that = this; // eslint-disable-line @typescript-eslint/no-this-alias | ||
yield suspend_1.suspend(effection_1.monitor(function* () { | ||
return yield effection_1.spawn(function* () { | ||
while (true) { | ||
@@ -56,3 +56,3 @@ let message = yield that.receive(); | ||
} | ||
})); | ||
}); | ||
} | ||
@@ -62,3 +62,3 @@ *map(fn) { | ||
let other = new Mailbox(); | ||
yield suspend_1.suspend(effection_1.monitor(function* () { | ||
return yield effection_1.resource(other, function* () { | ||
while (true) { | ||
@@ -68,23 +68,20 @@ let message = yield that.receive(); | ||
} | ||
})); | ||
return other; | ||
}); | ||
} | ||
} | ||
exports.Mailbox = Mailbox; | ||
function* subscribe(mailbox, emitter, events) { | ||
for (let name of [].concat(events)) { | ||
let listener = (...args) => { | ||
mailbox.send({ event: name, args }); | ||
}; | ||
if (isEventTarget(emitter)) { | ||
emitter.addEventListener(name, listener); | ||
yield suspend_1.suspend(ensure_1.ensure(() => emitter.removeEventListener(name, listener))); | ||
function* subscribe(mailbox, source, events) { | ||
return yield effection_1.spawn(function* () { | ||
for (let name of typeof events === 'string' ? [events] : events) { | ||
yield effection_1.fork(function* () { | ||
let events = yield events_2.on(source, name); | ||
while (true) { | ||
let args = yield events.next(); | ||
mailbox.send({ event: name, args }); | ||
} | ||
}); | ||
} | ||
else { | ||
emitter.on(name, listener); | ||
yield suspend_1.suspend(ensure_1.ensure(() => emitter.off(name, listener))); | ||
} | ||
} | ||
}); | ||
} | ||
exports.subscribe = subscribe; | ||
//# sourceMappingURL=mailbox.js.map |
export declare function compile(pattern: unknown): (target: unknown) => boolean; | ||
export declare function any(type: unknown): (value: unknown) => boolean; | ||
export declare function any(type: unknown): ((value: unknown) => boolean) | (() => boolean); |
@@ -9,6 +9,6 @@ "use strict"; | ||
else if (Array.isArray(pattern)) { | ||
return pattern.every((value, index) => compile(value)(target[index])); | ||
return Array.isArray(target) && pattern.every((value, index) => compile(value)(target[index])); | ||
} | ||
else if (typeof (pattern) === "object") { | ||
return Object.entries(pattern).every(([key, value]) => compile(value)(target[key])); | ||
return typeof (target) === 'object' && pattern !== null && Object.entries(pattern).every(([key, value]) => compile(value)(target && target[key])); | ||
} | ||
@@ -15,0 +15,0 @@ else if (typeof (pattern) === "function") { |
{ | ||
"name": "@bigtest/effection", | ||
"version": "0.1.1-1fb52a3", | ||
"version": "0.1.1-23f2461", | ||
"description": "Collection of handly utilities for working with effection. May find a different home later", | ||
@@ -18,7 +18,9 @@ "main": "dist/index.js", | ||
"mocha": "mocha -r ts-node/register", | ||
"prepack": "tsc --outdir dist --project tsconfig.dist.json --declaration --sourcemap --module commonjs" | ||
"prepack": "tsc --outdir dist --declaration --sourcemap" | ||
}, | ||
"devDependencies": { | ||
"@frontside/tsconfig": "*", | ||
"@types/mocha": "^7.0.1", | ||
"@types/node": "^12.7.11", | ||
"@types/node": "^13.13.4", | ||
"effection": "^0.6.0", | ||
"expect": "^24.9.0", | ||
@@ -28,5 +30,8 @@ "mocha": "^6.2.2", | ||
}, | ||
"peerDependencies": { | ||
"effection": "^0.6.0" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^12.7.11", | ||
"effection": "0.5.2" | ||
"@effection/events": "^0.6.1", | ||
"@types/node": "^13.13.4" | ||
}, | ||
@@ -33,0 +38,0 @@ "volta": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
13200
3
7
18
190
+ Added@effection/events@^0.6.1
+ Added@effection/events@0.6.1(transitive)
+ Added@types/node@13.13.52(transitive)
+ Addedeffection@0.6.4(transitive)
- Removedeffection@0.5.2
- Removed@types/node@12.20.55(transitive)
- Removedeffection@0.5.2(transitive)
Updated@types/node@^13.13.4