{"id":13617964,"url":"https://github.com/gajus/redux-immutable","last_synced_at":"2025-05-14T03:06:35.348Z","repository":{"id":36107170,"uuid":"40408758","full_name":"gajus/redux-immutable","owner":"gajus","description":"redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.","archived":false,"fork":false,"pushed_at":"2022-03-28T21:47:31.000Z","size":134,"stargazers_count":1877,"open_issues_count":10,"forks_count":83,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-11T01:48:59.821Z","etag":null,"topics":["immutable","javascript","react","redux"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"gajus","patreon":"gajus"}},"created_at":"2015-08-08T16:19:35.000Z","updated_at":"2025-04-26T14:44:46.000Z","dependencies_parsed_at":"2022-08-31T20:00:12.958Z","dependency_job_id":null,"html_url":"https://github.com/gajus/redux-immutable","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fredux-immutable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fredux-immutable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fredux-immutable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fredux-immutable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/redux-immutable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059500,"owners_count":22007768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["immutable","javascript","react","redux"],"created_at":"2024-08-01T20:01:51.687Z","updated_at":"2025-05-14T03:06:35.302Z","avatar_url":"https://github.com/gajus.png","language":"TypeScript","readme":"# `redux-immutable`\n\n[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/redux-immutable?style=flat-square)](https://gitspo.com/mentions/gajus/redux-immutable)\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\u003e The initialState argument passed to createStore has unexpected type of \"Object\".\n\u003e 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` v4 and under\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) =\u003e {\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\n### Using with `react-router-redux` v5\nTo make [`react-router-redux` v5](https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux) work with Immutable.js you only need to use a custom reducer:\n\n```js\nimport {\n  Map\n} from 'immutable';\nimport {\n  LOCATION_CHANGE\n} from 'react-router-redux';\n\nconst initialState = Map({\n  location: null,\n  action: null\n});\n\nexport function routerReducer(state = initialState, {type, payload = {}} = {}) {\n  if (type === LOCATION_CHANGE) {\n    const location = payload.location || payload;\n    const action = payload.action;\n\n    return state\n      .set('location', location)\n      .set('action', action);\n  }\n\n  return state;\n}\n\n```\n","funding_links":["https://github.com/sponsors/gajus","https://patreon.com/gajus"],"categories":["TypeScript","JavaScript","Utilities","Uncategorized","Marks","React"],"sub_categories":["Uncategorized","[React - A JavaScript library for building user interfaces](http://facebook.github.io/react)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fredux-immutable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fredux-immutable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fredux-immutable/lists"}