{"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.4","author":{"name":"Gajus Kuizinas","email":"gajus@anuary.com","url":"http://gajus.com"},"license":"BSD-3-Clause","dependencies":{},"devDependencies":{"benchmark":"^2.1.0","chai":"^3.5.0","create-index":"0.1.2","immutable":"^3.7.6","pragmatist":"^3.0.13"},"peerDependencies":{"immutable":"^3.7.6"},"scripts":{"create-index":"create-index --update-index ./src/utilities","pragmatist":"pragmatist --es5","lint":"npm run pragmatist lint","test":"npm run pragmatist test","build":"npm run pragmatist build","watch":"npm run pragmatist watch","watch-lint":"npm run pragmatist watch-lint","watch-test":"npm run pragmatist watch-test","watch-build":"npm run pragmatist watch-build","benchmark":"NODE_ENV=production node ./benchmarks/index.js"},"gitHead":"07775b7dc195b8334ca88746871595315dea2100","bugs":{"url":"https://github.com/gajus/redux-immutable/issues"},"homepage":"https://github.com/gajus/redux-immutable#readme","_id":"redux-immutable@3.0.4","_shasum":"0aafc071cf6f4b6ec1da0d51d3ce17af1550d1b2","_from":".","_npmVersion":"3.7.2","_nodeVersion":"5.6.0","_npmUser":{"name":"gajus","email":"gajus@gajus.com"},"dist":{"shasum":"0aafc071cf6f4b6ec1da0d51d3ce17af1550d1b2","tarball":"http://registry-npm.ywwl.com/redux-immutable/download/redux-immutable-3.0.4.tgz","integrity":"sha512-aEDdM6pvhXh/YrJRdsRMSQ7P1elLdTxZe2c8VW7WWp6AOhWvu1pEFogdEPJpBc7Rh8Bacf6Kv6HVg1r50KUQDw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID1O8zbpunrMN4CrW3bfJhuHzr+WNOJJe3GyUxqwiGzwAiA1Ke/xXJtmMUPzJHL+5sB4sYeZq65tJrLHvjKx1YEUDw=="}],"size":2901,"noattachment":false,"key":"/redux-immutable/-/redux-immutable-3.0.4.tgz"},"maintainers":[{"name":"gajus","email":"gk@anuary.com"}],"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/redux-immutable-3.0.4.tgz_1456162076105_0.8335268821101636"},"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":1456162081208,"_cnpm_publish_time":1456162081208,"dist-tags":{"latest":"4.0.0"}}