This package has been deprecated

Author message:

No longer in use

typesafereduxstate-js
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

Build Status

TypeSafeReduxState-JS

Functional, type-safe Redux state.

To use this State:

import { State } from 'typesafereduxstate-js';

This State object contains the a key-value object of the current state values, as well as a key-value object of nested substates. To access the value at any node, use:

state.valueAtNode(string);

The parameter of this function should be a String whose components are joined with the specified substateSeparator (which is by default '.'). For example:

state.valueAtNode('a.b.c.d.e');

The above call will access the value at key 'e' of substate 'a.b.c.d'.

In order to update the value at some node, call:

state.updatingValue(string, Nullable<any>);

The State object will update the value at that node, and if necessary create new substates along the way.

This State is useful for Redux reducers because you will not need to check for existence of property keys before updating value at a node. A reducer can be as such:

function reduce(state: State.Self<any>, action: Action): State.Self<any> {
  return state
    .updatingValue('auth.login.username', action.username)
    .updatingValue('auth.login.password', action.password)
    .updatingValue('auth.login.email', action.email);
}

As a result, we have a robust, functional set of reducers.

Readme

Keywords

none

Package Sidebar

Install

npm i typesafereduxstate-js

Weekly Downloads

5

Version

1.1.2

License

Apache-2.0

Last publish

Collaborators

  • haipham