Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
/ immutable-redux Public archive

Utilities for dealing with Immutable data structures in Redux.

License

Notifications You must be signed in to change notification settings

unindented/immutable-redux

Repository files navigation

Immutable Redux Version Build Status Dependency Status Coverage Status

Provides utilities for dealing with Immutable data structures in Redux.

Installation

To install the stable version along with Immutable and Redux, run the following:

$ npm install --save immutable-redux immutable redux

This assumes that you're using the npm package manager with a module bundler like Webpack or Browserify.

If you don't yet use npm or a modern module bundler, and would rather prefer a single-file UMD build that makes ImmutableRedux available as a global object, you can build it yourself by running the following:

$ npm run build

You'll find the development (immutable-redux.js) and production (immutable-redux.min.js) versions of the library in the dist folder. I don't recommend this approach for any serious application.

Usage

import {List} from 'immutable'
import {createStore} from 'redux'
import {combineImmutableReducers} from 'immutable-redux'

const reducer = combineImmutableReducers({
  counter: (state = 0, action) =>
    action.type === 'INCREMENT' ? state + 1 : state,
  stack: (state = List(), action) =>
    action.type === 'PUSH' ? state.push(action.payload) : state
})

let store = createStore(reducer)

store.subscribe(() =>
  console.log(store.getState())
)

store.dispatch({type: 'INCREMENT'})
// => Map { "counter": 1, "stack": List [] }
store.dispatch({type: 'PUSH', payload: 'a'})
// => Map { "counter": 1, "stack": List [ "a" ] }

Meta

Contributors

License

Copyright (c) 2015 Daniel Perez Alvarez (unindented.org). This is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Utilities for dealing with Immutable data structures in Redux.

Resources

License

Stars

Watchers

Forks

Packages

No packages published