Skip to content

Commit

Permalink
refactoring events sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Sep 26, 2019
1 parent 24d6c99 commit 1376c03
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions extras/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ easily do the same for any other type of event or resource in your project.
Implemented in [src/from-event].
<br/>
```ts
import {fromEvent, fromSharedEvent} from 'sub-events/ext';
import {fromEvent, shareEvent} from 'sub-events/ext';

const onClick = fromEvent(document, 'click'); // creating 'click' event

Expand All @@ -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.
</details>

<details>
Expand All @@ -33,7 +33,7 @@ And to share events across all subscribers, use `fromSharedEvent` instead.
Implemented in [src/from-emitter].
<br/>
```ts
import {fromEmitter, fromSharedEmitter} from 'sub-events/ext';
import {fromEmitter, shareEmitter} from 'sub-events/ext';

const e = new EventEmitter(); // our test emitter

Expand All @@ -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.
</details>

<details>
Expand All @@ -56,7 +56,7 @@ And to share events across all subscribers, use `fromSharedEmitter` instead.
Implemented in [src/from-interval].
<br/>
```ts
import {fromInterval, fromSharedInterval} from 'sub-events/ext';
import {fromInterval, shareInterval} from 'sub-events/ext';

const onInterval = fromInterval(1000); // creating 1-second interval event

Expand All @@ -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.
</details>

<details>
Expand Down
2 changes: 1 addition & 1 deletion extras/src/from-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any[]> {
export function shareEmitter(source: EventEmitter, event: string | symbol, options?: IEmitOptions): SubEventCount<any[]> {
const sec: SubEventCount<any[]> = new SubEventCount();
const handler = (...args: any[]) => sec.emit(args, options);
sec.onCount.subscribe(info => {
Expand Down
2 changes: 1 addition & 1 deletion extras/src/from-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> {
export function shareEvent(source: Node, event: string, options?: IEmitOptions): SubEventCount<Event> {
const sec: SubEventCount<Event> = new SubEventCount();
const handler: EventListener = e => sec.emit(e, options);
sec.onCount.subscribe(info => {
Expand Down
2 changes: 1 addition & 1 deletion extras/src/from-interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
export function shareInterval(timeout: number, options?: IEmitOptions): SubEventCount<number> {
const sec: SubEventCount<number> = new SubEventCount();
let timer: any, count = 0; // shared event counter
sec.onCount.subscribe(info => {
Expand Down
6 changes: 3 additions & 3 deletions extras/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 1376c03

Please sign in to comment.