{"id":18615823,"url":"https://github.com/josepot/rereducer","last_synced_at":"2025-04-11T01:31:33.444Z","repository":{"id":19211022,"uuid":"86509916","full_name":"josepot/rereducer","owner":"josepot","description":"Create declarative redux reducers without boilerplate.","archived":false,"fork":false,"pushed_at":"2022-12-08T19:06:59.000Z","size":1701,"stargazers_count":13,"open_issues_count":17,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T19:51:32.703Z","etag":null,"topics":["boilerplate","reducer","redux"],"latest_commit_sha":null,"homepage":"","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/josepot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-28T21:42:09.000Z","updated_at":"2023-09-19T14:51:23.000Z","dependencies_parsed_at":"2023-01-13T22:15:20.771Z","dependency_job_id":null,"html_url":"https://github.com/josepot/rereducer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josepot%2Frereducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josepot%2Frereducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josepot%2Frereducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josepot%2Frereducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josepot","download_url":"https://codeload.github.com/josepot/rereducer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248325173,"owners_count":21084882,"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":["boilerplate","reducer","redux"],"created_at":"2024-11-07T03:33:08.133Z","updated_at":"2025-04-11T01:31:28.436Z","avatar_url":"https://github.com/josepot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rereducer\n\nCreate declarative redux reducers without boilerplate.\n\nBasic example:\n```js\nimport rereducer from 'rereducer';\nconst INITIAL_COUNTER_STATE = 0;\n\nconst counter = rereducer(\n  INITIAL_COUNTER_STATE,\n  ['INCREASE', x =\u003e x + 1],\n  ['DECREASE', x =\u003e x - 1]\n);\n\ncounter();\n// =\u003e 0\ncounter(5, { type: 'INCREASE' });\n// =\u003e 6\n```\n\nWhat if you want the same transformation for more than one action type?\n\n```js\nimport rereducer from 'rereducer';\nconst INITIAL_COUNTER_STATE = 0;\n\nconst counter = rereducer(\n  INITIAL_COUNTER_STATE,\n  ['INCREASE', x =\u003e x + 1],\n  ['DECREASE', x =\u003e x - 1],\n  [['RESET', 'LOGOUT'], () =\u003e INITIAL_COUNTER_STATE]\n);\n\ncounter(100, { type: 'RESET' });\n// =\u003e 0\ncounter(100, { type: 'LOGOUT' });\n// =\u003e 0\n```\n\nWhat if you need a more complex condition for a transformation?\n\n```js\nimport rereducer from 'rereducer';\nconst INITIAL_COUNTER_STATE = 0;\n\nconst whenSomethingSpeciallHappens = (state, action) =\u003e (\n  action.type === 'SOMETHING_SPECIAL' \u0026\u0026\n  action.payload === 'SPECIAL_INDEED' \u0026\u0026\n  state \u003e 10\n);\n\nconst counter = rereducer(\n  INITIAL_COUNTER_STATE,\n  ['INCREASE', x =\u003e x + 1],\n  ['DECREASE', x =\u003e x - 1],\n  [whenSomethingSpeciallHappens, x =\u003e x + 1000]\n);\n\ncounter(11, { type: 'SOMETHING_SPECIAL', payload: 'SPECIAL_INDEED' });\n// =\u003e 1011\ncounter(10, { type: 'SOMETHING_SPECIAL', payload: 'SPECIAL_INDEED' });\n// =\u003e 10\ncounter(11, { type: 'SOMETHING_SPECIAL' });\n// =\u003e 11\n```\n\n### Credits to:\n\n- [@winkerVSbecks](https://github.com/winkerVSbecks): For sharing good ideas and feedback about the API\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosepot%2Frereducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosepot%2Frereducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosepot%2Frereducer/lists"}