Redux Model 9.0 发布,诸多改进

栏目: 软件资讯 · 发布时间: 5年前

内容简介:本次更新内容 Breaking 重构 自动引入了 redux 和 react-redux,请将项目中相关的库删除 yarn remove redux react-redux @types/react-redux - import { Middleware } from 'redux' + import { Middleware }...

本次更新内容

Breaking

  • 重构 自动引入了 redux 和 react-redux,请将项目中相关的库删除
yarn remove redux react-redux @types/react-redux
- import { Middleware } from 'redux'
+ import { Middleware } from '@redux-model/react'

- import { Provide } from 'react-redux'
+ import { Provide } from '@redux-model/react'

- import { connect } from 'react-redux'
+ import { connect } from '@redux-model/react'
  • 重构 模型实例方法 effects() 重命名为 subscriptions(),更具表达力
class TestModel extends Model {
- protected effects(): Effects<Data> {
+ protected subscriptions(): Subscriptions<Data> {
    return [
      ...,
      ...,
    ];
  }
}
  • 重构 模型实例方法 useData 总是采用浅对比的方式获取数据,以降低组件重渲染的概率
  • 重构 请求服务属性 requestConfig 重命名为 requestOptions,统一名称
  • 删除 模型实例方法 autoRegister(),模型一定是自动注册的
  • 删除 模型实例方法 register(),您无需手动注册。在代码分离时,如果您想提前注册,直接在入口import 'xyzModel'即可
  • 删除 模型构造函数中的 alias 参数,即使出现同名类,重写方法 getReducerName() 即可
  • 删除 HttpService.transformSuccessData,并引入 HttpService.onRespondSuccess 做为代替属性
  • 删除 createReduxStore.onCombineReducers 属性,缺少使用场景

Features

  • 新增 全局方法 resetStore(),用于重置所有模型数据,并支持部分模型保留数据
import { resetStore } from '@redux-model/react';

logout().then(() => {
+ resetStore();
});
  • 新增 模型实例方法 keepOnResetStore(),用于重置数据时保护当前模型不被影响
class TestModel extends Model<Data> {
  protected initialState(): Data {
    return {};
  }

+ protected keepOnResetStore() {
+   return true;
+ }
}
  • 新增 模型静态方法 init(),用于延迟自动注册以满足定制初始化数据的需求
interface Data {
  counter: number;
}

class TestModel extends Model<Data> {
+ protected readonly initCounter: number;

  constructor(p1: number) {
    super();
+   this.initCounter = p1;
  }

  protected initialState(): Data {
    return {
+     counter: this.initCounter,
    };
  }
}

- const testModel = new TestModel(10);  // testModel.data.counter === undefined
+ const testModel = TestModel.init(10); // testModel.data.counter === 10

Fixes

  • 修复 Taro-h5请求异常时未解析data
  • 修复 Taro-h5请求不支持abort操作

 

---------------------------------------------

Redux Model

Redux-Model是为了弥补原生Redux繁琐的开发流程,开发者重复劳动效率低下,模板文件导致代码量臃肿,以及因action和reducer文件分散造成代码追踪困难的问题而设计的。

 

特性

  • 深度封装,模块化开发
  • 使用mvvm快速处理reducer
  • ????真正意义上的Typescript框架,写起来比JS更流畅
  • 内置http服务,请求action自带loading追踪、数据节流
  • 支持React/Vue Hooks
  • 支持数据持久化
  • 支持Graphql请求
  • 支持代码分离

 


以上所述就是小编给大家介绍的《Redux Model 9.0 发布,诸多改进》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Agile Web Development with Rails, Third Edition

Agile Web Development with Rails, Third Edition

Sam Ruby、Dave Thomas、David Heinemeier Hansson / Pragmatic Bookshelf / 2009-03-17 / USD 43.95

Rails just keeps on changing. Rails 2, released in 2008, brings hundreds of improvements, including new support for RESTful applications, new generator options, and so on. And, as importantly, we’ve a......一起来看看 《Agile Web Development with Rails, Third Edition》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具