@akanjs/base 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/src/base.js +14 -3
- package/esm/src/base.js +14 -3
- package/package.json +1 -1
package/cjs/src/base.js
CHANGED
|
@@ -78,8 +78,17 @@ class DataList {
|
|
|
78
78
|
length;
|
|
79
79
|
values;
|
|
80
80
|
constructor(data = []) {
|
|
81
|
-
|
|
82
|
-
this
|
|
81
|
+
const values = Array.isArray(data) ? data : data.values;
|
|
82
|
+
this.values = [];
|
|
83
|
+
this.#idMap = /* @__PURE__ */ new Map();
|
|
84
|
+
values.forEach((value) => {
|
|
85
|
+
const idx = this.#idMap.get(value.id);
|
|
86
|
+
if (idx === void 0) {
|
|
87
|
+
this.#idMap.set(value.id, this.values.length);
|
|
88
|
+
this.values.push(value);
|
|
89
|
+
} else
|
|
90
|
+
this.values[idx] = value;
|
|
91
|
+
});
|
|
83
92
|
this.length = this.values.length;
|
|
84
93
|
}
|
|
85
94
|
indexOf(id) {
|
|
@@ -105,7 +114,9 @@ class DataList {
|
|
|
105
114
|
return this;
|
|
106
115
|
this.#idMap.delete(id);
|
|
107
116
|
this.values.splice(idx, 1);
|
|
108
|
-
this.values.slice(idx).forEach((value, i) =>
|
|
117
|
+
this.values.slice(idx).forEach((value, i) => {
|
|
118
|
+
this.#idMap.set(value.id, i + idx);
|
|
119
|
+
});
|
|
109
120
|
this.length--;
|
|
110
121
|
return this;
|
|
111
122
|
}
|
package/esm/src/base.js
CHANGED
|
@@ -53,8 +53,17 @@ class DataList {
|
|
|
53
53
|
length;
|
|
54
54
|
values;
|
|
55
55
|
constructor(data = []) {
|
|
56
|
-
|
|
57
|
-
this
|
|
56
|
+
const values = Array.isArray(data) ? data : data.values;
|
|
57
|
+
this.values = [];
|
|
58
|
+
this.#idMap = /* @__PURE__ */ new Map();
|
|
59
|
+
values.forEach((value) => {
|
|
60
|
+
const idx = this.#idMap.get(value.id);
|
|
61
|
+
if (idx === void 0) {
|
|
62
|
+
this.#idMap.set(value.id, this.values.length);
|
|
63
|
+
this.values.push(value);
|
|
64
|
+
} else
|
|
65
|
+
this.values[idx] = value;
|
|
66
|
+
});
|
|
58
67
|
this.length = this.values.length;
|
|
59
68
|
}
|
|
60
69
|
indexOf(id) {
|
|
@@ -80,7 +89,9 @@ class DataList {
|
|
|
80
89
|
return this;
|
|
81
90
|
this.#idMap.delete(id);
|
|
82
91
|
this.values.splice(idx, 1);
|
|
83
|
-
this.values.slice(idx).forEach((value, i) =>
|
|
92
|
+
this.values.slice(idx).forEach((value, i) => {
|
|
93
|
+
this.#idMap.set(value.id, i + idx);
|
|
94
|
+
});
|
|
84
95
|
this.length--;
|
|
85
96
|
return this;
|
|
86
97
|
}
|