{"id":20606809,"url":"https://github.com/jochumdev/redux-immutable-ts","last_synced_at":"2025-03-06T17:18:02.226Z","repository":{"id":67627076,"uuid":"448423275","full_name":"jochumdev/redux-immutable-ts","owner":"jochumdev","description":"redux-immutable-ts is used to create an equivalent function of Redux combineReducers that works with Immutable.js state which is written in typescript.","archived":false,"fork":false,"pushed_at":"2022-01-16T00:32:39.000Z","size":180,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T02:40:56.468Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/jochumdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-16T00:32:07.000Z","updated_at":"2024-05-06T10:13:01.000Z","dependencies_parsed_at":"2023-05-10T23:00:28.709Z","dependency_job_id":null,"html_url":"https://github.com/jochumdev/redux-immutable-ts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jochumdev%2Fredux-immutable-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jochumdev%2Fredux-immutable-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jochumdev%2Fredux-immutable-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jochumdev%2Fredux-immutable-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jochumdev","download_url":"https://codeload.github.com/jochumdev/redux-immutable-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242250928,"owners_count":20096897,"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":[],"created_at":"2024-11-16T09:34:46.579Z","updated_at":"2025-03-06T17:18:02.202Z","avatar_url":"https://github.com/jochumdev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `redux-immutable-ts`\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 { combineReducers } from \"redux-immutable\";\n\nimport { createStore } 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  foo: \"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  foo: 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 { LOCATION_CHANGE } 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 { browserHistory } from \"react-router\";\nimport { syncHistoryWithStore } 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\n\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 { Map } from \"immutable\";\nimport { LOCATION_CHANGE } from \"react-router-redux\";\n\nconst initialState = Map({\n  location: null,\n  action: null\n});\n\nexport function routerReducer(\n  state = initialState,\n  { type, payload = {} } = {}\n) {\n  if (type === LOCATION_CHANGE) {\n    const location = payload.location || payload;\n    const action = payload.action;\n\n    return state.set(\"location\", location).set(\"action\", action);\n  }\n\n  return state;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjochumdev%2Fredux-immutable-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjochumdev%2Fredux-immutable-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjochumdev%2Fredux-immutable-ts/lists"}