@acoustic-content-sdk/redux-feature-save 中文文档教程
@acoustic-content-sdk/redux-utils
实现有助于处理 redux 状态的实用函数。
Immutability
redux 模式的核心原则之一是保持所有状态不可变。 这意味着当更新一个值时,我们需要复制受影响的对象。 以下函数有助于限制这些副本的大小。
Updater
createUpdater
创建对象的包装器。 这个包装器允许设置或删除包装对象的(深层)属性而不改变它。 更新程序确保只创建最小的浅拷贝集。
示例:
const myObject={...};
const updater = createUpdater(myObject);
updater.set('elements.text.value', 'newValue');
const newObject = updater.get();
更新程序的工作方式类似于 immer 但没有开销。
Invariance Checks
在开发过程中,重要的是要验证对象没有发生变化。 使用不变性检查器对此进行测试,但出于性能原因,请确保不要在生产构建中包含这些检查。
例子:
const inv = invarianceChecker(myObject);
// do some operations
// validate that myObject has not been mutated
assert(inv());
@acoustic-content-sdk/redux-utils
Implementation of utility functions that help working with redux state.
Immutability
One of the core principals of the redux pattern is to keep all state immutable. This implies that when updating a value we need to make a copy of the affected objects. The following functions help to limit the size of these copies.
Updater
The createUpdater
creates an wrapper around an object. This wrapper allows to set or remove (deep) properties of the wrapped object without mutating it. The updater makes sure to only create the minimum set of shallow copies.
Example:
const myObject={...};
const updater = createUpdater(myObject);
updater.set('elements.text.value', 'newValue');
const newObject = updater.get();
The updater works similar to immer but without the overhead.
Invariance Checks
During development it is important to verify that objects are not getting mutated. Use the invariance checker to test this, but make sure to not include these checks in production builds for performance reasons.
Example:
const inv = invarianceChecker(myObject);
// do some operations
// validate that myObject has not been mutated
assert(inv());