0.0.4 • Published 5 years ago

@bryandbor/redux-booleans v0.0.4

Weekly downloads
61
License
MIT
Repository
github
Last release
5 years ago

redux-booleans

Simple boolean Redux integration

NPM JavaScript Style Guide

It is often necessary to extend your Redux state for a simple boolean. A common example is adding Redux state for whether a modal is open or not. This package can handle any number of boolean keys with minimal state; due to the fact that undefined keys are treated as false, the state is always as small as possible by only holding values which are evaluated as true. The rest of your Redux state can remain simple and focused without bloat for simple boolean values.

Install

npm install --save redux-booleans

Usage

import {createStore} from 'redux';
import {reducer as booleansReducer, toggleBoolean, getBooleanState} from '@bryandbor/redux-booleans';

const rootReducer = combineReducers({
  booleans: booleansReducer,
  // ...
});

const store = createStore(rootReducer);

const termsAndConditionsModalKey = 'modals.term-and-conditions';
store.dispatch(toggleBoolean(termsAndConditionsModalKey));

console.log(store.getState());
/*
{
  booleans: {
    'modals.term-and-conditions': true
  },
}
*/

console.log(getBooleanState(store.gesState(), termsAndConditionsModalKey));
// true

store.dispatch(toggleBoolean(termsAndConditionsModalKey));

console.log(store.getState());
/*
{
  booleans: {},
}
*/
console.log(getBooleanState(store.gesState(), termsAndConditionsModalKey));
// false

License

MIT © bryandbor

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago