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).
npm install --save redux rxjs tsdux tsdux-observable
function ofType<AC extends ActionCreator<string, any>>(
actionCreators: AC | Array<AC>,
): (source: Observable<AnyAction>) => Observable<AC['action']>
Function for filtering actions with ActionCreator
s of tsdux.
This function filter out all actions except specified actions by ActionCreator
s.
const AddTest = action('app/test/ADD_TEST', props<{ id: number test: string }>());
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' }
});
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]
});
Junyoung Clare Jang @Ailrun