npm

@acoustic-content-sdk/redux-feature-error
TypeScript icon, indicating that this package has built-in type declarations

9.0.10076 • Public • Published

@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());

Package Sidebar

Install

npm i @acoustic-content-sdk/redux-feature-error

Weekly Downloads

52

Version

9.0.10076

License

MIT

Unpacked Size

181 kB

Total Files

58

Last publish

Collaborators

  • marcin-pasiewicz
  • nikodem.graczewski.acoustic
  • pawel.galias-ac
  • orenaksakal
  • marcin.konopka-ac