# ppx

> ppx flux redux react

Latest version **2.0.6** (published 2018-02-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install ppx
pnpm add ppx
yarn add ppx
bun add ppx
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.6 |
| Published | 2018-02-02 |
| First published | 2017-03-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | tianwu |
| Maintainers | qingmeng, tianwu |
| Keywords | ppx, flux, redux, react |

## Links

- npm: https://www.npmjs.com/package/ppx
- Repository: https://github.com/yejinjian/ppx
- Homepage: https://github.com/yejinjian/ppx#readme
- Issues: https://github.com/yejinjian/ppx/issues
- npm.io page: https://npm.io/package/ppx

## Dependencies (4)

- [react](https://npm.io/package/react.md) ^16.2.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.2.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [promise-polyfill](https://npm.io/package/promise-polyfill.md) ^6.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.6 (latest) — 2018-02-02
- 2.0.5 — 2018-02-02
- 2.0.4 — 2018-01-04
- 2.0.3 — 2017-12-12
- 2.0.2 — 2017-12-11
- 2.0.1 — 2017-12-11
- 2.0.0 — 2017-12-11
- 1.3.3 — 2017-12-06
- 1.3.2 — 2017-12-06
- 1.3.1 — 2017-12-06
- 1.3.0 — 2017-12-06
- 1.2.0 — 2017-10-31
- 1.1.7 — 2017-10-13
- 1.1.6 — 2017-10-13
- 1.1.5 — 2017-10-13
- … 15 more at https://npm.io/package/ppx/versions

## README

## 设计概要
ppx(皮皮虾)是一个遵循flux思想的数据管理工具。

* one store 原则
  不同于redux, 我们摒弃reduce 的设计，改用了model的思想，考虑到model与view存在多对多的情况， 统一由一个store管理
* suport middleware
  与redux类同，也支持中间件，因为考虑到异步的缘故，目前是与redux的中间件不同，后期考虑支持redux中间件
* promisefy
  支持promise，不仅是model支持异步，而且中间件也支持异步
* suport react
  依然是flux的思想，那么支持react是必然的，后期考虑支持vue等其他的库

```
 npm install --save ppx
```  
  
## 接入说明

model引用
```
    import Store from 'ppx';
    class App {
        constructor() {
            this.state = {
              a: 1,
              b: 2
            };
        }
        test(state, action){
            return {
                ...state,
                aciton.test
            }
        }
        post (state, action){
            return Ajax(action.url).then(function(rep){
                return {
                    ...state,
                    a: rep.a
                }
            })
        }
    }
    Store.model(App);
```

middleware引用
```
    import Store from 'ppx';
    var middleware = (next, action)=>{
      console.log('plugin start:', action);
      const data = await next(action);
      console.log('plugin end:', data);
      return data;
    }
    Store.use(middleware);
```

view 调用

```
import React from 'react';
import {connect} from 'ppx';

class Test extends React.Component {
  constructor(props) {
    super(props);
  }

  handleAdd(e) {
    const {dispatch} = this.props;
    dispatch({type: 'app/add'});
  }
  handleDel(e) {
    const {dispatch} = this.props;
    dispatch({type: 'app/minus'});
  }

  render() {
    const {page} = this.props;
    const {a} = page;
    return (
      <div>
        <p>a: {a}</p>
        <a onClick={this.handleAdd.bind(this)}>增加</a>
        <a onClick={this.handleDel.bind(this)}>减少</a>
      </div>
    );
  }
}

export default connect(['App'])(Test);
```
## todo:
* 当一个view绑定多个model时 是否需要默认model
* reduce中是存在多种返回时：比如请求当成功时给成功提示，失败给失败提示，但是有使用失败给成功结果，失败提示， 目前初步定为用中间件去解决这类问题
* subscribe 性能调优


## 感谢：
* 感谢 [darrenscerri](https://gist.github.com/darrenscerri/5c3b3dcbe4d370435cfa) 提供的异步中间件思路
* 本库的flux思路类似于[dva](https://github.com/dvajs/dva), 只是有别与dva的redux与redux-saga的思路 ppx使用更加简单
* 感谢离职同事的贡献，所以本库任性的按照他的绰号取名

---
_Source: https://npm.io/package/ppx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
