tsdux-observable
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

tsdux-observable

npm latest version npm total download github license github latest tag github commit from latest travis status codecov coverage

TSdux utilities for Observables.

The latest version supports RxJS version 6 only. If you want to use this package with RxJS version 5, see support-v5 branch (tsdux-observable@^2).

Table of Contents

How To Install

npm install --save redux rxjs tsdux tsdux-observable

API

ofType

function ofType<AC extends ActionCreator<string, any>>(
  actionCreators: AC | Array<AC>,
): (source: Observable<AnyAction>) => Observable<AC['action']>

Function for filtering actions with ActionCreators of tsdux.
This function filter out all actions except specified actions by ActionCreators.

const AddTest = action('app/test/ADD_TEST', props<{ id: number teststring }>());
const RemoveTest = action('app/test/REMOVE_TEST', props<{ id: number }>());
 
Observable([
  AddTest.create({ id: 0, test: '123' }),
  RemoveTest.create({ id: 0 }),
  AddTest.create({ id: 1, test: 'ABabABC' }),
])
  .let(ofType(AddTest))
  .subscribe((action) => {
    console.log(action);
    // first logs { type: 'app/test/ADD_TEST', id: 0, test: '123' }
    // and then logs { type: 'app/test/ADD_TEST', id: 1, test: 'ABabABC' }
  });

toPayload

function toPayload<PA extends PayloadAction<string, any>>(): (source: Observable<PA>) => Observable<PA['payload']>

Function for mapping Observable of PayloadAction to Observable of payload property.

Observable([
  action('abc', payload<string>()).create('d012d@!gWE'),
  action('ttt', payload<number>()).create(178),
])
  .let(toPayload())
  .toArray()
  .subscribe((result) => {
    console.log(result) // ['d012d@!gWE', 178]
  });

Author

Junyoung Clare Jang @Ailrun

Package Sidebar

Install

npm i tsdux-observable

Weekly Downloads

25

Version

4.0.1

License

MIT

Unpacked Size

10.1 kB

Total Files

22

Last publish

Collaborators

  • ailrun