hydrogen-store-immer-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.4.5 • Public • Published

hydrogen-store-immer-plugin

使用 immerPlugin,可以使用 immer 的语法简化编写 reducer // TODO 暂时不能与 hydrogen-store-redux-plugin 同时使用,将在下个版本支持

用法

// 使用前
const reducers = {
  testAction: (state, payload) => ({
    ...state,
    data: {
      ...state.data,
      a: {
        ...state.data.a,
        b: 2,
      },
    },
  }),
}

// 使用后
const reducers = {
  testAction: (state, payload) => {
    state.data.a.b = 2
  },
}
import { createStore } from 'hydrogen-store'
import immerPlugin from 'hydrogen-store-immer-plugin'

const testModel = {
  state: { data: { a: { b: 1 } } },
  reducers: {
    testAction: (state, payload) => {
      state.data.a.b = 2
    },
  },
  effects: {},
}

export const singleStore = createStore({
  modules: {
    test: testModel,
  },
  plugins: [effectPlugin, immerPlugin],
})

Readme

Keywords

none

Package Sidebar

Install

npm i hydrogen-store-immer-plugin

Weekly Downloads

0

Version

0.4.5

License

ISC

Unpacked Size

10.2 kB

Total Files

6

Last publish

Collaborators

  • mingrenjbdt