# moox

> moox 是基于 redux 开发的高性能状态管理机。

Latest version **2.0.0** (published 2022-01-06) · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-01-06 |
| First published | 2018-02-01 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.17.6 |
| Dependencies | 1 |
| Unpacked size | 78.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Maintainers | suxiaoxin |

## Links

- npm: https://www.npmjs.com/package/moox
- Repository: https://github.com/Open-Federation/moox
- Homepage: https://github.com/Open-Federation/moox#readme
- Issues: https://github.com/Open-Federation/moox/issues
- npm.io page: https://npm.io/package/moox

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7

## Recent versions

- 2.0.0 (latest) — 2022-01-06
- 1.1.0 — 2021-07-21
- 1.0.8 — 2018-11-19
- 1.0.7 — 2018-11-19
- 1.0.6 — 2018-07-14
- 1.0.5 — 2018-04-13
- 1.0.4 — 2018-04-13
- 1.0.2 — 2018-03-20
- 1.0.1 — 2018-03-20
- 1.0.0-beta6 — 2018-03-14
- 1.0.0-beta5 — 2018-03-14
- 1.0.0-beta3 — 2018-03-14
- 1.0.0-beta2 — 2018-02-07
- 1.0.0-beta1 — 2018-02-01
- 1.0.0 — 2018-02-01

## README

# moox
moox is a high-performance state management tool of based on redux.

[中文文档](README_CN.md)

> version 2.0 is refactoring by ts.

## Install
```bash
npm install moox
```

## Getting Started

### 1.create Model
The structure of the model is as the following sample code，state is initialState of model, action is used of calculating state。

```js
import {createModel} from 'moox'

type StateType = {
  list: string[],
  status: number,
  filterText: string,
  currentEditIndex: number
}

const state : StateType = {
  list: ['tom', 'xiaoming'],
  status: 0,
  filterText: '',
  currentEditIndex: 0
}

const actions = {
  changeCurrentEditUser: function (state: StateType, params: {
    name: string,
    index: number, //index of todo list 
  }) {
    state.list[params.index] = params.name;
  },
  changeFilterValue: function (state: StateType, params: {
    text?: string
  }) {
    state.filterText = params.text;
  },
  changeEditIndex: function (state: StateType, params) {
    state.currentEditIndex = params.index;
  },
  addUser: function (state: StateType, params) {
    state.list.push(getRandomName());
    state.status = 0;
  },
  requestStatus: function (state: StateType, params) {
    state.status = 1;
  },
  delUser: function (state: StateType, params) {
    state.list.splice(params.index, 1);
  }
}

export default createModel({
  state, 
  actions
});

function getRandomName(len = 4) {
  let str = '';
  while (len--) str += String.fromCharCode(97 + Math.ceil(Math.random() * 25));
  return str;
}


```

### 2.Bind the component to the Provider

```js
export default Models.getProvider(App)
```

### 3.Get store data from hook

```js
import React from 'react'
import Model from './model'

const App = (props)=>{
  const store = useModel((state) => ({
    user: state.user
  }))
  const {user} = store;
  const handleClick = () =>{
    if(user.status === 1) return;
    Model.user.requestStatusAction()
    Model.user.addUserAction()
  }

  return <div>
    <div><button  onClick={handleClick}>Add Random Number</button>
      {user.status === 1? 'loading...' : ''}
    </div>

    {user.list.map((item, index)=>{
      return <div key={index}>{item}</div>
    })}
  </div>
}
export default App;

```
>Note: class components example:

```js
import {connect} from 'react-redux';

const changeState = ()=>{
   Models.user.changeStateAction({
      x: Math.random()
   })
}

@connect(state=>({
	store: state.user
}))
const Home = class extends React.PureComponent{
   render(){
    const {store} = this.props;
    return <span onClick={changeState}   >{JSON.stringify(store)}</span>
  }
}

```

For more detailed usage, please refer to [demo](https://github.com/Open-Federation/moox/tree/master/demo)

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