{"id":21850399,"url":"https://github.com/mutativejs/mutability","last_synced_at":"2025-08-21T20:32:57.758Z","repository":{"id":224085019,"uuid":"762369303","full_name":"mutativejs/mutability","owner":"mutativejs","description":"A JavaScript library for transactional mutable updates","archived":false,"fork":false,"pushed_at":"2024-11-23T17:22:36.000Z","size":645,"stargazers_count":37,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-11T05:51:33.878Z","etag":null,"topics":["immutability","mutative","transactional"],"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}},"created_at":"2024-02-23T16:29:15.000Z","updated_at":"2024-11-23T17:22:40.000Z","dependencies_parsed_at":"2024-03-09T02:24:05.324Z","dependency_job_id":"8a839c40-dea0-4bcb-a397-9ff304724648","html_url":"https://github.com/mutativejs/mutability","commit_stats":null,"previous_names":["unadlib/mutability","mutativejs/mutability"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fmutability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fmutability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fmutability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutativejs%2Fmutability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mutativejs","download_url":"https://codeload.github.com/mutativejs/mutability/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230532448,"owners_count":18240792,"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":["immutability","mutative","transactional"],"created_at":"2024-11-28T00:17:21.878Z","updated_at":"2024-12-20T04:07:55.026Z","avatar_url":"https://github.com/mutativejs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mutability\n\n![Node CI](https://github.com/mutativejs/mutability/workflows/Node%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/mutability.svg)](http://badge.fury.io/js/mutability)\n![license](https://img.shields.io/npm/l/mutability)\n\nA JavaScript library for transactional mutable updates based on [Mutative](https://github.com/unadlib/mutative).\n\n## Motivation\n\nWhen we want to perform transactional updates on a mutable object, if an error is caught during the update process, the mutable update will not be applied at all. Otherwise, the mutable update will be applied to the mutable object. Therefore, we need a tool to implement this functionality.\n\n## Installation\n\n```sh\nyarn add mutative mutability\n```\n\nor with npm\n\n```sh\nnpm install mutative mutability\n```\n\n## Usage\n\n```ts\nimport { mutate } from 'mutability';\n\ntest('base - mutate', () =\u003e {\n  const baseState = {\n    a: {\n      c: 1,\n    },\n  };\n  const { patches, inversePatches } = mutate(baseState, (draft) =\u003e {\n    draft.a.c = 2;\n  });\n  expect(baseState).toEqual({ a: { c: 2 } });\n  expect({ patches, inversePatches }).toEqual({\n    patches: [\n      {\n        op: 'replace',\n        path: ['a', 'c'],\n        value: 2,\n      },\n    ],\n    inversePatches: [\n      {\n        op: 'replace',\n        path: ['a', 'c'],\n        value: 1,\n      },\n    ],\n  });\n  apply(baseState, inversePatches);\n  expect(baseState).toEqual({ a: { c: 1 } });\n});\n\ntest('base - mutate with error', () =\u003e {\n  const baseState = {\n    a: {\n      c: 1,\n    },\n    b: {\n      c: 1,\n    },\n  };\n  try {\n    mutate(baseState, (draft) =\u003e {\n      draft.a.c = 2;\n      throw new Error('error');\n      draft.b.c = 2;\n    });\n  } catch (e) {\n    //\n  }\n  expect(baseState).toEqual({\n    a: {\n      c: 1,\n    },\n    b: {\n      c: 1,\n    },\n  });\n});\n```\n\n## APIs\n\n### `mutate()`\nMutate the mutable object, and return the patches and inverse patches.\n\n### `apply()`\nApply the mutable update with patches.\n\n## License\n\nMutability is [MIT licensed](https://github.com/mutativejs/mutability/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutativejs%2Fmutability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmutativejs%2Fmutability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutativejs%2Fmutability/lists"}