1.1.2 • Published 5 years ago

type-redux-rxjs v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

type-redux的Rxjs中间件

npm version Build Status Coverage Status

灵感来自 redux-observable , 但为type-redux定制。

快速开始

  1. 安装
npm install type-redux-rxjs
  1. 创建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>;
  1. 创建action
export function cancel(ctx: ICtx<string>, _: string) {
  return ctx.curAction$.pipe(
    tap(() => ctx.commit('loading', 'canel'))
  );
  1. dispatch
store.dispatch('cancel')

API

action函数中第一个参数为context

name说明
curAction$当前的action流
action$所有的action流
createAction$创建action流
1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago