-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [bug] 修复 api useMiddleWare 复用了 api createAgentReducer 的 MiddleWare 的问题。 * [design] 在过去, applyMiddleWares 使用的是方法级统一的缓存 cache , 这使得 MiddleWare 的缓存之间可能存在缓存数据共享问题,自当前版本开始 applyMiddleWares 会为每个 MiddleWare 开辟了独立的缓存空间 cache , 各个 MiddleWare 之间将不再有缓存共享问题。 * [design] `MiddleWares.takeNone()`作为当前版本新加入的 MiddleWare 可以阻止任何 state 改变。 * [feature] `MiddleWare`的覆盖优先级已经变更为: `useMiddleWare` -> `middleWare` -> `createAgentReducer`。 * [feature] 使用相同实例模型的`Agent`代理对象之间数据更新同步。
- Loading branch information
wangyi
committed
Mar 11, 2021
1 parent
01a5cd7
commit 7b61ec7
Showing
54 changed files
with
1,316 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.eslintrc.js | ||
test/ | ||
jest.config.js | ||
babel.config.js | ||
index.js | ||
webpack.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module.exports = { | ||
env: { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
extends: [ | ||
'airbnb-base', | ||
'plugin:@typescript-eslint/recommended', | ||
// 'plugin:@typescript-eslint/recommended-requiring-type-checking' | ||
], | ||
globals: { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly", | ||
"self": "readonly" | ||
}, | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
"ecmaVersion": 2019, | ||
"sourceType": 'module', | ||
tsconfigRootDir: '.', | ||
project: ['./tsconfig.json'], | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
|
||
settings: { | ||
'import/parsers': { | ||
'@typescript-eslint/parser': ['.ts'] | ||
}, | ||
'import/resolver': { | ||
'node': { | ||
"extensions": [".js", ".jsx", ".ts", ".tsx"] | ||
} | ||
|
||
} | ||
}, | ||
rules: { | ||
"import/extensions": "off", | ||
"no-param-reassign": "off", | ||
"no-use-before-define": ["error", { "functions": false, "classes": true }], | ||
"@typescript-eslint/no-explicit-any":"off", | ||
"@typescript-eslint/no-unused-vars": ["off"] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules/ | ||
/dist | ||
/libs | ||
/package-lock.json | ||
/index.d.ts | ||
/.idea/ | ||
/coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
## v3.1.1 2020-12-17 | ||
## v3.1.2 2021-02-28 | ||
|
||
* [bug] 已修复 reducer.update 方法中当 state 为 undefined 时, | ||
外部 store state 与 agent state 不同步的问题。 | ||
* [bug] fix `MiddleWares.takeDebounce` problem. | ||
* [bug] fix `globalConfig` problem. If a global object can not be found, `globalConfig` should not work. | ||
* [feature] add `nextExperience` in `env` config for experience next version features. | ||
`MiddleWare` override order in next version: `useMiddleWare` -> `middleWare` -> `createAgentReducer`. | ||
* [document] update document structure. | ||
* [document] increase english language support. | ||
* [unit test] update unit test structure. | ||
|
||
## v3.1.2 2021-02-28 | ||
## v3.2.0 2021-03-11 | ||
|
||
* [bug] 使用常规 debounce 代码修复原`MiddleWares.takeDebounce`因事件堆积导致的不稳定问题。 | ||
* [bug] 修复了`globalConfig`在无法获取到`window,global,self`情况下报错的问题。 | ||
* [feature] 新增`nextExperience`下一版本体验特性,并在`env`中增加了相应开启配置项。 | ||
`MiddleWare`的覆盖优先级将在`nextExperience`环境中变更为:`useMiddleWare` -> `middleWare` -> `createAgentReducer`。 | ||
* [document] 更改了文档结构以方便分步阅读。 | ||
* [document] 新增了英文文档。 | ||
* [unit test] 根据文档变更,新增了中英文分离的单元测试案例。 | ||
* [bug] fix `useMiddleWare` reuse the MiddleWare from `createAgentReducer` problem. | ||
* [design] `applyMiddleWares` reassign `runtime.cache` for each `MiddleWare`, | ||
in this version, `runtime.cache` used in MiddleWare is independent. | ||
* [design] `MiddleWares.takeNone()` is a new MiddleWare, this MiddleWare can stop any state change. | ||
* [feature] `MiddleWare` override order in current version: `useMiddleWare` -> `middleWare` -> `createAgentReducer`. | ||
* [feature] `Agent` objects based on the same object mode model updates state synchronously. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## v3.1.1 2020-12-17 | ||
|
||
* [bug] 已修复 reducer.update 方法中当 state 为 undefined 时, | ||
外部 store state 与 agent state 不同步的问题。 | ||
|
||
## v3.1.2 2021-02-28 | ||
|
||
* [bug] 使用常规 debounce 代码修复原`MiddleWares.takeDebounce`因事件堆积导致的不稳定问题。 | ||
* [bug] 修复了`globalConfig`在无法获取到`window,global,self`情况下报错的问题。 | ||
* [feature] 新增`nextExperience`下一版本体验特性,并在`env`中增加了相应开启配置项。 | ||
`MiddleWare`的覆盖优先级将在`nextExperience`环境中变更为:`useMiddleWare` -> `middleWare` -> `createAgentReducer`。 | ||
* [document] 更改了文档结构以方便分步阅读。 | ||
* [document] 新增了英文文档。 | ||
* [unit test] 根据文档变更,新增了中英文分离的单元测试案例。 | ||
|
||
## v3.2.0 2021-03-11 | ||
|
||
* [bug] 修复 api useMiddleWare 复用了 api createAgentReducer 的 MiddleWare 的问题。 | ||
* [design] 在过去, applyMiddleWares 使用的是方法级统一的缓存 cache , | ||
这使得 MiddleWare 的缓存之间可能存在缓存数据共享问题,自当前版本开始 | ||
applyMiddleWares 会为每个 MiddleWare 开辟了独立的缓存空间 cache , | ||
各个 MiddleWare 之间将不再有缓存共享问题。 | ||
* [design] `MiddleWares.takeNone()`作为当前版本新加入的 MiddleWare 可以阻止任何 state 改变。 | ||
* [feature] `MiddleWare`的覆盖优先级已经变更为: | ||
`useMiddleWare` -> `middleWare` -> `createAgentReducer`。 | ||
* [feature] 使用相同实例模型的`Agent`代理对象之间数据更新同步。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Relationship of Agent and OriginAgent | ||
|
||
`OriginAgent` is an action model, it provides state and methods for simulating a reducer function. `Agent` is a proxy object of `OriginAgent`, it can be generated from `OriginAgent` by using API createAgentReducer. The model instance and its `Agent` object shares a same state. | ||
|
||
Before `agent-reducer@3.2.0`, state updating between `Agent` objects from the same model instance is not synchronous, that may cause problems if you are sharing one model instance between some different `Agent` objects. Now, the state updating between `Agent` objects from same model instance is synchronous. If you call a method from one `Agent` object, and change its state, other `Agent` objects from the same model instance will update state too. | ||
|
||
You can check code in [state.sync.spec.ts](https://github.com/filefoxper/agent-reducer/blob/master/test/en/guides/state.sync.spec.ts). | ||
|
||
```typescript | ||
import {Action, createAgentReducer, OriginAgent, Reducer} from "agent-reducer"; | ||
|
||
describe("state updating between different Agents with same model instance", () => { | ||
|
||
// simulate a simple redux | ||
function createStore<S>(reducer: Reducer<S, Action>, initialState: S) { | ||
let listener: undefined | (() => any) = undefined; | ||
let state = initialState; | ||
return { | ||
dispatch(action: Action) { | ||
state = reducer(state, action); | ||
if (listener) { | ||
listener(); | ||
} | ||
}, | ||
getState(): S { | ||
return state; | ||
}, | ||
subscribe(l: () => any) { | ||
listener = l; | ||
l(); | ||
return () => { | ||
listener = undefined; | ||
}; | ||
}, | ||
}; | ||
} | ||
|
||
class Model implements OriginAgent<number> { | ||
|
||
state = 0; | ||
|
||
increase() { | ||
return this.state + 1; | ||
} | ||
|
||
} | ||
|
||
const model = new Model(); | ||
|
||
it("Agents from same model instance update state synchronously", () => { | ||
const reducer1 = createAgentReducer(model, {updateBy: 'manual'}); | ||
const {agent: agent1, update: update1} = reducer1; | ||
// create first store | ||
const store1 = createStore(reducer1, agent1.state); | ||
store1.subscribe(() => { | ||
update1(store1.getState(), store1.dispatch); | ||
}); | ||
|
||
const reducer2 = createAgentReducer(model, {updateBy: 'manual'}); | ||
const {agent: agent2, update: update2} = reducer2; | ||
// create second store | ||
const store2 = createStore(reducer2, agent2.state); | ||
store2.subscribe(() => { | ||
update2(store2.getState(), store2.dispatch); | ||
}); | ||
|
||
// just invoke first agent | ||
agent1.increase(); | ||
expect(agent1.state).toBe(store1.getState()); | ||
// agent1 and agent2 shares state, | ||
// for they have a same model instance | ||
expect(agent2.state).toBe(agent1.state); | ||
// though we did not dispatch any thing to store2, | ||
// but agent2 can listen its brothers changing, | ||
// and dispatch the changing state to store2 | ||
expect(agent2.state).toBe(store2.getState()); | ||
}); | ||
|
||
}); | ||
``` | ||
Go to [next section](https://github.com/filefoxper/agent-reducer/blob/master/documents/en/guides/not_recommend.md), and know some bad design in `agent-reducer` which are not recommend to use. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.