Wildhoney / redux-nest

Redux middleware for wrapping store in a Proxy to help with complex nested states.

Home Page:https://github.com/rackt/redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redux Nest

Redux middleware for wrapping store in a Proxy to help with complex nested states.

Getting Started

You need to import the module and then include it in the applyMiddleware invocation.

import {createStore, applyMiddleware} from 'redux';
import {nest} from 'redux-nest';

// ...

const createStoreWithMiddleware = applyMiddleware(nest)(createStore);

From there any data that passes through the store will be wrapped in a Proxy that will prevent undefined from causing issues when you chain properties.

In the following case, even if person is undefined it will still succeed and simply print nothing:

<label>
    {store.person.name}
</label>

Is Defined?

As the data is wrapped in a Proxy you cannot do the usual check of typeof x === 'undefined' because now x is an instance of Proxy — to allow you to check if x is undefined, redux-nest provides two functions.

import {isDefined, isUndefined} from 'redux-nest';

// ...

if (isDefined(x)) {

}

About

Redux middleware for wrapping store in a Proxy to help with complex nested states.

https://github.com/rackt/redux

License:MIT License


Languages

Language:JavaScript 100.0%