From 1376c0311390fb2809aaf3bf86f268c1caf3734e Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Thu, 26 Sep 2019 09:00:33 +0100 Subject: [PATCH] refactoring events sharing --- extras/README.md | 12 ++++++------ extras/src/from-emitter.ts | 2 +- extras/src/from-event.ts | 2 +- extras/src/from-interval.ts | 2 +- extras/src/index.ts | 6 +++--- package.json | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/extras/README.md b/extras/README.md index c6f926e..d8ffdcf 100644 --- a/extras/README.md +++ b/extras/README.md @@ -14,7 +14,7 @@ easily do the same for any other type of event or resource in your project. Implemented in [src/from-event].
```ts -import {fromEvent, fromSharedEvent} from 'sub-events/ext'; +import {fromEvent, shareEvent} from 'sub-events/ext'; const onClick = fromEvent(document, 'click'); // creating 'click' event @@ -24,7 +24,7 @@ const sub = onClick.subscribe((e:Event) => { sub.cancel(); // cancel subscription when no longer needed ``` -And to share events across all subscribers, use `fromSharedEvent` instead. +And to share events across all subscribers, use `shareEvent` instead.
@@ -33,7 +33,7 @@ And to share events across all subscribers, use `fromSharedEvent` instead. Implemented in [src/from-emitter].
```ts -import {fromEmitter, fromSharedEmitter} from 'sub-events/ext'; +import {fromEmitter, shareEmitter} from 'sub-events/ext'; const e = new EventEmitter(); // our test emitter @@ -47,7 +47,7 @@ e.emit('receive', 1, 2, 3); // source emitter sends data sub.cancel(); // cancel subscription when no longer needed ``` -And to share events across all subscribers, use `fromSharedEmitter` instead. +And to share events across all subscribers, use `shareEmitter` instead.
@@ -56,7 +56,7 @@ And to share events across all subscribers, use `fromSharedEmitter` instead. Implemented in [src/from-interval].
```ts -import {fromInterval, fromSharedInterval} from 'sub-events/ext'; +import {fromInterval, shareInterval} from 'sub-events/ext'; const onInterval = fromInterval(1000); // creating 1-second interval event @@ -66,7 +66,7 @@ const sub = onInterval.subscribe((count: number) => { sub.cancel(); // cancel subscription when no longer needed ``` -And to share events across all subscribers, use `fromSharedInterval` instead. +And to share events across all subscribers, use `shareInterval` instead.
diff --git a/extras/src/from-emitter.ts b/extras/src/from-emitter.ts index f94bf86..2ade389 100644 --- a/extras/src/from-emitter.ts +++ b/extras/src/from-emitter.ts @@ -29,7 +29,7 @@ export function fromEmitter(source: EventEmitter, event: string | symbol, option * Variable number of arguments emitted with the event become an array * of values when they arrive into `subscribe` callback function. */ -export function fromSharedEmitter(source: EventEmitter, event: string | symbol, options?: IEmitOptions): SubEventCount { +export function shareEmitter(source: EventEmitter, event: string | symbol, options?: IEmitOptions): SubEventCount { const sec: SubEventCount = new SubEventCount(); const handler = (...args: any[]) => sec.emit(args, options); sec.onCount.subscribe(info => { diff --git a/extras/src/from-event.ts b/extras/src/from-event.ts index 5c34cd0..330ad9d 100644 --- a/extras/src/from-event.ts +++ b/extras/src/from-event.ts @@ -22,7 +22,7 @@ export function fromEvent(source: Node, event: string, options?: IEmitOptions): * - we call `addEventListener` whenever the first subscriber has been registered; * - we call `removeEventListener` after the last subscription has been cancelled. */ -export function fromSharedEvent(source: Node, event: string, options?: IEmitOptions): SubEventCount { +export function shareEvent(source: Node, event: string, options?: IEmitOptions): SubEventCount { const sec: SubEventCount = new SubEventCount(); const handler: EventListener = e => sec.emit(e, options); sec.onCount.subscribe(info => { diff --git a/extras/src/from-interval.ts b/extras/src/from-interval.ts index 0dee29f..ce17bdd 100644 --- a/extras/src/from-interval.ts +++ b/extras/src/from-interval.ts @@ -27,7 +27,7 @@ export function fromInterval(timeout: number, options?: IEmitOptions): SubEvent< * * The event is parameterized with its shared counter. */ -export function fromSharedInterval(timeout: number, options?: IEmitOptions): SubEventCount { +export function shareInterval(timeout: number, options?: IEmitOptions): SubEventCount { const sec: SubEventCount = new SubEventCount(); let timer: any, count = 0; // shared event counter sec.onCount.subscribe(info => { diff --git a/extras/src/index.ts b/extras/src/index.ts index d0bc569..70b204d 100644 --- a/extras/src/index.ts +++ b/extras/src/index.ts @@ -1,4 +1,4 @@ -export {fromEvent, fromSharedEvent} from './from-event'; -export {fromEmitter, fromSharedEmitter} from './from-emitter'; -export {fromInterval, fromSharedInterval} from './from-interval'; +export {fromEvent, shareEvent} from './from-event'; +export {fromEmitter, shareEmitter} from './from-emitter'; +export {fromInterval, shareInterval} from './from-interval'; export {TimeoutEvent, fromTimeout} from './from-timeout'; diff --git a/package.json b/package.json index 3180ab0..bf1003d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sub-events", - "version": "1.1.3", + "version": "1.2.0", "description": "Lightweight, strongly-typed events, with monitored subscriptions.", "main": "dist/src/index.js", "types": "dist/src/index.d.ts",