{"id":19736514,"url":"https://github.com/soc221b/vue-ditto","last_synced_at":"2025-08-14T11:38:15.242Z","repository":{"id":37802190,"uuid":"415579973","full_name":"soc221b/vue-ditto","owner":"soc221b","description":"[WIP] Vue-ditto will create a Ditto ref for the original ref, you can add any metadata to it, even if the original ref changes, these metadata will be retained.","archived":true,"fork":false,"pushed_at":"2024-09-10T13:49:36.000Z","size":339,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T19:02:00.066Z","etag":null,"topics":["clone","detto","ditto","mirror","ref","vue"],"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/soc221b.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-10-10T12:30:39.000Z","updated_at":"2025-01-18T12:17:33.000Z","dependencies_parsed_at":"2024-05-13T06:25:55.630Z","dependency_job_id":"633fe9ec-6802-4e91-97d9-4e57148c247e","html_url":"https://github.com/soc221b/vue-ditto","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":0.375,"last_synced_commit":"d1b552034ef0c87ef45de078d29b0490dd1baefc"},"previous_names":["soc221b/vue-ditto","iendeavor/vue-ditto"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fvue-ditto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fvue-ditto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fvue-ditto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fvue-ditto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soc221b","download_url":"https://codeload.github.com/soc221b/vue-ditto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251643124,"owners_count":21620428,"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":["clone","detto","ditto","mirror","ref","vue"],"created_at":"2024-11-12T01:07:22.303Z","updated_at":"2025-04-30T04:32:05.900Z","avatar_url":"https://github.com/soc221b.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-ditto\n\n![Ditto Pokemon](./ditto.svg)\n\n**Vue-ditto** will create a _Ditto ref_ for the _original ref_, you can add any metadata to it, even if the _original ref_ changes, these metadata will be retained.\n\n[![npm version](https://badge.fury.io/js/vue-ditto.svg)](https://badge.fury.io/js/vue-ditto)\n[![CI](https://github.com/iendeavor/vue-ditto/workflows/CI/badge.svg)](https://github.com/iendeavor/vue-ditto/actions)\n[![Coverage Status](https://coveralls.io/repos/github/iendeavor/vue-ditto/badge.svg?branch=develop)](https://coveralls.io/github/iendeavor/vue-ditto?branch=develop)\n[![gzip](https://badgen.net/bundlephobia/minzip/vue-ditto)](https://bundlephobia.com/result?p=vue-ditto)\n\n## Features\n\n- Support primitive, plain object, and array types\n- Support the complete operation method of array, namely `push`, `pop`, `unshift`, `shift`, `reverse`, `sort`, `lookup set`, `delete`, `length` and sparse array are all supported.\n\n## Getting Started\n\n\u003e It works for Vue 2 \u0026 3 by the power of [Vue Demi](https://github.com/vueuse/vue-demi)!\n\n### Installation\n\n#### NPM\n\n```shell\n$ npm i vue-ditto # yarn add vue-ditto\n```\n\n```ts\nimport { dittoRef } from \"vue-ditto\";\n```\n\n#### CDN\n\n```html\n\u003cscript src=\"https://unpkg.com/vue-ditto\"\u003e\u003c/script\u003e\n```\n\n```ts\nconst dittoRef = VueDitto.dittoRef;\n```\n\n### Usage\n\nTo create a Ditto, you just need to pass ref to `dittoRef`:\n\n```ts\nconst original = ref(\"foo\");\nconsole.log(dittoRef({ original }).value);\n// {}\n```\n\nIt also works with nesting plain objects and arrays:\n\n```ts\nconst original = ref({ foo: 42 });\nconsole.log(dittoRef({ original }).value);\n// { foo: {} }\n```\n\nFor arrays, each item must be a plain object, and the object must contain a unique `id` property to hint **Vue-ditto** to diff the new item against the old item.\n\n```ts\nconst original = ref([{ id: 0, foo: 42 }]);\nconsole.log(dittoRef({ original }).value);\n// [ { id: {}, foo: {} } ]\n```\n\nThere are several callbacks that can be used to track creation and updates:\n\n```ts\nconst original = ref({ foo: 42 });\nconst ditto = dittoRef({\n  original,\n  onCreated: ({ ditto, path, original }) =\u003e {\n    console.log(`${[\"$\"].concat(path as string[]).join(\".\")} is created`);\n    // $ is created\n    // $.foo is created\n  },\n});\n```\n\nYou can add any metadata for each Ditto in these callbacks, and you must also provide `metaKeys` to preserve these metadata during the operation.\n\n```ts\nconst original = ref({ foo: 42 });\nconst ditto = dittoRef({\n  original,\n  metaKeys: [\"$original\"],\n  onCreated: ({ ditto, path, original }) =\u003e {\n    ditto.$original = original.value;\n  },\n});\n\nconsole.log(ditto.value);\n// { '$original': { foo: 42 }, foo: { '$original': 42 } }\n```\n\nThis also applies to the array itself:\n\n```ts\nconst original = ref([\n  { id: 1, value: \"foo\" },\n  { id: 2, value: \"bar\" },\n]);\nconst ditto = dittoRef({\n  original,\n  metaKeys: [\"$original\"],\n  onCreated: ({ ditto, path, original }) =\u003e {\n    ditto.$original = original.value;\n  },\n});\n\nconsole.log(ditto.value);\n/*\n  [\n    {\n      '$original': { id: 1, value: 'foo' },\n      id: { '$original': 1 },\n      value: { '$original': 'foo' }\n    },\n    {\n      '$original': { id: 2, value: 'bar' },\n      id: { '$original': 2 },\n      value: { '$original': 'bar' }\n    },\n    '$original': [ { id: 1, value: 'foo' }, { id: 2, value: 'bar' } ]\n  ]\n*/\n```\n\nWhen the original ref changes, the corresponding callback will be called, which gives you the opportunity to update the metadata:\n\n```ts\nconst original = ref\u003c{ foo: number }\u003e({ foo: 42 });\nconst ditto = dittoRef({\n  original,\n  metaKeys: [\"$updateCount\"],\n  flush: \"sync\",\n  onCreated: ({ ditto, path, original }) =\u003e {\n    ditto.$updateCount = 0;\n  },\n  onUpdated: ({ ditto, path, original }) =\u003e {\n    ditto.$updateCount++;\n  },\n});\n\nconsole.log(ditto.value);\n// { '$updateCount': 0, foo: { '$updateCount': 0 } }\n\noriginal.value.foo++;\nconsole.log(ditto.value);\n// { '$updateCount': 0, foo: { '$updateCount': 1 } }\n```\n\nFor TypeScript, you must extend the type for the Ditto interface:\n\n```ts\ndeclare module \"vue-ditto\" {\n  interface DittoMeta\u003cT\u003e {\n    $original: T;\n    $updateCount: number;\n  }\n}\n```\n\n## API Reference\n\n```ts\nfunction dittoRef\u003cT\u003e({\n  original,\n  metaKeys,\n  flush,\n  onCreated,\n  onChildrenCreated,\n  onUpdated,\n  onChildrenUpdated,\n}: {\n  original: Ref\u003cT\u003e;\n  metaKeys?: Key[];\n  flush?: WatchOptions[\"flush\"];\n  onCreated?: DittoCallback;\n  onChildrenCreated?: DittoCallback;\n  onUpdated?: DittoCallback;\n  onChildrenUpdated?: DittoCallback;\n}): Ref\u003cDitto\u003cT\u003e\u003e;\n\ntype Ditto\u003cT\u003e = T extends any[]\n  ? Ditto\u003cT[number]\u003e[] \u0026 DittoMeta\u003cT\u003e\n  : T extends object\n  ? {\n      [P in keyof T]: Ditto\u003cT[P]\u003e;\n    } \u0026 DittoMeta\u003cT\u003e\n  : DittoMeta\u003cT\u003e;\n\ninterface DittoMeta\u003cT\u003e {}\n\ntype DittoCallback = \u003cT\u003e({\n  ditto,\n  path,\n  original,\n}: {\n  ditto: Ditto\u003cT\u003e;\n  path: Path;\n  original: Ref\u003cany\u003e;\n}) =\u003e void;\n\ntype Path = Key[];\n\ntype Key = string | number | symbol;\n```\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull\nrequests to us.\n\n## Versioning\n\nThis project use [SemVer](https://semver.org/) for versioning. For the versions available, see the tags on this repository.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoc221b%2Fvue-ditto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoc221b%2Fvue-ditto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoc221b%2Fvue-ditto/lists"}