{"id":23338751,"url":"https://github.com/appfeel/path-reducer","last_synced_at":"2025-06-17T08:04:41.555Z","repository":{"id":57320702,"uuid":"58740338","full_name":"appfeel/path-reducer","owner":"appfeel","description":"Reducer that updates the state with action path. Ready to use as redux middleware.","archived":false,"fork":false,"pushed_at":"2016-05-24T11:47:44.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-17T08:04:40.663Z","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/appfeel.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":"2016-05-13T12:53:16.000Z","updated_at":"2016-05-17T13:45:00.000Z","dependencies_parsed_at":"2022-08-26T01:10:37.877Z","dependency_job_id":null,"html_url":"https://github.com/appfeel/path-reducer","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/appfeel/path-reducer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfeel%2Fpath-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfeel%2Fpath-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfeel%2Fpath-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfeel%2Fpath-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appfeel","download_url":"https://codeload.github.com/appfeel/path-reducer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfeel%2Fpath-reducer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260318645,"owners_count":22991116,"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-12-21T03:16:18.539Z","updated_at":"2025-06-17T08:04:41.527Z","avatar_url":"https://github.com/appfeel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Path reducer\n\n[![License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://npmjs.org/package/path-reducer)\n[![NPM version](http://img.shields.io/npm/v/path-reducer.svg?style=flat)](https://npmjs.org/package/path-reducer)\n[![Downloads](http://img.shields.io/npm/dm/path-reducer.svg?style=flat)](https://npmjs.org/package/path-reducer)\n[![Build Status](http://img.shields.io/travis/appfeel/path-reducer.svg?style=flat)](https://travis-ci.org/appfeel/path-reducer)\n[![dependency status](https://img.shields.io/david/appfeel/path-reducer.svg?style=flat)](https://david-dm.org/appfeel/path-reducer)\n\nThis is a reducer function to modify the app state via path (100% compatible with [redux](https://github.com/reactjs/redux)).\nAt this development stage, it only works with [immutable-js](https://facebook.github.io/immutable-js/docs/#/) state objects.\n\n# Quick start\n\n```javascript\nimport { assert } from 'chai';\nimport { pathReducer } from 'path-reducer';\nimport { Immutable } from 'immutable';\nimport { createStore } from 'redux';\n\nconst defaultState = Immutable.fromJS({\n    foo: 0,\n    bar: {\n        boo: 0,\n        bla: 0\n    }\n});\nconst reducer = (state = defaultState, action) =\u003e {\n    // Operate with nextState here\n    return state;\n};\nconst store = createStore(pathReducer(reducer));\nconst action = {\n    type: 'updateElementInObject',\n    meta: ['bar', 'boo'],\n    payload: {\n        boo: 1\n    }\n};\n\nstore.dispatch(action);\nassert.equal(store.getState(), {\n    foo: 0,\n    bar: {\n        boo: 1,\n        bla: 0\n    }\n});\n```\n\n# API\n\n## pathReducer(reducer)\nThis is a reducer wrapper that makes your life easier:\n\n```javascript\nconst reducer = (state = defaultState, action) {\n    // The state here is already parsed\n    return state;\n};\nconst store = createStore(pathReducer(reducer));\n```\n\nThe `pathReducer` function will look for an array in `meta` and an object/array in `payload`.\nIf this conditions are met, it will try to update the path specified into the supplied state.\n\n**[SEE CASES.md](https://github.com/appfeel/path-reducer/blob/master/CASES.md)** for an extended list of expample cases.\n\n\n## updateImmutableState(state, action)\nThis is just a simple reducer. It allows you to setup which parts of your reducer will be updated with path:\n\n```javascript\nimport { updateImmutableState } from 'path-reducer';\nimport { combineReducers, createStore } from 'redux';\n\nconst somePartOfTheTree = (state = someDefaultState, action) =\u003e {\n    switch (action.type) {\n        case 'PATH':\n            const nextState = updateImmutableState(state, action);\n            // Operate with nextState here\n            return nextState;\n        default:\n            return state;\n    }\n};\n\nconst anotherPartOfTheTree = (state = anotherDefaultState, action) =\u003e {\n    switch (action.type) {\n        case 'NO_PATH':\n            const nextState = Object.assign({}, state);\n            // ... Operate the state\n            return nextState;\n        default:\n            return state;\n    }\n};\n\nconst wholeTree = combineReducers({\n    somePartOfTheTree,\n    anotherPartOfTheTree,\n});\n\nconst store = createStore(wholeTree);\n```\n\nIt expects an FSA action:\n\n```json\n{\n    \"type\": \"myApp/myAction\",\n    \"meta\": [],\n    \"payload\": { }\n}\n```\n\n*Note* the path must be relative to the suplied path, not to the state path. If you are updating a sub-tree of the state, you should add the corresponding part of the path to the action:\n\n\n```javascript\nconst reducer = (state = defaultState, action) =\u003e {\n    const newAction = {\n        type: action.type,\n        meta: ['additional', 'path', 'elements', ...action.path],\n        payload: Object.assign({}, action.payload)\n    };\n    const nextState = updateImmutableState(state, action);\n    // Operate with nextState here\n    return nextState;\n};\n```\n\n# License: MIT\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016 AppFeel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n# Next steps\n\n- [ ] Support non [immutable-js](https://facebook.github.io/immutable-js/docs/#/) state\n\n*\u003cp style=\"font-size: small;\" align=\"right\"\u003e\u003ca color=\"#232323;\" href=\"http://appfeel.com\"\u003eMade in Barcelona with \u003cspan color=\"#FCB\"\u003e\u003c3\u003c/span\u003e and \u003cspan color=\"#BBCCFF\"\u003eCode\u003c/span\u003e\u003c/a\u003e\u003c/p\u003e*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappfeel%2Fpath-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappfeel%2Fpath-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappfeel%2Fpath-reducer/lists"}