Skip to content

v3.0.0

Compare
Choose a tag to compare
@geekact geekact released this 08 Oct 13:27
· 34 commits to master since this release

破坏性更新

  • 删除hooks函数 useDefined
  • 删除模型内onDestroy事件钩子
  • 删除持久化maxAge配置
store.init({
  persist: [
    {
      key: 'key',
-     maxAge: 3600,
      engines: engines.localStorage,
      models: [],
    }
  ]
})
  • 非hooks状态下计算属性使用执行函数的方式获取
const model = defineModel('model', {
  initialState: { firstName: '', lastName: '' },
  methods: {
    myMethod() {
-     return this.fullName.value;
+     return this.fullName();
    }
  },
  computed: {
   fullName() {
     return this.state.firstName + this.state.lastName;
   },
  }
});

新特性

  • 开启持久化的模型会立即存储initialState
  • 计算属性支持传递参数
const model = defineModel('model', {
  initialState: { firstName: '', lastName: '' },
  methods: {
    myMethod() {
+     const profile = this.profile(30, 'addr', false);
    }
  },
  computed: {
   fullName() {
     return this.state.firstName + this.state.lastName;
   },
+  profile(age: number, address: string, coding: boolean = true) {
+    return this.fullName() + '-' + age + address + coding;
+  },
  }
});

const App: FC = () => {
  const fullName = useComputed(model.fullName);
+ const profile = useComputed(model.profile, 20, 'my-address');
}
  • 持久化增加 dumpload 两个系列化函数
const model = defineModel('model', {
  initialState: { firstName: 'tick', lastName: 'tock' },
  persist: {
+   dump(state) {
+     return state.firstName;
+   },
+   load(dumpData) {
+     return { ...this.initialState, firstName: dumpData };
+   },
  }
});
  • 持久化新增合并模式 replace, merge(默认), deep-merge
store.init({
  persist: [
    {
      key: 'item1',
      version: '1.0',
+     merge: 'replace',
      engine: engines.localStorage,
      models: [],
    },
  ]
})

其它

  • npm包转译为ES5语法以兼容更早的浏览器 (#41)
  • immer版本降级:10.0.2 -> 9.0.21
  • react-redux版本升级:8.1.2 -> 8.1.3

v2.0.1...v3.0.0