Skip to content

Latest commit

 

History

History
68 lines (44 loc) · 2.72 KB

README.md

File metadata and controls

68 lines (44 loc) · 2.72 KB

redux-freeze-tag

A tiny, tiny library that adds customizable immutability to Redux. It does this by using freeze-tag to enhance the reducer(s) you use to create your Redux store.

It's recommended you delete redux-freeze-tag in any production build.. It will slow state changes down some, especially if you configure the method to handle mutations other than set. But it's plenty fast enough for development!

Features

  • Recursive - Begins at your state object and goes all the way down. No data structure left behind.
  • Fast - Places a mutation handler on objects, which is way faster than the recursive Object.freeze-ing solution you normally see.
  • Simple API - One line of code in your Redux store setup. Then you can copy your state for mutation using whatever method you normally (I hope!) use to copy mutable objects.
  • Configurable - A simple options parameter allows you to set rules for mutations.

Usage

npm install redux-freeze-tag

Then, in your JavaScript:

import reduxFreeze from 'redux-freeze-tag';
import {createStore} from 'redux';

const store = createStore(reduxFreeze(reducer));

reduxFreeze will return an enhanced reducer that immutablizes state, which you use to create your store and never worry about again. No more accidental reducer mutations or crazy immutability APIs!

Configuration

You can configure the internal freeze-tag behavior by passing in an options object as a second argument. It's the same options object that regular freeze-tag uses. (See the configuration section of the freeze-tag README for more info on this feature.)

const options = {delete: true};
const store = createStore(reduxFreeze(reducer, options));

You can even configure which reducers to use redux-freeze-tag on.

import {combineReducers} from 'redux';

const rootReducer = combineReducers({
  todoReducer: reduxFreeze(todoReducer),
  calendarReducer: calendarReducer,
  chatReducer: chatReducer,
  reviewsReducer: reduxFreeze(reviewsReducer)
}); // WHAT UNHOLY HYBRID APP ABOMINATION IS THIS.

And, of course, you can pass in an options object to any of those reduxFreeze calls as well.

How Does One Play the Actual Game of Freeze Tag?

Like this:

alt text

Except usually without soccer balls. But that sounds cool! Hit me up if you wanna play.