Skip to content

MingNeo/hydrogen-store-immer-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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],
})

About

让hydrogen-store可以使用immer语法的plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published