{"id":21850386,"url":"https://github.com/mutativejs/xstate-mutative","last_synced_at":"2025-06-15T12:02:40.619Z","repository":{"id":260664693,"uuid":"857469275","full_name":"mutativejs/xstate-mutative","owner":"mutativejs","description":"A faster and more flexible utilities for using Mutative with XState","archived":false,"fork":false,"pushed_at":"2025-05-22T16:28:08.000Z","size":357,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-22T16:29:57.305Z","etag":null,"topics":["fsm","immutability","mutative","state-machine","xstate"],"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/mutativejs.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-14T18:35:21.000Z","updated_at":"2025-05-22T16:27:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"dfbaad60-d104-414b-b828-811ef1aadc4f","html_url":"https://github.com/mutativejs/xstate-mutative","commit_stats":null,"previous_names":["mutativejs/xstate-mutative"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mutativejs/xstate-mutative","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fxstate-mutative","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fxstate-mutative/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fxstate-mutative/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fxstate-mutative/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mutativejs","download_url":"https://codeload.github.com/mutativejs/xstate-mutative/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fxstate-mutative/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259971263,"owners_count":22940003,"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":["fsm","immutability","mutative","state-machine","xstate"],"created_at":"2024-11-28T00:17:18.499Z","updated_at":"2025-06-15T12:02:40.361Z","avatar_url":"https://github.com/mutativejs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xstate-mutative\n\n![Node CI](https://github.com/mutativejs/xstate-mutative/workflows/Node%20CI/badge.svg)\n[![npm](https://img.shields.io/npm/v/xstate-mutative.svg)](https://www.npmjs.com/package/xstate-mutative)\n![license](https://img.shields.io/npm/l/xstate-mutative)\n\nA faster and more flexible utilities for using [Mutative](https://github.com/unadlib/mutative) with XState\n\n`xstate-mutative` is more than 10x faster than `@xstate/immer`. [Read more about the performance comparison in Mutative](https://mutative.js.org/docs/getting-started/performance).\n\n## Installation\n\nIn order to use the Mutative utilities in XState, you will need to install Mutative and XState as a direct dependency.\n\n```bash\nnpm install xstate mutative xstate-mutative\n# Or use any package manager of your choice.\n```\n\n## Usage\n\nImport the Mutative utilities:\n\n```js\nimport { createMachine, interpret } from 'xstate';\nimport { assign, createUpdater } from 'xstate-mutative';\n\nconst levelUpdater = createUpdater('UPDATE_LEVEL', (ctx, { input }) =\u003e {\n  ctx.level = input;\n});\n\nconst toggleMachine = createMachine({\n  id: 'toggle',\n  context: {\n    count: 0,\n    level: 0,\n  },\n  initial: 'inactive',\n  states: {\n    inactive: {\n      on: {\n        TOGGLE: {\n          target: 'active',\n          // Immutably update context the same \"mutable\"\n          // way as you would do with Mutative!\n          actions: assign((ctx) =\u003e ctx.count++),\n        },\n      },\n    },\n    active: {\n      on: {\n        TOGGLE: {\n          target: 'inactive',\n        },\n        // Use the updater for more convenience:\n        [levelUpdater.type]: {\n          actions: levelUpdater.action,\n        },\n      },\n    },\n  },\n});\n\nconst toggleService = interpret(toggleMachine)\n  .onTransition((state) =\u003e {\n    console.log(state.context);\n  })\n  .start();\n\ntoggleService.send({ type: 'TOGGLE' });\n// { count: 1, level: 0 }\n\ntoggleService.send(levelUpdater.update(9));\n// { count: 1, level: 9 }\n\ntoggleService.send({ type: 'TOGGLE' });\n// { count: 2, level: 9 }\n\ntoggleService.send(levelUpdater.update(-100));\n// Notice how the level is not updated in 'inactive' state:\n// { count: 2, level: 9 }\n```\n\n### Mutative Options\n\n- [Strict mode](https://mutative.js.org/docs/advanced-guides/strict-mode)\n- [Auto Freeze](https://mutative.js.org/docs/advanced-guides/auto-freeze)\n- [Marking data structure](https://mutative.js.org/docs/advanced-guides/mark)\n\n## Credits\n\n`xstate-mutative` is inspired by `@xstate/immer`.\n\nIt uses the same API as `@xstate/immer` but uses Mutative under the hood. The repository is based on the `@xstate/immer` repository.\n\n## License\n\n`xstate-mutative` is [MIT licensed](https://github.com/mutativejs/xstate-mutative/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutativejs%2Fxstate-mutative","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmutativejs%2Fxstate-mutative","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutativejs%2Fxstate-mutative/lists"}