0.2.0 • Published 3 years ago

rxjs-signal v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Installation and Usage

ES6 via npm

npm i rxjs-signal

Function ca stands for create signal.

The type of ca is cs<P1, P2, R>(modifier?: SignalModifier<P1, P2, R>): Signal<P1, P2, R>. P1 is input payload type, P2 is output payload type, R is a return type.

import { ca } from "rxjs-signal";

const signal = cs<number>();

signal.$.subscribe(console.log);

signal(1);

const curried = signal._(2);

curried();

// You will see in console:
// 1
// 2

Interfaces

Basically signal is a function with static props:

  • $ shared Observable
  • _ currying helper (payload: P1) => () => signal(payload)
interface Signal<P1 = void, P2 = P1, R = void> {
  $: Observable<P2>
  _: (...args: P1 extends void ? unknown[] : [P1]) => () => R
  (...args: P1 extends void ? unknown[] : [P1]): R
}

type SignalModifier<P1, P2, R> = (emit: (payloadOutput: P2) => void, payloadInput: P1) => R

General signal stream signalWave$

It's regular RxJS Subject which is used to emit every signal call. You should avoid to directly call it's next, error and complite methods. You can subscribe to signalWave$ in case you need more control over the signal sequence or if you want to conditionally recall some signal.

interface SignalWave {
  signal: Signal<unknown>
  modifier?: SignalModifier<unknown, unknown, unknown>
  payload: unknown
}

export const signalWave$ = new Subject<SignalWave>()

Debug mode

For dev environment you can activate debug mode by calling signalDebug. It will subscribe to signalWave$ and it'll print all waves into the console.

import { signalDebug } from 'rxjs-signal';

if (process.env.NODE_ENV !== 'production') {
  signalDebug();
}

Author

Dmitrii Bykov

License

Released under the MIT License

0.2.0

3 years ago

0.1.0-next.3

3 years ago

0.1.0

3 years ago

0.1.0-next.2

3 years ago

0.1.0-next.1

3 years ago