{"id":13455592,"url":"https://github.com/naver/egjs-list-differ","last_synced_at":"2025-03-24T08:33:13.017Z","repository":{"id":40939534,"uuid":"194217606","full_name":"naver/egjs-list-differ","owner":"naver","description":"➕➖🔄 A module that checks the diff when values are added, removed, or changed in an array.","archived":true,"fork":false,"pushed_at":"2023-01-04T06:18:15.000Z","size":3597,"stargazers_count":63,"open_issues_count":8,"forks_count":3,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-09T10:33:41.849Z","etag":null,"topics":["added","changed","diff","differ","ordered","purechanged","removed"],"latest_commit_sha":null,"homepage":"https://naver.github.io/egjs-list-differ","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/naver.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-06-28T06:15:22.000Z","updated_at":"2024-08-01T06:40:15.000Z","dependencies_parsed_at":"2023-02-02T01:02:15.558Z","dependency_job_id":null,"html_url":"https://github.com/naver/egjs-list-differ","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-list-differ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-list-differ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-list-differ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-list-differ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naver","download_url":"https://codeload.github.com/naver/egjs-list-differ/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245235685,"owners_count":20582287,"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":["added","changed","diff","differ","ordered","purechanged","removed"],"created_at":"2024-07-31T08:01:07.796Z","updated_at":"2025-03-24T08:33:12.492Z","avatar_url":"https://github.com/naver.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\n\u003cp align=\"middle\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/naver/egjs-list-differ/master/demo/images/logo.png\"/\u003e\u003c/p\u003e\n\u003ch2 align=\"middle\"\u003e@egjs/list-differ\u003c/h2\u003e\n\u003cp align=\"middle\"\u003e\u003ca href=\"https://www.npmjs.com/package/@egjs/list-differ\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@egjs/list-differ.svg?style=flat-square\u0026color=007acc\u0026label=version\u0026logo=NPM\" alt=\"version\" /\u003e\u003c/a\u003e \u003ca href=\"https://travis-ci.org/naver/egjs-list-differ\" target=\"_blank\"\u003e\u003cimg alt=\"Travis (.org)\" src=\"https://img.shields.io/travis/naver/egjs-list-differ.svg?style=flat-square\u0026label=build\u0026logo=travis%20ci\" /\u003e\u003c/a\u003e \u003ca href=\"https://coveralls.io/github/naver/egjs-list-differ?branch=master\u0026style=flat-square\" target=\"_blank\"\u003e\u003cimg alt=\"Coveralls github\" src=\"https://img.shields.io/coveralls/github/naver/egjs-list-differ.svg?style=flat-square\u0026label=%E2%9C%85%20coverage\"\u003e\u003c/a\u003e \u003ca href=\"https://www.npmjs.com/package/@egjs/list-differ\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@egjs/list-differ.svg?style=flat-square\u0026label=%E2%AC%87%20downloads\u0026color=08CE5D\" alt=\"npm downloads per month\"\u003e\u003c/a\u003e  \u003ca href=\"https://github.com/naver/egjs-list-differ/blob/master/LICENSE\" target=\"_blank\"\u003e\u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/naver/egjs-list-differ.svg?style=flat-square\u0026label=%F0%9F%93%9C%20license\u0026color=08CE5D\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\n\u003cp align=\"middle\"\u003e➕➖🔄 A module that checks the diff when values are added, removed, or changed in an array.\u003c/p\u003e\n\n\n\n## ⚙️ Installation\n\n```sh\n$ npm i @egjs/list-differ\n```\n\n```html\n\u003cscript src=\"//naver.github.io/egjs-list-differ/release/latest/dist/list-differ.min.js\"\u003e\u003c/script\u003e\n```\n\n## 📖 Documentation\n* See [**Documentation**](https://naver.github.io/egjs-list-differ/release/latest/doc/index.html) page.\n* [Introducing ListDiffer to track changes in data and track changes](https://medium.com/naver-fe-platform/introducing-listdiffer-to-track-changes-in-data-27793f0c6f4a)([한국어](https://medium.com/naver-fe-platform/%EB%8D%B0%EC%9D%B4%ED%84%B0%EC%9D%98-%EB%B3%80%ED%99%94%EB%A5%BC-%EC%95%8C%EC%95%84%EB%82%B4%EA%B3%A0-%EB%B3%80%ED%99%94-%EA%B3%BC%EC%A0%95%EC%9D%84-%EC%B6%94%EC%A0%81-%ED%95%98%EB%8A%94-listdiffer-9c3f1d770542))\n* [How to Make Cross Framework Component](https://medium.com/naver-fe-platform/how-to-make-cross-framework-component-ee76d76708b1)([한국어](https://medium.com/naver-fe-platform/cross-framework-component%EB%A5%BC-%EB%A7%8C%EB%93%9C%EB%8A%94-%EB%B0%A9%EB%B2%95-234b3fece353))\n\n\n## 📦 Packages\n|Package|Version|Description|\n|:-----:|:-----:|:-----:|\n|[**@egjs/children-differ**](https://github.com/naver/egjs-children-differ)|\u003ca href=\"https://www.npmjs.com/package/@egjs/children-differ\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@egjs/children-differ.svg?style=flat-square\u0026color=007acc\u0026label=%F0%9F%94%96\" alt=\"version\" /\u003e\u003c/a\u003e|A module that checks diff in DOM children.|\n|[**@egjs/react-children-differ**](https://github.com/naver/egjs-children-differ/blob/master/packages/react-children-differ/README.md)|\u003ca href=\"https://www.npmjs.com/package/@egjs/react-children-differ\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@egjs/react-children-differ.svg?style=flat-square\u0026color=00d8ff\u0026label=%F0%9F%94%96\" alt=\"version\" /\u003e\u003c/a\u003e|\u003cimg width=\"15\" src=\"https://naver.github.io/egjs-flicking/images/react.svg\" valign=\"middle\" alt=\"React\" /\u003e [React](https://reactjs.org/) port of @egjs/children-differ|\n|[**@egjs/ngx-children-differ**](https://github.com/naver/egjs-children-differ/blob/master/packages/ngx-children-differ/README.md)|\u003ca href=\"https://www.npmjs.com/package/@egjs/ngx-children-differ\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@egjs/ngx-children-differ.svg?style=flat-square\u0026color=dd0031\u0026label=%F0%9F%94%96\" alt=\"version\" /\u003e\u003c/a\u003e|\u003cimg width=\"15\" src=\"https://naver.github.io/egjs-flicking/images/angular.svg\" valign=\"middle\" alt=\"Angular\" /\u003e [Angular](https://angular.io/) port of @egjs/children-differ|\n|[**@egjs/vue-children-differ**](https://github.com/naver/egjs-children-differ/blob/master/packages/vue-children-differ/README.md)|\u003ca href=\"https://www.npmjs.com/package/@egjs/vue-children-differ\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@egjs/vue-children-differ.svg?style=flat-square\u0026color=42b883\u0026label=%F0%9F%94%96\" alt=\"version\" /\u003e\u003c/a\u003e|\u003cimg width=\"15\" src=\"https://naver.github.io/egjs-flicking/images/vue.svg\" valign=\"middle\" alt=\"Vue.js\" /\u003e [Vue.js](https://vuejs.org/v2/guide/index.html) port of @egjs/children-differ|\n\n## 🏃 How to use\n### checks the diff in array\n```js\nimport ListDiffer, { diff } from \"@egjs/list-differ\";\n\n// script =\u003e eg.ListDiffer\n// Value is key\nconst differ = new ListDiffer([1, 2, 3, 4, 5, 6, 7], e =\u003e e);\n// const result = diff([1, 2, 3, 4, 5, 6, 7], [4, 3, 8, 2, 1, 7], e =\u003e e);\nconst result = differ.update([4, 3, 8, 2, 1, 7]);\n// List before update\n// [1, 2, 3, 4, 5, 6, 7]\nconsole.log(result.prevList);\n// Updated list\n// [4, 3, 8, 2, 1, 7]\nconsole.log(result.list);\n// Index array of values added to `list`\n// [2]\nconsole.log(result.added);\n// Index array of values removed in `prevList`\n// [5, 4]\nconsole.log(result.removed);\n// An array of index pairs of `prevList` and `list` with different indexes from `prevList` and `list`\n// [[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]]\nconsole.log(result.changed);\n// An array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array\u003c[prevIndex, nextIndex]\u003e)\n// [[0, 3], [0, 2], [0, 1]]\nconsole.log(result.ordered);\n// An array of index pairs of `prevList` and `list` that have not been added/removed so data is preserved\n// [[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]]\nconsole.log(result.maintained);\n```\n### What is changed?\n* **changed**: An array of index pairs of `prevList` and `list` with different indexes from `prevList` and `list`\n\n\n||**changed**|\n|---:|---|\n||[[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]]|[[[3, 0], [2, 1], [1, 3]]||\n|prevList|![prev_list](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/changed_prev_list.png)|\n|list|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/changed_list.png)|\n\n### What is ordered?\nAn array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array\u003c[prevIndex, nextIndex]\u003e)\n\n||removed -\u003e ordered -\u003e added|\n|---:|---|\n|prevList|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/prev_list.png)|\n|removed\u003cbr/\u003e[5, 4]|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/removed.png)|\n|ordered|[[0, 3], [0, 2], [0, 1]]|\n||![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/ordered_before_added.gif)|\n|ordered[0]\u003cbr/\u003e[3 =\u003e 0]| ![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/ordered_before_ordered0.png)|\n|ordered[1]\u003cbr/\u003e[3 =\u003e 1]| ![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/ordered_before_ordered1.png)|\n|ordered[2]\u003cbr/\u003e[3 =\u003e 2]| ![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/ordered_before_ordered2.png)|\n|added\u003cbr/\u003e[2]|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/ordered_before_added.png)|\n|list|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/list.png)|\n\n\n\n## Data Sync Examples\n```js\nimport ListDiffer, { diff } from \"@egjs/list-differ\";\n\nconst prevList = [1, 2, 3, 4, 5, 6, 7];\nconst list = [4, 3, 8, 2, 1, 7];\n// const differ = new ListDiffer(prevList, e =\u003e e);\n// const result = differ.update(list);\nconst result = diff(prevList, list, e =\u003e e);\n```\n\n### removed =\u003e ordered =\u003e added\n\n||removed =\u003e ordered =\u003e added|\n|---|---|\n|prevList|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/prev_list.png)|\n|process|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/changed_before_animation.gif)|\n|list|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/list.png)|\n\n*  Synchronize List\n```js\nconst nextList = prevList.slice();\nresult.removed.forEach(index =\u003e {\n  nextList.splice(index, 1);\n});\nresult.ordered.forEach(([from, to], i) =\u003e {\n  const element = nextList.splice(from, 1)[0];\n  nextList.splice(to, 0, element);\n});\nresult.added.forEach(index =\u003e {\n  nextList.splice(index, 0, list[index]);\n});\n// `nextList` is the same as `list`.\nconsole.log(nextList);\n```\n\n*  Synchronize DOM\n```js\nconst parentElement = document.querySelector(\".parent\");\nconst children = parentElement.children;\n\nresult.removed.forEach(index =\u003e {\n  children[index].remove();\n});\nresult.ordered.forEach(([from, to]) =\u003e {\n  parentElement.insertBefore(children[from], children[from \u003c to ? to + 1 : to]);\n});\nresult.added.forEach(index =\u003e {\n  parentElement.insertBefore(document.createElement(\"div\"), children[index]);\n});\n```\n\n### removed =\u003e maintained =\u003e added\n||maintained =\u003e added|\n|---|---|\n|prevList|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/prev_list.png)|\n|process|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/maintained_with_added.gif)|\n|list|![](https://raw.githubusercontent.com/naver/egjs-list-differ/master/images/list.png)|\n\n* Synchronize List\n```js\nconst nextList: number[] = [];\nresult.removed.forEach(index =\u003e {\n  // There is a remove operation for the index.\n  // prevList[index];\n});\nresult.maintained.forEach(([from, to]) =\u003e {\n  nextList[to] = list[to];\n});\nresult.added.forEach(index =\u003e {\n  nextList[index] = list[index];\n});\n// `nextList` is the same as `list`.\nconsole.log(nextList);\n```\n\n*  Synchronize DOM\n```js\nconst parentElement = document.querySelector(\".parent\");\nconst children = parentElement.children;\nconst prevChildren: Element[] = [].slice.call(parentElement.children);\n\nresult.removed.forEach(index =\u003e {\n  prevChildren[index].remove();\n});\nresult.maintained.forEach(([from, to]) =\u003e {\n  parentElement.appendChild(prevChildren[from]);\n});\nresult.added.forEach(index =\u003e {\n  parentElement.insertBefore(document.createElement(\"div\"), children[index]);\n});\n```\n\n\n## 🙌 Contributing\nSee [CONTRIBUTING.md](https://github.com/naver/egjs-list-differ/blob/master/CONTRIBUTING.md).\n\n## 📝 Feedback\nPlease file an [Issue](https://github.com/naver/egjs-list-differ/issues).\n\n## 📜 License\n@egjs/list-differ is released under the [MIT license](https://github.com/naver/egjs-list-differ/blob/master/LICENSE).\n\n```\nCopyright (c) 2019-present NAVER Corp.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaver%2Fegjs-list-differ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaver%2Fegjs-list-differ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaver%2Fegjs-list-differ/lists"}