# applets-dva

> ## 目的

Latest version **1.1.1** (published 2025-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install applets-dva
pnpm add applets-dva
yarn add applets-dva
bun add applets-dva
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2025-04-16 |
| First published | 2021-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | xxx |
| Maintainers | ricardom |

## Links

- npm: https://www.npmjs.com/package/applets-dva
- Repository: xxx
- npm.io page: https://npm.io/package/applets-dva

## Recent versions

- 1.1.1 (latest) — 2025-04-16
- 1.1.0 — 2025-04-16
- 1.0.9 — 2022-07-26
- 1.0.8 — 2022-07-26
- 1.0.7-alpha.1 — 2022-07-26
- 1.0.7 — 2022-06-28
- 1.0.6 — 2021-12-15
- 1.0.5 — 2021-12-15
- 1.0.4 — 2021-12-15
- 1.0.3 — 2021-12-15
- 1.0.2 — 2021-12-15
- 1.0.1 — 2021-12-15
- 1.0.0 — 2021-12-15

## README

# 应用于小程序中的dva 全局状态存储插件

## 目的

为了解决

- 父组件<->子组件<->孙组件
- 兄弟组件
- 页面与页面
  多重套娃的数据处理

## 使用

1. 在app.js 中引用

```
import dva from 'applets-dva'

const app = new dva()
app.start()

App({
  ...
})
```

2. 导入modal

```
import dva from 'applets-dva'
import xxx from 'xxx'

const app = new dva()

app.model(xxx)
app.start()

App({
  ...
})
```

3. 在page或者component中连接仓库
   在生命周期函数中

```
import { connect } 'applets-dva'

onReady() {
  connect('仓库model的namespace', this)
}

attached() {
  connect('仓库model的namespace', this)
}
```

4. 目前抛出的有dispatch和connect的方法；注意reducer和dva不太一样，不能用generator函数

5. Demo

```
const testModal = {
  namespace: 'test',
  state: {
    num: 0,
  },
  effects: {
    asyncAdd({ payload }, { select, put }) {
      put({
        type: 'test/add',
      })

      put({
        type: 'test/asyncReduce',
        payload: {
          test: 1
        }
      })
    },
    asyncReduce(_, { select, put }) {
      const num = select(state => state.test.num)
      put({
        type: 'test/reduce1',
      })

    }
  },
  reducers: {
    add(state, action) {
      return {
        ...state,
        num: state.num + 1
      }
    },
    saveNum(state, action) {
      return {
        ...state,
        num: action.payload
      }
    },
    reduce(state, action) {
      return {
        ...state,
        num: state.num - 1
      }
    },
    reduce1(state, action) {
      return {
        ...state,
        num: state.num - 2
      }
    },
    mulit(state) {
      return {
        ...state,
        num: state.num * state.num
      }
    }
  }
}

export default testModal
```

6. Git地址：https://github.com/Ricardom520/applet-dva

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