# if-vuex

> userful functions for vuex

Latest version **1.0.9** (published 2024-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install if-vuex
pnpm add if-vuex
yarn add if-vuex
bun add if-vuex
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2024-06-29 |
| First published | 2023-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 43.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alibob |
| Keywords | vuex, vue3, store, persistedstate |

## Links

- npm: https://www.npmjs.com/package/if-vuex
- npm.io page: https://npm.io/package/if-vuex

## Dependencies (2)

- [vuex](https://npm.io/package/vuex.md) ^4.1.0
- [vuex-persistedstate](https://npm.io/package/vuex-persistedstate.md) ^4.1.0

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.9 (latest) — 2024-06-29
- 1.0.8 — 2024-02-04
- 1.0.7 — 2024-01-29
- 1.0.6 — 2023-11-24
- 1.0.5 — 2023-11-24
- 1.0.4 — 2023-09-04
- 1.0.2 — 2023-09-02
- 1.0.0 — 2023-09-02

## README

# if-vuex
provide some useful functions to imporve the development experience



# Functions

## extendStore(store, name, module, persistedstates)
Extends Store instance (Vuex)

```
const name = 'example'
const module = {
  namespaced: true,
  state: {
    name: 'Example Store',
    version: 'beta',
    counter: {
      num: 0
    }
  },
  getters: {
    count: state => state.counter.num
  },
  mutations: {
    increment(state, offset) {
      state.counter.num += offset
    }
  },
  actions: {
    plus({commit}, offset) {
      commit('increment', offset)
    }
  }
  
}
// Default
extendStore(store, 'example', module)

// vuex-persistedstate
extendStore(store, 'example', module, ['name'])
```

## useStoreByModule(name, defaultStore?)

```
const {useRef, useRefs, commit, dispatch, getter, mapGetter} = useStoreByModule('example')

useRef('counter.num')  // 0
userRefs(['counter.num', 'name', 'version']) // [0, 'Example Store', 'beta']
commit('increment', 2)  // 2
dispatch('plus', 3)  // 5
getter('count')  // 5
mapGetter({'count': 'countNew'}) // {countNew: 5}
```

## setStoreEnv (实验性质)
1.0.7起新增环境隔离，默认不开启。


新增环境设置, 当启用环境隔离的时候，将会根据预设的环境 生成多环境store， 也可以为多个应用进行分别存储



```
// Init
setStoreEnv({
  preset: ["local", "development", "testing", "uat", "production"],
  enable: true,
  env: 'local'
})

// update Env
setStoreEnv({ env: 'development'})
```

## getStoreEnv
1.0.7起新增环境隔离

···
const env = getStoreEnv('env')  // computed 获取当前环境
const envEnable = getStoreEnv('enable') // computed 获取是否开启了环境隔离
···

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