{"id":22132443,"url":"https://github.com/chiefgui/reswitch","last_synced_at":"2026-03-11T16:37:22.484Z","repository":{"id":75643953,"uuid":"55030850","full_name":"chiefGui/reswitch","owner":"chiefGui","description":"A tiny library to write friendly reducers with less boilerplate.","archived":false,"fork":false,"pushed_at":"2017-03-13T13:52:30.000Z","size":56,"stargazers_count":38,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-27T00:06:59.134Z","etag":null,"topics":["javascript","react","reducer","reducers","redux","redux-saga","switch"],"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/chiefGui.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-30T03:53:02.000Z","updated_at":"2022-11-23T02:15:58.000Z","dependencies_parsed_at":"2024-01-07T20:12:21.785Z","dependency_job_id":null,"html_url":"https://github.com/chiefGui/reswitch","commit_stats":{"total_commits":32,"total_committers":4,"mean_commits":8.0,"dds":0.09375,"last_synced_commit":"116710dfa2d69cdbfbf1d657681d515c8d8c98f1"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiefGui%2Freswitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiefGui%2Freswitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiefGui%2Freswitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiefGui%2Freswitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chiefGui","download_url":"https://codeload.github.com/chiefGui/reswitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227614534,"owners_count":17793944,"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":["javascript","react","reducer","reducers","redux","redux-saga","switch"],"created_at":"2024-12-01T18:41:36.345Z","updated_at":"2026-03-11T16:37:22.456Z","avatar_url":"https://github.com/chiefGui.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"http://i.imgur.com/PptVucZ.png\" align=\"right\" height=\"280px\" hspace=\"30px\" vspace=\"30px\"\u003e\n\n# \u003cem\u003ere\u003c/em\u003eswitch \u003csup\u003ev1.0.0\u003c/sup\u003e [![Build Status](https://travis-ci.org/chiefGui/reswitch.svg?branch=master)](https://travis-ci.org/chiefGui/reswitch)\n\nA tiny library to write friendly reducers with less boilerplate.\n\n\n### Install\n\n`yarn add reswitch` or `npm install reswitch --save`\n\n### Usage\n\nIts usage couldn't be simpler: you pass as much arguments as you need to the\n`reswitch` function, being the odd ones the actions dispatched and the\neven ones the state the action will return:\n\n```js\n/* /reducers/users.js */\n\nimport reswitch from 'reswitch'\nimport {USERS_GET, USERS_GET__SUCCESS, USERS_GET__FAILURE} from 'consts/users'\n\nconst INITIAL_STATE = {areLoading: false, hasError: false, users: null}\n\nconst users(state = INITIAL_STATE, action) =\u003e reswitch(\n  USERS_GET,\n    {...defaultState, areLoading: true},\n\n  USERS_GET__SUCCESS,\n    {...defaultState, areLoading: false, users: action.users},\n\n  USERS_GET__FAILURE,\n    {...defaultState, areLoading: false, hasError: true}\n)(state, action.type)\n\nexport default users\n```\n\n**Arrays are also welcomed:**\n\n```js\nreswitch(\n  ADD_TODO,\n    [...state.todos, action.todo]\n)(state, action.type)\n```\n\n**As well as a function:**\n\n```js\nreswitch(\n  REMOVE_TODO,\n    () =\u003e state.todos.filter(todo =\u003e todo.id !== action.todo.id)\n)(state, action.type)\n```\n\nThe default action is the current state of your reducer. You can customise it\nby just passing an `object`, `array` or `function` as the last argument of\n`reswitch`, without any explicit action:\n\n```js\nreswitch(\n  ADD_TODO,\n    [...state.todos, action.todo],\n\n  () =\u003e sort(state.todos)\n)(state, action.type)\n```\n\nThat's it.\n\n### Tests\n\n`yarn test` or `npm test`\n\n### Motivation\n\nI personally don't like those huge amounts of `switch`es. Tokens out and about,\nneedless. Too much verbosity. To describe what I'm saying, this:\n\n![](http://i.imgur.com/VTfXQdY.png)\n\nBecomes this:\n\n![](http://i.imgur.com/dOMlzER.png)\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchiefgui%2Freswitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchiefgui%2Freswitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchiefgui%2Freswitch/lists"}