{"id":25620763,"url":"https://github.com/codewell/automatic-action-switch","last_synced_at":"2025-10-28T13:31:51.342Z","repository":{"id":35116382,"uuid":"208589629","full_name":"codewell/automatic-action-switch","owner":"codewell","description":"Automatically perform reducer actions depending on the action type","archived":false,"fork":false,"pushed_at":"2023-01-07T09:46:20.000Z","size":685,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T07:52:31.328Z","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/codewell.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":"2019-09-15T12:18:34.000Z","updated_at":"2021-06-30T11:47:47.000Z","dependencies_parsed_at":"2023-01-15T14:09:37.166Z","dependency_job_id":null,"html_url":"https://github.com/codewell/automatic-action-switch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewell%2Fautomatic-action-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewell%2Fautomatic-action-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewell%2Fautomatic-action-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewell%2Fautomatic-action-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codewell","download_url":"https://codeload.github.com/codewell/automatic-action-switch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240139755,"owners_count":19754173,"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":"2025-02-22T07:27:59.336Z","updated_at":"2025-10-28T13:31:51.241Z","avatar_url":"https://github.com/codewell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @codewell/automatic-action-switch\nAutomatically perform reducer actions depending on the action type.\nWill automatically update a state property depending on the passed action type.\nIntended to work with flat states.\n\nLets say we have a dispatched action\n`{type: 'SET_FOO', payload: 'value'}`\nThe result of the automatic action switch (if the initial state is `{}`) will be:\n`{foo: 'value'}`. There is a bit of magic. The state property will be calculated from the actual action type. The prefix is ignored and used to select what type of state action should be performed (i.e. reducer function). `SET` overrides a state property, `UPDATE` updates the passed properties, `REMOVE` removes a state property.\n\n\n```JavaScript\n// Set the state property named 'stateProperty'\nconst SET_STATE_PROPERTY = 'SET_STATE_PROPERTY';\n\n// Update the state property named 'stateProperty'\nconst UPDATE_STATE_PROPERTY = 'UPDATE_STATE_PROPERTY';\n\n// Remove state property named 'stateProperty'\nconst REMOVE_STATE_PROPERTY = 'REMOVE_STATE_PROPERTY';\n```\n\n## Installation\n```\nnpm install @codewell/automatic-action-switch\n```\n\n## Basic usage\n```JavaScript\nimport automaticActionSwitch from '@codewell/automatic-action-switch';\n\nconst actionSwitch = automaticActionSwitch();\n\nconst state = {};\nconst SET_STATE_PROPERTY = 'SET_STATE_PROPERTY';\nconst action = {type: SET_STATE_PROPERTY, payload: 'value'}\n\nconst nextState = actionSwitch(state, action);\nconsole.log(nextState);\n// =\u003e {stateProperty: 'value'}\n```\n\n### React `useReducer`\n```JavaScript\nimport { useReducer } from 'react';\nimport automaticActionSwitch from '@codewell/automatic-action-switch';\n\nconst actionSwitch = automaticActionSwitch();\n\nconst reducer = (state, action) =\u003e {\n  return actionSwitch(state, action); // Automatically updates the state\n};\n\n//...\nuseReducer(reducer); // Use where applicable\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewell%2Fautomatic-action-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewell%2Fautomatic-action-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewell%2Fautomatic-action-switch/lists"}