https://github.com/j-xzy/type-redux-rxjs
type-redux的rxjs中间件
https://github.com/j-xzy/type-redux-rxjs
Last synced: 3 months ago
JSON representation
type-redux的rxjs中间件
- Host: GitHub
- URL: https://github.com/j-xzy/type-redux-rxjs
- Owner: j-xzy
- Created: 2019-04-15T07:39:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-14T05:52:56.000Z (almost 6 years ago)
- Last Synced: 2025-02-21T20:43:02.339Z (3 months ago)
- Language: TypeScript
- Size: 158 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# type-redux的Rxjs中间件
[](https://badge.fury.io/js/type-redux-rxjs)
[](https://www.travis-ci.org/whj1995/type-redux-rxjs)
[](https://coveralls.io/github/whj1995/type-redux-rxjs?branch=master)灵感来自 [redux-observable](https://github.com/redux-observable/redux-observable) , 但为type-redux定制。
## 快速开始
1. 安装
```
npm install type-redux-rxjs
```2. 创建store并定义类型
``` ts
// ./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 = TypeRedux.IRxContext;
```3. 创建action
``` ts
export function cancel(ctx: ICtx, _: string) {
return ctx.curAction$.pipe(
tap(() => ctx.commit('loading', 'canel'))
);
```4. dispatch
``` ts
store.dispatch('cancel')
```## API
action函数中第一个参数为context
| name | 说明 |
|---|---|
| curAction$ | 当前的action流 |
| action$ | 所有的action流 |
| createAction$ | 创建action流 |