# mayako-wex

> 新建一个文件为store.js 内容为 ``` javascript /** * no use strict */ wx.wex = new Wex().init({ state: { obj: '咩咩咩咩', TS: 2, peopleNum: 0, dishesTypeId: 1, dishesTypeName: '', test:{ a:1, b:{a:2} } },

Latest version **0.3.5** (published 2020-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install mayako-wex
pnpm add mayako-wex
yarn add mayako-wex
bun add mayako-wex
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2020-05-27 |
| First published | 2018-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 72.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | mayako |
| Maintainers | maya21126 |

## Links

- npm: https://www.npmjs.com/package/mayako-wex
- Repository: https://github.com/mayako21126/wex
- Homepage: https://github.com/mayako21126/wex#readme
- Issues: https://github.com/mayako21126/wex/issues
- npm.io page: https://npm.io/package/mayako-wex

## Recent versions

- 0.3.5 (latest) — 2020-05-27
- 0.3.4 — 2020-03-09
- 0.3.3 — 2019-12-23
- 0.3.2 — 2019-12-20
- 0.3.1 — 2018-02-02
- 0.3.0 — 2018-02-02
- 0.2.0 — 2018-02-01
- 0.1.9-beta — 2018-02-01
- 0.1.9 — 2018-02-01
- 0.1.8 — 2018-01-22
- 0.1.7 — 2018-01-20
- 0.1.6 — 2018-01-18
- 0.1.5 — 2018-01-18
- 0.1.4 — 2018-01-18
- 0.1.3 — 2018-01-18
- … 2 more at https://npm.io/package/mayako-wex/versions

## README

## 使用方法

# 初始化&引入

新建一个文件为store.js 
内容为
``` javascript
/**
 * no use strict 
 */
wx.wex = new Wex().init({
  state: {
    obj: '咩咩咩咩',
    TS: 2,
    peopleNum: 0,
    dishesTypeId: 1,
    dishesTypeName: '',
    test:{
      a:1,
      b:{a:2}
    }
  },
  Mutation: {
    getFoodInfo: () => {

    },
    setTest:({setState,args})=>{
      setState('test',args[0])
    },
    getTest:({state})=>{
      return state.test;
    },
    getdishesTypeId: ({state}) => {
      return state.dishesTypeId
    },
    setdishesTypeId: ({setState,args}) => {
      setState('dishesTypeId', args[0] );
    },
    setdishesTypeName: ({setState,args}) => {
      setState('dishesTypeName', args[0] );
    },
    getdishesTypeName: ({state}) => {
      return state.dishesTypeName;
    },
    getObj: ({state}) => {
      return state.obj
    },
    tt: ({state}) => {
      return state.TS
    },
    setTs: ({setState,args}) => {
      setState('TS', args[0])
      
    },
    setObj: ({setState,commit,args}) => {
      setState('obj', args[0])
      commit('setTs',args[0])
    },
    setPeopleNum: ({setState,args,state}) => {
      state.peopleNum = args[0]
      // setState('peopleNum', args[0] )
    },
    getPeopleNum: ({state}) => {
      return state.peopleNum
    }

  }
});

```
在入口文件中引入  
``` javascript
import './store'
```
在需要使用的地方
``` javascript
// 如果只是需要使用获取值，设置值
    var {
        setPeopleNum,
        getTest,
        setTest
    } = wx.wex.mapMutations;
setPeopleNum(10)
    var {
        peopleNum
    } = wx.wex.state
// 如果需要是值具有响应功能
wx.wex.on('dishesTypeId', (oj) => {
     this.dishesTypeId = oj;
}, this)
// 使用箭头函数保证作用域指向，在回调填写响应后的变化
// 同一页面内多次订阅同一状态会只记录最后一次订阅，防止多次无意义订阅造成内存泄漏
// 无法直接更改state和mutation，使用wx.wex.history可以查询到全部的变更记录
// 新增部分数组变异方法，在Mutation里直接操作state也可以观测到变化，不过setState在某些情况下性能更好一些。
```
## wex对象提供state(取值),commit(提交方法),on(订阅),emit(触发),off(删除),mapMutations(映射mutations方法),history(变更记录)几个方法

## 在mutaions里参数包含state,setState,commit,args4个参数。

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