{"id":17772489,"url":"https://github.com/kwelch/entities-reducer","last_synced_at":"2025-06-24T06:33:32.930Z","repository":{"id":17069115,"uuid":"80489057","full_name":"kwelch/entities-reducer","owner":"kwelch","description":"Redux high order reducer for FSA normalized payloads","archived":false,"fork":false,"pushed_at":"2023-12-15T05:12:50.000Z","size":634,"stargazers_count":5,"open_issues_count":13,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-22T02:09:10.911Z","etag":null,"topics":["entities","entities-reducer","normalizer","reducer","redux"],"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/kwelch.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}},"created_at":"2017-01-31T03:50:04.000Z","updated_at":"2023-03-27T23:37:11.000Z","dependencies_parsed_at":"2023-01-13T19:08:38.248Z","dependency_job_id":null,"html_url":"https://github.com/kwelch/entities-reducer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwelch%2Fentities-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwelch%2Fentities-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwelch%2Fentities-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwelch%2Fentities-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwelch","download_url":"https://codeload.github.com/kwelch/entities-reducer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221587147,"owners_count":16848049,"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":["entities","entities-reducer","normalizer","reducer","redux"],"created_at":"2024-10-26T21:39:22.374Z","updated_at":"2024-10-26T21:39:22.845Z","avatar_url":"https://github.com/kwelch.png","language":"JavaScript","funding_links":[],"categories":["Marks"],"sub_categories":["[React - A JavaScript library for building user interfaces](http://facebook.github.io/react)"],"readme":"# Entities Reducer\n\n[![Build Status][build-badge]][build]\n[![Code Coverage][coverage-badge]][coverage]\n[![version][version-badge]][package]\n\n\n[![Watch on GitHub][github-watch-badge]][github-watch]\n[![Star on GitHub][github-star-badge]][github-star]\n\nThis package is a high-order reducer that updates state using entities from [normalizr](https://github.com/paularmstrong/normalizr).\nBy default, it expects the action to have a property of `entities` or to follow the [`flux-standard-action` spec](https://github.com/acdlite/flux-standard-action).\nHowever, it is possible to pass a data resolver ([see Parameters](#parameters)) if your case doesn't match either of those.  \n\n## Why\n**Why does this package exist?**\n\nOne of the best things to store in redux is data from server requests. Additionally, working with items stored in redux is best done when the data is normalized.\nTo simplify the storing of the data, this package will handle updating state with fresh normalized data.\n \nEntities Reducer is a high-order reducer, which means it will accept more reducers for further customizations.\nThe custom reducers are passed directly to `combineReducers` from redux and should be passed into `entities-reducers` with the same format. \n\n## Installation\n```\nnpm install --save entities-reducer\n--- or ---\nyarn add entities-reducer\n```\n\nThen add to your root reducer:\n```javascript\nimport { combineReducers } from 'redux';\nimport entitiesReducer from 'entities-reducer';\n\nconst rootReducer = combineReducers({\n  entities: entitiesReducer({\n    /* custom reducers here */\n  }),\n});\n\nexport default rootReducer;\n```\n\n# Parameters\n\n```javascript\nentitiesReducer(reducers, { dataResolver })\n```\n\n### Reducers\nReducers are passed directly into `combineReducers` from redux, after the entities have been updated in state. It is called with the updated state and immediately returned. \n\n### dataResolver\nThe data resolver is a lookup function that is passed the action and returns the entities object to use while updating.\nIf the data resolver returns a falsy value the `entities-reducer` will skip process and move directly to handling the custom reducers. \nBelow is a customer dataResolver example, or you can checkout the [default resolver](src/index.js). \n**Example**\n```javascript\nconst customDataResolver = (action) =\u003e {\n  if (action.error) {\n    return false;\n  }\n  return action.data.extra.normalized;\n}\n```\n\n\n[build]: https://travis-ci.org/kwelch/entities-reducer\n[build-badge]: https://img.shields.io/travis/kwelch/entities-reducer.svg?style=flat-square\n[coverage-badge]: https://img.shields.io/codecov/c/github/kwelch/entities-reducer.svg?style=flat-square\n[coverage]: https://codecov.io/github/kwelch/entities-reducer\n[github-watch-badge]: https://img.shields.io/github/watchers/kwelch/entities-reducer.svg?style=social\n[github-watch]: https://github.com/kwelch/entities-reducer/watchers\n[github-star-badge]: https://img.shields.io/github/stars/kwelch/entities-reducer.svg?style=social\n[github-star]: https://github.com/kwelch/entities-reducer/stargazers\n[version-badge]: https://img.shields.io/npm/v/entities-reducer.svg?style=flat-square\n[package]: https://www.npmjs.com/package/entities-reducer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwelch%2Fentities-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwelch%2Fentities-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwelch%2Fentities-reducer/lists"}