{"id":15506242,"url":"https://github.com/fi3ework/histor","last_synced_at":"2026-05-17T05:35:20.803Z","repository":{"id":57264374,"uuid":"171018940","full_name":"fi3ework/histor","owner":"fi3ework","description":"💾 Save the history mutation of state.","archived":false,"fork":false,"pushed_at":"2019-02-17T09:07:47.000Z","size":123,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T19:58:21.112Z","etag":null,"topics":[],"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/fi3ework.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-02-16T15:31:38.000Z","updated_at":"2019-08-01T08:21:22.000Z","dependencies_parsed_at":"2022-08-25T02:52:04.335Z","dependency_job_id":null,"html_url":"https://github.com/fi3ework/histor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fi3ework%2Fhistor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fi3ework%2Fhistor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fi3ework%2Fhistor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fi3ework%2Fhistor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fi3ework","download_url":"https://codeload.github.com/fi3ework/histor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240721882,"owners_count":19847015,"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":"2024-10-02T09:26:25.665Z","updated_at":"2026-05-17T05:35:15.783Z","avatar_url":"https://github.com/fi3ework.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# histor\n\nhistor is a enhancer to watch the deep change of an object and tell the detail of the change.\n\n## Install\n\n```bash\n$ yarn add histor\n```\n\nor\n\n```bash\n$ npm i histor\n```\n\n## Usage\n\n### histor(object, onChange)\n\nAccept an object and a `onChange` callback function. The callback function will be called if any part of the object is changed.\n\nThe `onChange` callback will receive a change detail whose type is:\n\n```ts\ninterface IDiff {\n  path: (string | number)[] // the path chain of the changed key\n  from: any // previous value before change of the prop\n  to: any // current value after change of the prop\n}\n```\n\nExample:\n\n```ts\nimport histor from 'histor'\n\nconst person = {\n  name: 'wee',\n  skills: ['eat', 'sleep'],\n  pets: {\n    cat: {\n      name: 'c1'\n    },\n    dog: 'd1'\n  }\n}\n\nconst p = histor(person, diff =\u003e {\n  console.log(`$${diff.path.map(p =\u003e `[${p}]`).join('')}: ${diff.from} ==\u003e ${diff.to}`)\n})\n\nperson.pets.cat.name = 'c2'\n// it will log:\n// `$[pets][cat][name]: c1 ==\u003e c2`\n```\n\n## ⚠️ CAVEAT\n\n- The change diff will just keep a reference to the changed value. So if the new value or the new value has been changed deeply afterward. The previous diff will be changed at the same time. So it's better to serialize the diff to make it immutable.\n\n## Thanks\n\nInspired by [on-change](https://github.com/sindresorhus/on-change).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffi3ework%2Fhistor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffi3ework%2Fhistor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffi3ework%2Fhistor/lists"}