{"id":25229053,"url":"https://github.com/andres-kovalev/general-reducer","last_synced_at":"2025-10-06T13:08:05.882Z","repository":{"id":57246028,"uuid":"222165609","full_name":"andres-kovalev/general-reducer","owner":"andres-kovalev","description":"General purpose reducer generator","archived":false,"fork":false,"pushed_at":"2020-07-13T22:39:42.000Z","size":695,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T06:47:24.049Z","etag":null,"topics":["general","general-purpose","reducer","universal"],"latest_commit_sha":null,"homepage":"https://andres-kovalev.github.io/general-reducer/","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/andres-kovalev.png","metadata":{"files":{"readme":"README.hbs","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":"2019-11-16T22:11:42.000Z","updated_at":"2019-12-11T00:00:54.000Z","dependencies_parsed_at":"2022-08-24T16:31:35.541Z","dependency_job_id":null,"html_url":"https://github.com/andres-kovalev/general-reducer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andres-kovalev/general-reducer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fgeneral-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fgeneral-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fgeneral-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fgeneral-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andres-kovalev","download_url":"https://codeload.github.com/andres-kovalev/general-reducer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fgeneral-reducer/sbom","scorecard":{"id":193061,"data":{"date":"2025-08-11","repo":{"name":"github.com/andres-kovalev/general-reducer","commit":"ffe2079aeeaa88e4bf63d6e5e7b7fe124ff21b2a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/7 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 11 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T21:11:54.661Z","repository_id":57246028,"created_at":"2025-08-16T21:11:54.661Z","updated_at":"2025-08-16T21:11:54.661Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271087718,"owners_count":24697039,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["general","general-purpose","reducer","universal"],"created_at":"2025-02-11T10:46:59.097Z","updated_at":"2025-10-06T13:08:00.844Z","avatar_url":"https://github.com/andres-kovalev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![ci](https://img.shields.io/circleci/build/github/andres-kovalev/general-reducer.svg?style=flat-square\u0026logo=circleci)](https://circleci.com/gh/andres-kovalev/general-reducer)\n[![codecov](https://img.shields.io/codecov/c/github/andres-kovalev/general-reducer.svg?style=flat-square\u0026logo=codecov\u0026token=1280f2cf41a24522add9857967be2a73)](https://codecov.io/gh/andres-kovalev/general-reducer)\n[![downloads](https://img.shields.io/npm/dm/general-reducer.svg?style=flat-square\u0026logo=data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJDYXBhXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Igp3aWR0aD0iNDAwcHgiIGhlaWdodD0iNDAwcHgiIHhtbDpzcGFjZT0icHJlc2VydmUiCj48ZyBmaWxsPSJ3aGl0ZSI+PHBhdGggZD0iTTM3OSwxODAuNWgtMTAydi0xMDBoLTE1M3YxMDBoLTEwMmwxNzguNSwxNzguNWwxNzguNSwtMTc4LDUiLz48L2c+PC9zdmc+Cg==)](https://www.npmjs.com/package/general-reducer)\n[![node](https://img.shields.io/node/v/general-reducer.svg?style=flat-square\u0026logo=node.js\u0026color=007ec6)](https://nodejs.org/)\n[![npm](https://img.shields.io/npm/v/general-reducer.svg?style=flat-square\u0026logo=npm)](https://www.npmjs.com/package/general-reducer)\n[![MIT](https://img.shields.io/npm/l/general-reducer.svg?color=007ec6\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAA5ElEQVR4AY3SJWyDcRQE8G+MsnIg63XNmMm2ZuB9xjyv5tWYfAZ2TD6tGW9qzHCX3H9bX4rJz7y7K3t8NK20OT7ogHnYl3ndfK5nRwFYgxf4Nl6UBVzfjcoholIiEXbdsBS2TCERdks5HIaPVIfqDnN4HCO8gUm5iZEfc/gYI+gBT3pi5I8M3szxE0LgSYg303ljcGqOtAHFshEjP+VwOkbwCvXyGiOf5rASrkwQhhIJm4zdKg4zYBDe/z8j72Te0bu6GRxSIUzAHXxBF3jSpdudOoX2/5oDQVgEP3ji1y3Ijhv9ABp7euvVsybrAAAAAElFTkSuQmCC\u0026style=flat-square)](https://github.com/andres-kovalev/general-reducer/blob/master/LICENSE)\n[![npm bundle size](https://img.shields.io/bundlephobia/min/general-reducer.svg?style=flat-square\u0026logo=data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJDYXBhXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Igp3aWR0aD0iNDAwcHgiIGhlaWdodD0iNDAwcHgiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxnIGZpbGw9IndoaXRlIj48cGF0aCBkPSJNNzUsMzBoMTc1bDEwMCwxMDB2MjQwaC0yNzV2LTI0MCIvPjwvZz48ZyBmaWxsPSIjREREIj48cGF0aCBkPSJNMjUwLDMwbDEwMCwxMDBoLTEwMHYtMTAwIi8+PC9nPjwvc3ZnPgo=)](https://www.npmjs.com/package/general-reducer)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)\n\n# general-reducer\n\nGeneral purpose reducer generator\n\n* full documentation can be found on [https://andres-kovalev.github.io/general-reducer/](https://andres-kovalev.github.io/general-reducer/)\n\n# Description\n\n`general-reducer` provides utilities to generate universal reducer with corresponding actions.\n\n# Installation\n\nAs any other npm package `general-reducer` can be added to your project by following command:\n\n```bash\nnpm i -S general-reducer\n```\n\n# API\n\n## Universal reducer\n\n`general-reducer` package provides general purpose reducer to perform most common operations on store. You just need to configure your store with it.\n\n * with react hook:\n\n    ```js\n    import React, { useReducer } from 'react';\n    import { reducer } from 'general-reducer';\n\n    const Component = () =\u003e {\n        const [ value, dispatch ] = useReducer(reducer);\n\n        ...\n    }\n    ```\n\n * with [redux](https://redux.js.org/):\n\n    ```js\n    import { createStore } from 'redux'\n    import { reducer } from 'general-reducer';\n\n    const store = createStore(reducer);\n    ```\n\n * with [react-easy-flux](https://www.npmjs.com/package/react-easy-flux):\n\n    ```js\n    import { createStorage } from 'react-easy-flux';\n    import { reducer } from 'general-reducer';\n\n    const {\n        Provider,\n        useStorage,\n        useActions\n    } = createStorage(reducer);\n    ```\n\n\u003e Since `general-reducer` uses [immutable-object-update](https://www.npmjs.com/package/immutable-object-update) under the hood, it performs immutable state update and returns frozen object.\n\n## Built-in actions\n\n`general-reducer` exposes `ACTIONS` map object with actions for most common operations with state:\n\n{{#each actions}}\n* [{{fn}}](src/actions/{{name}}/README.md)\n{{/each}}\n\nMost of actions consumes at least 1 argument - `path` to updated element, it might be an array of items or dot-separated string. When action dispatched reducer will apply corresponding operation from [immutable-state-update](https://andres-kovalev.github.io/immutable-object-update/#api) package:\n\n```js\nimport { reducer, ACTIONS } from 'general-reducer';\n\nconst state = {\n    a: {\n        a1: 1,\n        a2: 2\n    },\n    b: {\n        b1: 3,\n        b2: 4\n    }\n};\n\nconst updated = reducer(state, ACTIONS.set('b.b1', 5));\n\n// or\n\nconst updated = reducer(state, ACTIONS.set([ 'b', 'b1' ], 5));\n```\n\nAs a result we will receive new object with structure below:\n\n```js\n{\n    a: {\n        a1: 1,\n        a2: 2\n    },\n    b: {\n        b1: 3,\n        b2: 5\n    }\n}\n```\n\n## Action combination\n\nSince `general-reducer` uses [](https://github.com/andres-kovalev/reducer-generator) under the hook, we're able to use [composite action](https://github.com/andres-kovalev/reducer-generator#combining-actions) to combine several simple actions and possibly improve performance a bit:\n\n```js\nconst trim = (path, n) =\u003e ACTIONS.all(\n    ACTIONS.shift(path, n)\n    ACTIONS.pop(path, n)\n);\n\nconst updated = reducer(state, trim('a.b', 2));\n```\n\n## Custom actions\n\nIt is possible to add custom actions to perform some complex updates. To so `createGeneralReducer()` function is exposed. It consumes map object with custom action update functions. Each update function will consume part of a state as an argument and should return updated value.\n\n```js\nconst {\n    reducer,\n    ACTIONS\n} = createGeneralReducer({\n    selectAll: items =\u003e items.map(\n        item =\u003e ({ ...item, selected: true })\n    ),\n    unselectAll: items =\u003e items.map(\n        item =\u003e ({ ...item, selected: false })\n    ),\n    removeSelected: items =\u003e items.filter(\n        ({ selected }) =\u003e !selected\n    )\n});\n```\n\nReturned actions will consume path to state piece to be updated.\n\n```js\nconst state = {\n    items: [\n        { selected: true, text: 'Steal pants' },\n        { selected: false, text: '?????' },\n        { selected: false, text: 'Profit!' }\n    ]\n};\n\nconst updated = reducer(state, ACTIONS.removeSelected('items'));\n\n/*\n{\n    items: [\n        { selected: false, text: '?????' },\n        { selected: false, text: 'Profit!' }\n    ]\n};\n*/\n```\n\nIf you need any additional arguments in your update function just pass those into action creator after path:\n\n```js\nconst {\n    reducer,\n    ACTIONS\n} = createGeneralReducer({\n    add: (value, diff) =\u003e value + diff\n});\n\nconst state = {\n    a: 10\n};\n\nconst updated = reducer(state, ACTIONS.add('a', 5));\n\n/*\n{\n    a: 15\n}\n*/\n```\n\n## Actions namespace\n\nBy default `general-reducer` uses `'general'` as a namespace for all actins, it means two different general reducers will have the same action types:\n\n```js\nconst { TYPES } = createGeneralReducer({\n    customCase: (...) =\u003e ...\n});\n\n/*\nTYPES = {\n    insert: 'general.insert',\n    insertAll: 'general.insertAll',\n    pop: 'general.pop',\n    ...\n    customCase: 'general.customCase'\n}\n*/\n```\n\nBecause of that it can be problematic to combine general reducers. To generate unique action types just provide different namespace as 2nd argument of `createGeneralReducer()` function:\n\n```js\nconst { TYPES } = createGeneralReducer({\n    customCase: (...) =\u003e ...\n}, 'customNamespace');\n\n/*\nTYPES = {\n    insert: 'customNamespace.insert',\n    insertAll: 'customNamespace.insertAll',\n    pop: 'customNamespace.pop',\n    ...\n    customCase: 'customNamespace.customCase'\n}\n*/\n```\n\nDefinitely, in most cases to extend general reducer it's better to provide custom actions or include general reducer into custom one:\n\n```js\nfunction customReducer(state, action) {\n    switch (action.type) {\n        ...\n        default:\n            return generalReducer(state, action);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandres-kovalev%2Fgeneral-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandres-kovalev%2Fgeneral-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandres-kovalev%2Fgeneral-reducer/lists"}