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