{"id":23452805,"url":"https://github.com/sijiecai/redux-prim","last_synced_at":"2025-08-17T18:51:22.047Z","repository":{"id":32877235,"uuid":"142160473","full_name":"SijieCai/redux-prim","owner":"SijieCai","description":"redux helper tool to abstract action and reducer with getDefaultState and updaters.","archived":false,"fork":false,"pushed_at":"2023-05-29T00:55:40.000Z","size":168,"stargazers_count":82,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-27T12:08:14.122Z","etag":null,"topics":["abstraction","contracts-programming","data-driven","react","redux","reusability"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/SijieCai.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":"2018-07-24T13:12:09.000Z","updated_at":"2023-08-10T06:42:49.000Z","dependencies_parsed_at":"2022-08-07T18:15:50.782Z","dependency_job_id":null,"html_url":"https://github.com/SijieCai/redux-prim","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/SijieCai%2Fredux-prim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SijieCai%2Fredux-prim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SijieCai%2Fredux-prim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SijieCai%2Fredux-prim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SijieCai","download_url":"https://codeload.github.com/SijieCai/redux-prim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788868,"owners_count":21161726,"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":["abstraction","contracts-programming","data-driven","react","redux","reusability"],"created_at":"2024-12-24T01:27:33.201Z","updated_at":"2025-04-13T21:44:07.538Z","avatar_url":"https://github.com/SijieCai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-prim\n\nredux-prim builds an abstract layer on top of redux, making state management as it should be:\n- The initial state: `getDefaultState`\n- State modification: `updaters` and `namespacing`\n\nThe actions and reducers are greatly weaken, while under the abstraction layer, everything stays the same:\n\n- State is a single immutable object tree.\n- *Actions* describe updates.\n- *Reducer* pure function to apply updates.\n- Redux's ecosystem\n\nThis abstraction is more in line with the human brain's understanding of the data, and supports custom *updater* to achieve code reuse. Redux-prim also provides interfaces for **data contract design**.\n\n## Install\n\n```shell\nnpm i redux-prim\n```\n\n## Simple example\n\nCreate a todo slice\n``` javascript\nimport createSlice from 'redux-prim';\n\nconst {actions, reducer, selector} = createSlice('todo',\n()=\u003e({ visible: false }),\n({ setState }) =\u003e {\n  return {\n    setTodoVisibility(todoVisible) {\n      return setState({ todoVisible });\n    }\n  }\n});\n\n```\n\ncombine reducers\n``` javascript\nimport { combineReducers } from 'redux';\nimport todoSlice from './todoSlice';\n\nexport default combineReducers({\n  ...todoSlice.reducer\n});\n```\n\nuse slice\n``` javascript\nimport React, { useCallback } from 'react'; \nimport todoSlice from './store/todoSlice';\nimport { useSelector, useDispatch } from 'react-redux';\nconst { actions, selector } = todoSlice;\n\nfunction App() {\n  const todo = useSelector(selector);\n  const dispatch = useDispatch();\n  const showTodo = useCallback(() =\u003e dispatch(actions.setTodoVisibility(true)), []); \n  return (\n    \u003cdiv\u003e\n      {todo.visible ? \u003cdiv\u003ethis is todo\u003c/div\u003e : \u003cbutton onClick={showTodo}\u003eshow todo\u003c/button\u003e}\n    \u003c/div\u003e\n  )\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsijiecai%2Fredux-prim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsijiecai%2Fredux-prim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsijiecai%2Fredux-prim/lists"}