@bigtest/effection
Advanced tools
Comparing version 0.1.1-69e86af to 0.1.1-6b0bb51
@@ -1,5 +0,4 @@ | ||
export { once } from './events'; | ||
export { Deferred } from './deferred'; | ||
export { Mailbox, SubscriptionMessage, subscribe } from './mailbox'; | ||
export { any } from './pattern'; | ||
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"); | ||
@@ -12,4 +12,2 @@ exports.Mailbox = mailbox_1.Mailbox; | ||
exports.ensure = ensure_1.ensure; | ||
var monitor_errors_1 = require("./monitor-errors"); | ||
exports.monitorErrors = monitor_errors_1.monitorErrors; | ||
//# sourceMappingURL=index.js.map |
@@ -0,4 +1,5 @@ | ||
/// <reference types="node" /> | ||
import { Operation } from 'effection'; | ||
import { EventEmitter } from 'events'; | ||
export { any } from './pattern'; | ||
import { EventSource } from './event-source'; | ||
export interface SubscriptionMessage { | ||
@@ -11,8 +12,9 @@ event: string; | ||
private messages; | ||
static subscribe(source: EventSource, 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<never>, any, 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>, source: EventSource, events: string | string[]): Operation; | ||
export declare function subscribe(mailbox: Mailbox<SubscriptionMessage>, source: EventEmitter | EventTarget, events: string | string[]): Operation; |
@@ -8,4 +8,3 @@ "use strict"; | ||
exports.any = pattern_2.any; | ||
const ensure_1 = require("./ensure"); | ||
const event_source_1 = require("./event-source"); | ||
const events_2 = require("@effection/events"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -21,2 +20,5 @@ class Mailbox { | ||
} | ||
setMaxListeners(value) { | ||
this.subscriptions.setMaxListeners(value); | ||
} | ||
send(message) { | ||
@@ -69,12 +71,11 @@ this.messages.add(message); | ||
return yield effection_1.spawn(function* () { | ||
for (let name of [].concat(events)) { | ||
let listener = (...args) => { | ||
mailbox.send({ event: name, args }); | ||
}; | ||
event_source_1.addListener(source, name, listener); | ||
yield ensure_1.ensure(() => { | ||
event_source_1.removeListener(source, name, listener); | ||
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 }); | ||
} | ||
}); | ||
} | ||
yield; | ||
}); | ||
@@ -81,0 +82,0 @@ } |
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-69e86af", | ||
"version": "0.1.1-6b0bb51", | ||
"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 --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,6 +30,9 @@ "mocha": "^6.2.2", | ||
}, | ||
"dependencies": { | ||
"@types/node": "^12.7.11", | ||
"peerDependencies": { | ||
"effection": "^0.6.0" | ||
}, | ||
"dependencies": { | ||
"@effection/events": "^0.6.1", | ||
"@types/node": "^13.13.4" | ||
}, | ||
"volta": { | ||
@@ -34,0 +39,0 @@ "node": "12.16.0", |
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
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)
- Removedeffection@^0.6.0
- Removed@types/node@12.20.55(transitive)
Updated@types/node@^13.13.4