Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (30 sloc) 925 Bytes
description
Immer提供了开发人员友好的方式来使用Rematch创建不可变reducer。

Immer

请参见下面的一个例子:

import produce from 'immer';

export default {

  // state is the array of cell IDs for this page
  state: [ '1' ],

  reducers: {

    reorder: produce((state, { fromIndex, toIndex }) => {
      const [ id ] = state.splice(fromIndex, 1);
      if (id) {
        state.splice(toIndex, 0, id);
      }
    }),

    'cells/create': produce((state, { id, atIndex }) => {
      if (atIndex > state.length) {
        throw new Error('Cell index too high');
      }

      state.splice(atIndex, 0, id);
    }),

    'cells/delete': produce((state, { atIndex }) => {
      state.splice(atIndex, 1);
    }),

  },

};

如果你想用Immer produce包装所有reducer,请检查Rematch Immer插件

You can’t perform that action at this time.