跳到主要内容

更新记录

3.0.1 (2023-08-02)

Bug 修复

  • 解决Natur在SSR场景的报错Error: Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering.

改进

  • 新增 NaturBaseFactory 工具类,用于提高用户开发体验

3.0.0 (2023-03-04)

  • natur-service的功能移植到natur本身,变为新的 watch 属性,为了模块通讯以及更好的掌握业务
    import { ModuleEvent, AllModuleEvent, WatchAPI } from 'natur';
    export const moduleA = {
    state: {},
    actions: {/* ... */},
    watch: {
    moduleB(event: ModuleEvent, api: WatchAPI) {
    // 任何 moduleB 的变动都会触发这个函数,具体的变动信息在event参数获取
    // api参数包含本模块的, getState, getMaps, localDispatch等API, 以及获取全局store的getStoreAPI.
    // localDispatch是只能调用本模块的action,例如:localDispatch('actionNameA', ...actionAArgs);
    }
    }
    }
    export const moduleB = {
    state: {},
    actions: {/* ... */},
    // watch也可以是一个函数用来监听所有模块的变动
    watch: (event: AllModuleEvent, api: WatchAPI) => {
    // 任何模块的变动都会触发这个函数,具体的变动信息在event参数获取
    // api参数包含本模块的, getState, getMaps, localDispatch等API, 以及获取全局store的getStoreAPI.
    // localDispatch是只能调用本模块的action,例如:localDispatch('actionNameA', ...actionAArgs);
    }
    }
  • 即将废弃thunkMiddleware中的dispatch API, 由新的localDispatchAPI替代,localDispatch只能调用本模块的action
  • subscribe and subscribeAll API增强,提供更全面的事件信息,以及API入参来掌控业务

3.0.0-beta1 (2023-02-25)

重大变更

  • 完成 TypeScript 部分的重构

2.2.0 (2023-02-25)

重大更新

  • 重构inject HOC,从类组件改为函数式组件
  • 新增 CreateUseInject API. 现在更加推荐使用useInject的hook方式
  • 新增 store.subscribeAll API, 监听所有模块变动,无需指定模块监听
  • 新的 Provider API, 更好的支持SSR和多个store场景.
  • 新的 CreateUseStore API.
  • Middleware/Interceptor参数新增 getStore API,用来在Middleware/Interceptor中获取当前store的实例
  • Middleware/Interceptor范型调整,改为需要两个参数(Modules和Lazy Modules,就像Store一样), 并且有默认参数

不兼容更新

  • 删除 watch API
  • 升级到React 18版本, 不再兼容React17以下版本
    • 如果你想要在18版本以下升级natur, 你可以尝试使用 use-sync-external-store, 并在调用createInject/createUseInject之前将其放入React object中
    import {useSyncExternalStore} from 'use-sync-external-store/shim';
    import React from 'react';

    React.useSyncExternalStore = useSyncExternalStore;

2.2.0-beta7 (2023-02-10)

重大更新

  • useInjectAPI新增flat选项

bug fix

  • createStore类型bug fix

3.0.0-alpha2 (2023-02-06)

重大更新

  • natur-service的功能移植到natur本身,变为新的 watch API,为了模块通讯以及更好的掌握业务
    import { ModuleEvent, AllModuleEvent, WatchAPI } from 'natur';
    export const moduleA = {
    state: {},
    actions: {/* ... */},
    watch: {
    moduleB(event: ModuleEvent, api: WatchAPI) {
    // any update of moduleB will trigger this function
    // event have any data of this change
    // api contain, getState, getMaps, localDispatch, getStore API etc.
    }
    }
    }
    export const moduleB = {
    state: {},
    actions: {/* ... */},
    // watch also can be a function to watch all module of store
    watch: (event: AllModuleEvent, api: WatchAPI) => {
    // any update of any module will trigger this function
    // event have any data of this change
    // api contain, getState, getMaps, localDispatch, getStore API etc.
    }
    }
  • 即将废弃thunkMiddleware中的dispatch API, 由新的localDispatchAPI替代,localDispatch只能调用本模块的action
  • subscribe and subscribeAll API增强,提供更全面的事件信息,以及API入参来掌控业务

2.2.0-beta5 (2023-02-04)

重大更新

  • 新的 Provider API, 更好的支持SSR和多个store场景.
  • 新的 CreateUseStore API.
  • Middleware/Interceptor参数新增 getStore API,用来在Middleware/Interceptor中获取当前store的实例
  • Middleware/Interceptor范型调整,改为需要两个参数(Modules和Lazy Modules,就像Store一样), 并且有默认参数

2.2.0-beta2 (2022-12-18)

重大更新

  • 重构inject HOC,从类组件改为函数式组件
  • 新增 CreateUseInject API. 现在更加推荐使用useInject的hook方式
  • 新增 store.subscribeAll API, 监听所有模块变动,无需指定模块监听

不兼容更新

  • 删除 watch API
  • 升级到React 18版本, 不再兼容React17以下版本

优化

  • 缓存优化