Rx
Rx
is a convenience re-export of rxjs. Check this issue for motivation.
The entry point contains:
- all exports from
rxjs/operators
- Following exports from
rxjs
:
Subject
,forkJoin
,empty
,of
,timer
,from
,defer
,Observable
,interval
- Renamed exports from
rxjs
:concat
->concatObs
merge
->mergeObs
race
->raceObs
throwError
->throwObs
- Following exports from
rxjs/internal-compatibility
:
fromPromise
Additional operators
ofType(actionCreator)
Filter actions based on the provided action creator or action creators.
Arguments
actionCreator: AC | AC[]
- the action creator or array of action creators.
Returns
{OperatorFunction}
- the rxjs operator function.
Example
// symbol.ts
export const MySymbol = Symbol('my');
// interface.ts
import { createModule } from 'typeless';
import { MySymbol } from './symbol';
export const [handle, MyActions] = createModule(MySymbol)
.withActions({
loadUser: null,
userLoaded: (user: User) => ({ payload: { user } }),
cancel: null,
});
// module.ts
import * as Rx from 'typeless/rx';
import { handle, MyActions } from 'typeless';
handle.epic()
.on(MyActions.loadUser, (_, { action$ }) =>
API.loadUser().pipe(
Rx.map(user => MyActions.userLoader(user)),
// cancel operation if `MyActions.cancel()` is dispatched
Rx.takeUntil(action$.pipe(Rx.ofType(MyActions.cancel)))
)
);
waitForType(actionCreator)
Wait for a single action creator.
Arguments
actionCreator: AC
- the action creator to wait for.
Returns
{OperatorFunction}
- the rxjs operator function.
Example
// symbol.ts
export const MySymbol = Symbol('my');
// interface.ts
import { createModule } from 'typeless';
import { MySymbol } from './symbol';
export const [handle, MyActions] = createModule(MySymbol)
.withActions({
deleteUser: null,
userDeleted: null,
errorOccurred: null,
confirmDelete: (confirm: boolean) => ({ payload: { confirm } }),
});
// module.ts
import * as Rx from 'typeless/rx';
import { handle, MyActions } from 'typeless';
handle.epic()
// show a confirmation dialog and wait for Yes/No click
.on(MyActions.deleteUser, (_, { action$ }) =>
action$.pipe(
Rx.waitForType(MyActions.confirmDelete),
Rx.filter(action => action.payload.confirm)
Rx.mergeMap(() => API.deleteUser()),
Rx.mapTo(MyActions.userDeleted()),
Rx.catchError(e => {
console.error(e);
return Rx.of(MyActions.errorOccurred());
})
)
);