{"id":18711910,"url":"https://github.com/algolia/redux-updeep","last_synced_at":"2025-06-28T14:34:44.882Z","repository":{"id":57351836,"uuid":"63052238","full_name":"algolia/redux-updeep","owner":"algolia","description":"small reducer generator that uses updeep to immutably deep merge partial updates into the reducer's state","archived":false,"fork":false,"pushed_at":"2018-05-28T19:42:09.000Z","size":10,"stargazers_count":50,"open_issues_count":1,"forks_count":4,"subscribers_count":71,"default_branch":"master","last_synced_at":"2025-05-25T22:42:10.104Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algolia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-11T08:52:02.000Z","updated_at":"2025-01-15T15:32:07.000Z","dependencies_parsed_at":"2022-08-29T10:52:50.719Z","dependency_job_id":null,"html_url":"https://github.com/algolia/redux-updeep","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/algolia/redux-updeep","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fredux-updeep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fredux-updeep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fredux-updeep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fredux-updeep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algolia","download_url":"https://codeload.github.com/algolia/redux-updeep/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fredux-updeep/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260781438,"owners_count":23062237,"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-07T12:40:43.594Z","updated_at":"2025-06-19T15:42:19.012Z","avatar_url":"https://github.com/algolia.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# redux-updeep\n\n`redux-updeep` is a small reducer generator that uses [updeep](https://github.com/substantial/updeep) to immutably deep merge partial updates into the reducer's state. It's great for reducing boilerplate in your redux actions and reducers!\n\n[![Version][version-svg]][package-url] [![Build Status][travis-svg]][travis-url] [![License][license-image]][license-url]\n\n## Installation\n\n`redux-updeep` is available on npm:\n\n```bash\nnpm install redux-updeep\n```\n\n\n## Getting started\n\n### 1. Create your reducers\n\n```js\nimport createReducer from 'redux-updeep';\n\nconst initialState = {\n  user: {\n    name: 'Alex',\n    company: 'Algolia'\n  }\n};\n\nexport default createReducer('MY_REDUCER', initialState);\n```\n\nThat's it ! No need to specify any actions, `redux-updeep` will take care of it.\n\n\n### 2. Dispatch actions\n\nIn the previous example, `MY_REDUCER` is the namespace of the reducer. The reducer automatically handle any action whose `type` starts with `MY_REDUCER` and immutable deep merge the `payload` of the action into the reducer state.\n\n```js\nexport function updateName(newName) {\n  return {\n    type: 'MY_REDUCER/UPDATE_NAME',\n    payload: {\n      user: {\n        name: newName\n      }\n    }\n  };\n}\n```\n\n```js\ndispatch(updateName('Alexandre'))\n\n//  New State:\n{\n  user: {\n    name: 'Alexandre',\n    company: 'Algolia'\n  }\n}\n```\n\n\n\n## Advanced usage\n\n### Handling Arrays\n\nDeep merging arrays using updeep can lead to surprising behaviour, therefore it's recommended to use [`updeep.constant`](https://github.com/substantial/updeep#uconstantobject) when merging arrays as values.\n\nUpdeep provides a number of utility functions which are very useful for handling arrays, for instance [`updeep.reject`](https://github.com/substantial/updeep#urejectpredicate-object).\n\n\n```js\nimport createReducer from 'redux-updeep';\nimport u from 'updeep';\n\nconst initialState = {\n  user: {\n    name: 'Alex',\n    company: 'Algolia',\n    favoriteColors: ['green', 'rebeccapurple']\n  }\n};\n\nexport default createReducer('MY_REDUCER', initialState);\n\nexport function removeFavoriteColor(newFavoriteColors) {\n  return {\n    type: 'MY_REDUCER/UPDATE_FAVORITE_COLORS',\n    payload: {\n      user: {\n        // Will ensure the new array replaces the previous one instead of merging with it\n        favoriteColor: u.constant(newFavoriteColors)\n      }\n    }\n  };\n}\n\nexport function removeFavoriteColor(colorToRemove) {\n  return {\n    type: 'MY_REDUCER/REMOVE_FAVORITE_COLOR',\n    payload: {\n      user: {\n        favoriteColor: u.reject(item =\u003e item === colorToRemove)\n      }\n    }\n  };\n}\n```\n\n\n### Complex actions\n\nSometimes deep merging partial updates is not enough and we need to perform complex transformations of the state. In this case, it is possible to pass a third argument to the `createReducer` function, which needs to be an object mapping action types to normal reducers.\n\n```js\nexport default createReducer('MY_REDUCER', initialState, {\n  'MY_REDUCER/COMPLEX_ACTION': (state, action) =\u003e {\n    return complexTransformation(state, action.payload);\n  };\n})\n```\n\n\n### Specifying a path\n\nIt is possible to specify a `path` at which the payload should be merged inside the object. Those paths are the same as the [`_.get`](https://lodash.com/docs#get) paths and can be strings or arrays.\n\n```js\nimport createReducer from 'redux-updeep';\nimport {reject} from 'updeep';\n\nconst initialState = {\n  user: {\n    name: 'Alex',\n    company: 'Algolia',\n  }\n};\n\nexport default createReducer('MY_REDUCER', initialState);\n\nexport function updateName(newName) {\n  return {\n    type: 'MY_REDUCER/UPDATE_FAVORITE_COLORS',\n    payload: newName,\n    path: ['user', 'name']\n  };\n}\n```\n\n\n[version-svg]: https://img.shields.io/npm/v/redux-updeep.svg?style=flat-square\n[package-url]: https://npmjs.org/package/redux-updeep.js\n[travis-svg]: https://img.shields.io/travis/algolia/redux-updeep/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/algolia/redux-updeep\n[license-image]: http://img.shields.io/badge/license-MIT-green.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: https://img.shields.io/npm/dm/redux-udeep.js.svg?style=flat-square\n[downloads-url]: http://npm-stat.com/charts.html?package=redux-updeep","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fredux-updeep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgolia%2Fredux-updeep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fredux-updeep/lists"}