{"id":23738096,"url":"https://github.com/cjies/redux-duck-immer","last_synced_at":"2025-09-04T13:32:21.778Z","repository":{"id":32447209,"uuid":"133964337","full_name":"cjies/redux-duck-immer","owner":"cjies","description":"Helpers to adapt ducks-modular-redux proposal","archived":false,"fork":false,"pushed_at":"2023-01-06T01:47:20.000Z","size":1086,"stargazers_count":8,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-21T13:40:54.931Z","etag":null,"topics":["immer","redux","redux-duck"],"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/cjies.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-05-18T14:21:19.000Z","updated_at":"2021-05-31T01:44:42.000Z","dependencies_parsed_at":"2023-01-14T21:15:27.844Z","dependency_job_id":null,"html_url":"https://github.com/cjies/redux-duck-immer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjies%2Fredux-duck-immer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjies%2Fredux-duck-immer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjies%2Fredux-duck-immer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjies%2Fredux-duck-immer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cjies","download_url":"https://codeload.github.com/cjies/redux-duck-immer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231965415,"owners_count":18453071,"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":["immer","redux","redux-duck"],"created_at":"2024-12-31T08:52:49.212Z","updated_at":"2024-12-31T08:52:49.879Z","avatar_url":"https://github.com/cjies.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-duck-immer\n\n[![NPM version](https://img.shields.io/npm/v/redux-duck-immer.svg?style=flat-square)](https://www.npmjs.com/package/redux-duck-immer)\n[![Build status](https://img.shields.io/travis/cjies/redux-duck-immer.svg?style=flat-square)](https://travis-ci.org/cjies/redux-duck-immer)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\nInspired by [redux-duck](https://github.com/PlatziDev/redux-duck).\n\nProviding redux helpers to implement [ducks-modular-redux](https://github.com/erikras/ducks-modular-redux/) proposal.\nAnd the reducer's state is produced by [Immer](https://github.com/mweststrate/immer) for immutability.\n\n## Installation\n\n```bash\nyarn add redux-duck-immer\n```\n\n## API\n\n### Define action types\n\n```javascript\nimport { defineType } from 'redux-duck-immer';\n\n/**\n * type ActionType = string;\n *\n * (...actionTypes: string[]): ActionType;\n */\nconst UPDATE = defineType('UPDATE');\nconst PREFIXED_UPDATE = defineType('prefix', 'UPDATE'); // 'prefix/UPDATE'\n```\n\n- `defineType` method receive one or many arguments.\n- If multiple arguments are provided, its result should be a string like `prefix/UPDATE`.\n\n### Create action creator\n\n```javascript\nimport { createAction } from 'redux-duck-immer';\n\n/**\n * interface Action\u003cP\u003e {\n *   type: ActionType;\n *   payload?: P;\n * }\n *\n * (actionType: ActionType): \u003cP\u003e(payload?: P) =\u003e Action\u003cP\u003e;\n */\nconst update = createAction(UPDATE);\n\n// Dispatch action\ndispatch(update('hello world!'));\n```\n\n- `createAction` method receive just one argument.\n- This argument should be the defined action type string.\n- It should return a function who will receive the action payload and return a valid (FSA compilant) action object.\n- The action creator will receive an optional argument with the action payload.\n\n### Create reducer\n\n```javascript\nimport { createReducer } from 'redux-duck-immer';\n\nconst initialState = {\n  message: '',\n};\n\n/**\n * interface ActionCases\u003cS, P\u003e {\n *   [actionType: ActionType]: (state: S, action: Action\u003cP\u003e) =\u003e void | S;\n * }\n *\n * \u003cS, P: any\u003e(initState: any, cases: ActionCases\u003cS, P\u003e): (state: S, action: Action\u003cP\u003e) =\u003e S;\n */\nconst reducer = createReducer(initState, {\n  [UPDATE]: (state, action) =\u003e ({\n    state.message = action.payload\n  }),\n});\n```\n\n- `createReducer` method receive two arguments, both required.\n- The first argument is the reducer initial state.\n- The second argument is an object with the possible action cases, should use the previously defined _action types_ as keys.\n- Each key in the action cases should be a function who will receive the current state and the dispatched action as arguments.\n- Reducer state is immutable which protected by [Immer](https://github.com/mweststrate/immer). In each action case, Immer will produce the nextState based on the mutations to the draft state.\n\n## License\n\nCheck [LICENSE](/LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjies%2Fredux-duck-immer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcjies%2Fredux-duck-immer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjies%2Fredux-duck-immer/lists"}