1 | /*
|
2 | Copyright (c) 2019-present NAVER Corp.
|
3 | name: @egjs/children-differ
|
4 | license: MIT
|
5 | author: NAVER Corp.
|
6 | repository: https://github.com/naver/egjs-children-differ
|
7 | version: 1.0.1
|
8 | */
|
9 | import ListDiffer, { diff as diff$1 } from '@egjs/list-differ';
|
10 |
|
11 | /*! *****************************************************************************
|
12 | Copyright (c) Microsoft Corporation. All rights reserved.
|
13 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
14 | this file except in compliance with the License. You may obtain a copy of the
|
15 | License at http://www.apache.org/licenses/LICENSE-2.0
|
16 |
|
17 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
18 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
19 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
20 | MERCHANTABLITY OR NON-INFRINGEMENT.
|
21 |
|
22 | See the Apache Version 2.0 License for specific language governing permissions
|
23 | and limitations under the License.
|
24 | ***************************************************************************** */
|
25 |
|
26 | /* global Reflect, Promise */
|
27 | var extendStatics = function (d, b) {
|
28 | extendStatics = Object.setPrototypeOf || {
|
29 | __proto__: []
|
30 | } instanceof Array && function (d, b) {
|
31 | d.__proto__ = b;
|
32 | } || function (d, b) {
|
33 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
34 | };
|
35 |
|
36 | return extendStatics(d, b);
|
37 | };
|
38 |
|
39 | function __extends(d, b) {
|
40 | extendStatics(d, b);
|
41 |
|
42 | function __() {
|
43 | this.constructor = d;
|
44 | }
|
45 |
|
46 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
47 | }
|
48 |
|
49 | /*
|
50 | egjs-children-differ
|
51 | Copyright (c) 2019-present NAVER Corp.
|
52 | MIT license
|
53 | */
|
54 | var findKeyCallback = typeof Map === "function" ? undefined : function () {
|
55 | var childrenCount = 0;
|
56 | return function (el) {
|
57 | return el.__DIFF_KEY__ || (el.__DIFF_KEY__ = ++childrenCount);
|
58 | };
|
59 | }();
|
60 |
|
61 | /**
|
62 | * A module that checks diff when child are added, removed, or changed .
|
63 | * @ko 자식 노드들에서 자식 노드가 추가되거나 삭제되거나 순서가 변경된 사항을 체크하는 모듈입니다.
|
64 | * @memberof eg
|
65 | * @extends eg.ListDiffer
|
66 | */
|
67 |
|
68 | var ChildrenDiffer =
|
69 | /*#__PURE__*/
|
70 | function (_super) {
|
71 | __extends(ChildrenDiffer, _super);
|
72 | /**
|
73 | * @param - Initializing Children <ko> 초기 설정할 자식 노드들</ko>
|
74 | */
|
75 |
|
76 |
|
77 | function ChildrenDiffer(list) {
|
78 | if (list === void 0) {
|
79 | list = [];
|
80 | }
|
81 |
|
82 | return _super.call(this, list, findKeyCallback) || this;
|
83 | }
|
84 |
|
85 | return ChildrenDiffer;
|
86 | }(ListDiffer);
|
87 |
|
88 | /*
|
89 | egjs-children-differ
|
90 | Copyright (c) 2019-present NAVER Corp.
|
91 | MIT license
|
92 | */
|
93 | /**
|
94 | *
|
95 | * @memberof eg.ChildrenDiffer
|
96 | * @static
|
97 | * @function
|
98 | * @param - Previous List <ko> 이전 목록 </ko>
|
99 | * @param - List to Update <ko> 업데이트 할 목록 </ko>
|
100 | * @return - Returns the diff between `prevList` and `list` <ko> `prevList`와 `list`의 다른 점을 반환한다.</ko>
|
101 | * @example
|
102 | * import { diff } from "@egjs/children-differ";
|
103 | * // script => eg.ChildrenDiffer.diff
|
104 | * const result = diff([0, 1, 2, 3, 4, 5], [7, 8, 0, 4, 3, 6, 2, 1]);
|
105 | * // List before update
|
106 | * // [1, 2, 3, 4, 5]
|
107 | * console.log(result.prevList);
|
108 | * // Updated list
|
109 | * // [4, 3, 6, 2, 1]
|
110 | * console.log(result.list);
|
111 | * // Index array of values added to `list`
|
112 | * // [0, 1, 5]
|
113 | * console.log(result.added);
|
114 | * // Index array of values removed in `prevList`
|
115 | * // [5]
|
116 | * console.log(result.removed);
|
117 | * // An array of index pairs of `prevList` and `list` with different indexes from `prevList` and `list`
|
118 | * // [[0, 2], [4, 3], [3, 4], [2, 6], [1, 7]]
|
119 | * console.log(result.changed);
|
120 | * // The subset of `changed` and an array of index pairs that moved data directly. Indicate an array of absolute index pairs of `ordered`.(Formatted by: Array<[index of prevList, index of list]>)
|
121 | * // [[4, 3], [3, 4], [2, 6]]
|
122 | * console.log(result.pureChanged);
|
123 | * // An array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array<[prevIndex, nextIndex]>)
|
124 | * // [[4, 1], [4, 2], [4, 3]]
|
125 | * console.log(result.ordered);
|
126 | * // An array of index pairs of `prevList` and `list` that have not been added/removed so data is preserved
|
127 | * // [[0, 2], [4, 3], [3, 4], [2, 6], [1, 7]]
|
128 | * console.log(result.maintained);
|
129 | */
|
130 |
|
131 | function diff(prevList, list) {
|
132 | return diff$1(prevList, list, findKeyCallback);
|
133 | }
|
134 |
|
135 | /*
|
136 | egjs-children-differ
|
137 | Copyright (c) 2019-present NAVER Corp.
|
138 | MIT license
|
139 | */
|
140 |
|
141 | export default ChildrenDiffer;
|
142 | export { diff };
|
143 | //# sourceMappingURL=children-differ.esm.js.map
|