{"id":27935821,"url":"https://github.com/rt2zz/redux-persist-transform-immutable","last_synced_at":"2025-05-07T06:50:48.105Z","repository":{"id":36317960,"uuid":"40622614","full_name":"rt2zz/redux-persist-transform-immutable","owner":"rt2zz","description":"immutable support for redux-persist","archived":false,"fork":false,"pushed_at":"2023-02-16T17:40:21.000Z","size":19,"stargazers_count":112,"open_issues_count":17,"forks_count":42,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-28T19:49:15.436Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rt2zz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2015-08-12T20:27:39.000Z","updated_at":"2024-01-24T10:55:03.000Z","dependencies_parsed_at":"2024-06-18T14:06:31.669Z","dependency_job_id":null,"html_url":"https://github.com/rt2zz/redux-persist-transform-immutable","commit_stats":{"total_commits":43,"total_committers":11,"mean_commits":3.909090909090909,"dds":0.2558139534883721,"last_synced_commit":"047e9d7dc207b867cec04749626ef1ccc356791f"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rt2zz%2Fredux-persist-transform-immutable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rt2zz%2Fredux-persist-transform-immutable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rt2zz%2Fredux-persist-transform-immutable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rt2zz%2Fredux-persist-transform-immutable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rt2zz","download_url":"https://codeload.github.com/rt2zz/redux-persist-transform-immutable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252831181,"owners_count":21810780,"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":"2025-05-07T06:50:47.460Z","updated_at":"2025-05-07T06:50:48.094Z","avatar_url":"https://github.com/rt2zz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux Persist Transform Immutable\nAdd immutable sub-reducer support to redux-persist.\n\n**NOTE** this handles immutable state on a per-reducer basis. If your top level state is an immutable map, this module will not work.\n\n## Breaking Change\nv5 changes from `transitjs` to `remotedev-serialize`. For existing projects that upgrade to v5, all persisted data will be lost upon the initial persist. **note** It is possible to write an upgrade via a custom transform that supports both formats - if you do write one please PR!\n\n### Usage with Redux Persist\n```js\nimport { createStore, combineReducers } from 'redux'\nimport { persistStore, persistReducer } from 'redux-persist'\nimport immutableTransform from 'redux-persist-transform-immutable'\n\nconst persistConfig = {\n  transforms: [immutableTransform()],\n  key: 'root',\n  storage\n}\n\nconst reducer = combineReducers(reducers)\nconst persistedReducer = persistReducer(persistConfig, reducer)\nconst store = createStore(persistedReducer)\n\npersistStore(store)\n```\n\n#### Config\nFor config, please refer to [redux-persist's docs](https://github.com/rt2zz/redux-persist/blob/master/docs/api.md#type-persistconfig).\n\n### Usage with Records\nBy default, immutable [`Record`s](https://facebook.github.io/immutable-js/docs/#/Record) will be persisted and restored as `Map`s, because the library has no way of knowing what your `Record` constructor looks like. To change this behavior and allow a `Record` to be persisted and restored as a `Record` instance, you'll need to do two things:\n\n1. Add a name attribute to your record (this is the second argument to a `Record`'s constructor).\n2. Pass your `Record` constructor to the transformer's `withRecords()` function to generate a transformer capable of serializing and deserializing the record.\n\nMinimal example:\n```js\nimport { compose } from 'redux'\nimport { persistStore, autoRehydrate } from 'redux-persist'\nimport immutableTransform from 'redux-persist-transform-immutable'\n\nconst reducer = combineReducers(reducers)\nconst store = compose(autoRehydrate(), createStore)(reducer)\n\nconst MyRecord = Record({\n  foo: 'null'\n}, 'MyRecord') // \u003c- Be sure to add a name field to your record\n\npersistStore(\n  store,\n  {\n    transforms: [immutableTransform({records: [MyRecord]})]\n  }\n)\n\n```\n\n### Avoiding Unnecessary Serialization\n\nBy default, `redux-persist-immutable-transform` will serialize and deserialize *all* passed objects using `transit-immutable-js`. If you are concerned about performance, you can either whitelist or blacklist reducer that you know are not immutable.\n\nExample state object:\n\n```js\nstate = {\n  username: 'john',\n  imageUri: 'images/profilePic.png',\n  friends: Immutable.List([ ... ])\n}\n```\n\nSet up the transformer to ignore the string-based reducer keys:\n\n```js\npersistStore(store, {\n  transforms: [immutableTransform({\n    blacklist: ['username', 'imageUri']\n  })]\n})\n\n/* OR */\n\npersistStore(store, {\n  transforms: [immutableTransform({\n    whitelist: ['friends']\n  })]\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frt2zz%2Fredux-persist-transform-immutable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frt2zz%2Fredux-persist-transform-immutable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frt2zz%2Fredux-persist-transform-immutable/lists"}