An open API service indexing awesome lists of open source software.

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中间件

Awesome Lists containing this project

README

        

# type-redux的Rxjs中间件

[![npm version](https://badge.fury.io/js/type-redux-rxjs.svg)](https://badge.fury.io/js/type-redux-rxjs)
[![Build Status](https://www.travis-ci.org/whj1995/type-redux-rxjs.svg?branch=master)](https://www.travis-ci.org/whj1995/type-redux-rxjs)
[![Coverage Status](https://coveralls.io/repos/github/whj1995/type-redux-rxjs/badge.svg?branch=master)](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流 |