{"name":"redux-immutable","description":"redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.","main":"./dist/index.js","repository":{"type":"git","url":"git+https://github.com/gajus/redux-immutable.git"},"keywords":["immutable","redux"],"version":"3.0.10","author":{"name":"Gajus Kuizinas","email":"gajus@anuary.com","url":"http://gajus.com"},"license":"BSD-3-Clause","dependencies":{"flow-runtime":"0.0.6","immutable":"^3.8.1"},"devDependencies":{"babel-cli":"^6.18.0","babel-plugin-add-module-exports":"^0.2.1","babel-plugin-flow-runtime":"0.0.6","babel-plugin-syntax-flow":"^6.18.0","babel-plugin-transform-flow-strip-types":"^6.21.0","babel-preset-es2015":"^6.18.0","babel-preset-stage-0":"^6.16.0","babel-register":"^6.18.0","benchmark":"^2.1.3","chai":"^3.5.0","eslint":"^3.13.1","eslint-config-canonical":"^6.0.0","husky":"^0.12.0","mocha":"^3.2.0","semantic-release":"^6.3.2"},"scripts":{"lint":"eslint ./src ./tests","test":"mocha --compilers js:babel-register ./tests/**/*.js","build":"babel ./src --source-maps --out-dir ./dist","benchmark":"NODE_ENV=production node ./benchmarks/index.js","precommit":"npm run lint && npm run test"},"gitHead":"7ceccf8e9d74fbcd636c5fc911b6697cfdc1468e","bugs":{"url":"https://github.com/gajus/redux-immutable/issues"},"homepage":"https://github.com/gajus/redux-immutable#readme","_id":"redux-immutable@3.0.10","_shasum":"160c9ebfe59cf3f2fd4ee9baf0017cd56fe54649","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"gajus","email":"gajus@gajus.com"},"dist":{"shasum":"160c9ebfe59cf3f2fd4ee9baf0017cd56fe54649","tarball":"http://registry-npm.ywwl.com/redux-immutable/download/redux-immutable-3.0.10.tgz","integrity":"sha512-toMQ6aBcW3icz1V4Oj2rhJ4ORrdEZM9ka0E+HYvKAoz8iEZE+2DTD1hNQgLQg1onaNK3GhR/OrzyyPQqFaYaWw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICVkaZkd4N1H+A1lAM4se7Z+WFcHCb2/b/pJ3s44NIBnAiAdV561E7b35NLANy0DLp3bk+unLlT11XjOHQqtYv2jqw=="}],"size":6300,"noattachment":false,"key":"/redux-immutable/-/redux-immutable-3.0.10.tgz"},"maintainers":[{"name":"gajus","email":"gk@anuary.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/redux-immutable-3.0.10.tgz_1484133699739_0.42976068356074393"},"directories":{},"readme":"# `redux-immutable`\n\n[![Travis build status](http://img.shields.io/travis/gajus/redux-immutable/master.svg?style=flat-square)](https://travis-ci.org/gajus/redux-immutable)\n[![NPM version](http://img.shields.io/npm/v/redux-immutable.svg?style=flat-square)](https://www.npmjs.org/package/redux-immutable)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n\n`redux-immutable` is used to create an equivalent function of Redux [`combineReducers`](http://redux.js.org/docs/api/combineReducers.html) that works with [Immutable.js](https://facebook.github.io/immutable-js/) state.\n\nWhen Redux [`createStore`](https://github.com/reactjs/redux/blob/master/docs/api/createStore.md) `reducer` is created using `redux-immutable` then `initialState` must be an instance of [`Immutable.Collection`](https://facebook.github.io/immutable-js/docs/#/Collection).\n\n## Problem\n\nWhen [`createStore`](https://github.com/reactjs/redux/blob/v3.0.6/docs/api/createStore.md) is invoked with `initialState` that is an instance of `Immutable.Collection` further invocation of reducer will [produce an error](https://github.com/reactjs/redux/blob/v3.0.6/src/combineReducers.js#L31-L38):\n\n> The initialState argument passed to createStore has unexpected type of \"Object\".\n> Expected argument to be an object with the following keys: \"data\"\n\nThis is because Redux `combineReducers` [treats `state` object as a plain JavaScript object](https://github.com/reactjs/redux/blob/v3.0.6/src/combineReducers.js#L120-L129).\n\n`combineReducers` created using `redux-immutable` uses Immutable.js API to iterate the state.\n\n## Usage\n\nCreate a store with `initialState` set to an instance of [`Immutable.Collection`](https://facebook.github.io/immutable-js/docs/#/Collection):\n\n```js\nimport {\n  combineReducers\n} from 'redux-immutable';\n\nimport {\n  createStore\n} from 'redux';\n\nconst initialState = Immutable.Map();\nconst rootReducer = combineReducers({});\nconst store = createStore(rootReducer, initialState);\n```\n\nBy default, if `state` is `undefined`, `rootReducer(state, action)` is called with `state = Immutable.Map()`. A different default function can be provided as the second parameter to `combineReducers(reducers, getDefaultState)`, for example:\n\n```js\nconst StateRecord = Immutable.Record({\n\tfoo: 'bar'\n});\nconst rootReducer = combineReducers({foo: fooReducer}, StateRecord);\n// rootReducer now has signature of rootReducer(state = StateRecord(), action)\n// state now must always have 'foo' property with 'bar' as its default value\n```\n\nWhen using `Immutable.Record` it is possible to delegate default values to child reducers:\n\n```js\nconst StateRecord = Immutable.Record({\n\tfoo: undefined\n});\nconst rootReducer = combineReducers({foo: fooReducer}, StateRecord);\n// state now must always have 'foo' property with its default value returned from fooReducer(undefined, action)\n```\n\nIn general, `getDefaultState` function must return an instance of `Immutable.Record` or `Immutable.Collection` that implements `get`, `set` and `withMutations` methods. Such collections are `List`, `Map` and `OrderedMap`.\n\n### Using with `react-router-redux`\n\n`react-router-redux` [`routeReducer`](https://github.com/reactjs/react-router-redux/tree/v4.0.2#routerreducer) does not work with Immutable.js. You need to use a custom reducer:\n\n```js\nimport Immutable from 'immutable';\nimport {\n  LOCATION_CHANGE\n} from 'react-router-redux';\n\nconst initialState = Immutable.fromJS({\n  locationBeforeTransitions: null\n});\n\nexport default (state = initialState, action) => {\n  if (action.type === LOCATION_CHANGE) {\n    return state.set('locationBeforeTransitions', action.payload);\n  }\n\n  return state;\n};\n```\n\nPass a selector to access the payload state and convert it to a JavaScript object via the [`selectLocationState` option on `syncHistoryWithStore`](https://github.com/reactjs/react-router-redux/tree/v4.0.2#history--synchistorywithstorehistory-store-options):\n\n```js\nimport {\n  browserHistory\n} from 'react-router';\nimport {\n  syncHistoryWithStore\n} from 'react-router-redux';\n\nconst history = syncHistoryWithStore(browserHistory, store, {\n  selectLocationState (state) {\n      return state.get('routing').toJS();\n  }\n});\n```\n\nThe `'routing'` path depends on the `rootReducer` definition. This example assumes that `routeReducer` is made available under `routing` property of the `rootReducer`.\n","publish_time":1484133700509,"_cnpm_publish_time":1484133700509,"dist-tags":{"latest":"4.0.0"}}