Skip to content

Commit bba4e12

Browse files
authored
Release/1.4.1 (#116)
* docs: language link for migration * docs: add link for upgrade guidelines * fix: immer error (#117) * feat: set error & loading as blacklist for immer pulgin * chore: lint * chore: notice
1 parent 4fafc3e commit bba4e12

6 files changed

+40
-28
lines changed

docs/migration.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: migration
33
title: Migration
44
---
55

6+
English | [简体中文](./migration.zh-CN.md)
7+
68
## Migrating From Redux
79

810
We provide a gradual solution to allow your project to be partially migrated from Redux to icestore.

docs/migration.zh-CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: migration
33
title: Migration
44
---
55

6+
[English](./migration.md) | 简体中文
7+
68
## 从 Redux 迁移
79

810
我们提供了渐进式的方案使得您的项目可以局部从 Redux 迁移到 icestore。

docs/upgrade-guidelines.zh-CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Upgrade Guidelines
77

88
## 从 1.2.0 升级到 1.3.0
99

10-
1.3.0 是完全向下兼容的,但是我们推荐您在新增代码中使用最新的 API。
10+
1.3.0 是完全向下兼容的,但是我们推荐您在新增代码中使用最新的 API。1.2.x 有一些已知的[功能不完备](https://github.com/alibaba/ice/issues/3037),您必须知晓。
1111

1212
我们会在未来的版本中删除标记为「已过期」的 API。
1313

@@ -128,7 +128,7 @@ export default withModelDispatchers('todos')(TodoList);
128128

129129
## 从 1.0.0 升级到 1.3.0
130130

131-
1.3.0 是完全向下兼容的,但是我们推荐您在新增代码中使用最新的 API。
131+
1.3.0 是完全向下兼容的,但是我们推荐您在新增代码中使用最新的 API。1.0.x 有一些已知的[功能不完备](https://github.com/alibaba/ice/issues/3037),您必须知晓。
132132

133133
我们会在未来的版本中删除标记为「已过期」的 API。
134134

@@ -246,7 +246,7 @@ export default withModelEffectsState('todos')(TodoList);
246246

247247
从 0.x.x 到 1.x.x 是不兼容的。您可以选择性地进行升级。
248248

249-
但 0.x.x 有一些已知的缺陷,您必须知晓:https://github.com/alibaba/ice/issues/3037
249+
但 0.x.x 有一些已知的[缺陷](https://github.com/alibaba/ice/issues/3037),您必须知晓。
250250

251251
### Define Model
252252

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ice/store",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Simple and friendly state for React",
55
"main": "lib/index.js",
66
"files": [

src/index.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,19 @@ export const createStore = <M extends T.Models, C extends T.CreateStoreConfig<M>
5555
plugins.push(createReduxHooksPlugin({context}));
5656
plugins.push(createModelApisPlugin());
5757

58-
const loading = createLoadingPlugin();
59-
const error = createErrorPlugin();
60-
const immer = createImmerPlugin();
61-
if (!disableImmer) {
62-
plugins.push(immer);
63-
}
58+
// https://github.com/ice-lab/icestore/issues/94
59+
// TODO: fix error & loading plugin immer problem
60+
const immerBlacklist = [];
6461
if (!disableLoading) {
65-
plugins.push(loading);
62+
plugins.push(createLoadingPlugin());
63+
immerBlacklist.push('loading');
6664
}
6765
if (!disableError) {
68-
plugins.push(error);
66+
plugins.push(createErrorPlugin());
67+
immerBlacklist.push('error');
68+
}
69+
if (!disableImmer) {
70+
plugins.push(createImmerPlugin({ blacklist: immerBlacklist }));
6971
}
7072

7173
// compatibility handling

src/plugins/immer.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,35 @@ import produce from 'immer';
22
import { combineReducers, ReducersMapObject } from 'redux';
33
import * as T from '../types';
44

5-
function combineReducersWithImmer(reducers: ReducersMapObject) {
6-
const reducersWithImmer: ReducersMapObject<any, T.Action<any>> = {};
7-
// reducer must return value because literal don't support immer
5+
export interface ImmerConfig {
6+
blacklist?: string[];
7+
}
8+
9+
function createCombineReducersWithImmer(blacklist: string[] = []) {
10+
return function(reducers: ReducersMapObject) {
11+
const reducersWithImmer: ReducersMapObject<any, T.Action<any>> = {};
12+
// reducer must return value because literal don't support immer
813

9-
Object.keys(reducers).forEach((key) => {
10-
const reducerFn = reducers[key];
11-
reducersWithImmer[key] = (state, payload) =>
12-
typeof state === 'object'
13-
? produce(state, (draft: T.Models) => {
14-
const next = reducerFn(draft, payload);
15-
if (typeof next === 'object') return next;
16-
})
17-
: reducerFn(state, payload);
18-
});
14+
Object.keys(reducers).forEach((key) => {
15+
const reducerFn = reducers[key];
16+
reducersWithImmer[key] = (state, payload) =>
17+
typeof state === 'object' && !blacklist.includes(key)
18+
? produce(state, (draft: T.Models) => {
19+
const next = reducerFn(draft, payload);
20+
if (typeof next === 'object') return next;
21+
})
22+
: reducerFn(state, payload);
23+
});
1924

20-
return combineReducers(reducersWithImmer);
25+
return combineReducers(reducersWithImmer);
26+
};
2127
}
2228

2329
// icestore plugin
24-
const immerPlugin = (): T.Plugin => ({
30+
const immerPlugin = (config: ImmerConfig = {}): T.Plugin => ({
2531
config: {
2632
redux: {
27-
combineReducers: combineReducersWithImmer,
33+
combineReducers: createCombineReducersWithImmer(config.blacklist),
2834
},
2935
},
3036
});

0 commit comments

Comments
 (0)