1.1.2 • Published 5 years ago
type-redux-rxjs v1.1.2
type-redux的Rxjs中间件
灵感来自 redux-observable , 但为type-redux定制。
快速开始
- 安装
npm install type-redux-rxjs
- 创建store并定义类型
// ./index.ts
import { createRxjsMiddleware } from 'type-redux-rxjs';
import { applyMiddleware, createStore } from 'type-redux';
import * as actions from './actions';
import * as mutations from './mutations';
...
const reducers = { mutations, actions };
export const store = createStore(initialState, reducers, applyMiddleware(createRxjsMiddleware(actions)));
export type ICtx<T> = TypeRedux.IRxContext<IState, typeof reducers['mutations'], typeof reducers['actions'], T>;
- 创建action
export function cancel(ctx: ICtx<string>, _: string) {
return ctx.curAction$.pipe(
tap(() => ctx.commit('loading', 'canel'))
);
- dispatch
store.dispatch('cancel')
API
action函数中第一个参数为context
name | 说明 |
---|---|
curAction$ | 当前的action流 |
action$ | 所有的action流 |
createAction$ | 创建action流 |