@esportsplus/reactivity 0.13.2 → 0.14.0
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/build/reactive/array.js +4 -20
- package/package.json +1 -1
- package/src/reactive/array.ts +4 -33
package/build/reactive/array.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import { isNumber } from '@esportsplus/utilities';
|
|
2
2
|
import { REACTIVE_ARRAY } from '../constants.js';
|
|
3
|
-
import { dispose as d, isComputed, read } from '../system.js';
|
|
4
3
|
import { isReactiveObject } from './object.js';
|
|
5
|
-
function at(data, i) {
|
|
6
|
-
let value = data[i];
|
|
7
|
-
if (isComputed(value)) {
|
|
8
|
-
return read(value);
|
|
9
|
-
}
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
4
|
function cleanup(item) {
|
|
13
5
|
if (isReactiveObject(item)) {
|
|
14
6
|
item.dispose();
|
|
15
7
|
}
|
|
16
|
-
else if (isComputed(item)) {
|
|
17
|
-
d(item);
|
|
18
|
-
}
|
|
19
8
|
}
|
|
20
9
|
function clear(data, listeners) {
|
|
21
10
|
dispose(data);
|
|
@@ -58,8 +47,7 @@ function map(data, proxy, fn, i, n) {
|
|
|
58
47
|
n = Math.min(n, data.length);
|
|
59
48
|
let values = new Array(n - i);
|
|
60
49
|
for (; i < n; i++) {
|
|
61
|
-
|
|
62
|
-
values[i] = fn.call(proxy, (isComputed(item) ? item.value : item), i);
|
|
50
|
+
values[i] = fn.call(proxy, data[i], i);
|
|
63
51
|
}
|
|
64
52
|
return values;
|
|
65
53
|
}
|
|
@@ -112,7 +100,7 @@ function shift(data, listeners) {
|
|
|
112
100
|
return item;
|
|
113
101
|
}
|
|
114
102
|
function sort(data, listeners, fn) {
|
|
115
|
-
data.sort((a, b) => fn(
|
|
103
|
+
data.sort((a, b) => fn(a, b));
|
|
116
104
|
dispatch(listeners, 'sort');
|
|
117
105
|
}
|
|
118
106
|
function splice(data, listeners, start, deleteCount = data.length, items = []) {
|
|
@@ -138,11 +126,7 @@ export default (data) => {
|
|
|
138
126
|
let listeners = {}, proxy = new Proxy({}, {
|
|
139
127
|
get(_, key) {
|
|
140
128
|
if (isNumber(key)) {
|
|
141
|
-
|
|
142
|
-
if (isComputed(value)) {
|
|
143
|
-
return read(value);
|
|
144
|
-
}
|
|
145
|
-
return value;
|
|
129
|
+
return data[key];
|
|
146
130
|
}
|
|
147
131
|
else if (key in wrapper) {
|
|
148
132
|
return wrapper[key];
|
|
@@ -173,7 +157,7 @@ export default (data) => {
|
|
|
173
157
|
}
|
|
174
158
|
}), wrapper = {
|
|
175
159
|
[REACTIVE_ARRAY]: true,
|
|
176
|
-
at: (i) =>
|
|
160
|
+
at: (i) => data[i],
|
|
177
161
|
clear: () => {
|
|
178
162
|
clear(data, listeners);
|
|
179
163
|
return proxy;
|
package/package.json
CHANGED
package/src/reactive/array.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isNumber } from '@esportsplus/utilities';
|
|
2
2
|
import { REACTIVE_ARRAY } from '~/constants';
|
|
3
|
-
import { dispose as d, isComputed, read } from '~/system';
|
|
4
3
|
import { Infer } from '~/types';
|
|
5
4
|
import { isReactiveObject } from './object';
|
|
6
5
|
|
|
@@ -49,23 +48,10 @@ type Listener<V> = {
|
|
|
49
48
|
type Listeners = Record<string, (Listener<any> | null)[]>;
|
|
50
49
|
|
|
51
50
|
|
|
52
|
-
function at<T>(data: T[], i: number) {
|
|
53
|
-
let value = data[i];
|
|
54
|
-
|
|
55
|
-
if (isComputed(value)) {
|
|
56
|
-
return read(value);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
51
|
function cleanup<T>(item: T) {
|
|
63
52
|
if (isReactiveObject(item)) {
|
|
64
53
|
item.dispose();
|
|
65
54
|
}
|
|
66
|
-
else if (isComputed(item)) {
|
|
67
|
-
d(item);
|
|
68
|
-
}
|
|
69
55
|
}
|
|
70
56
|
|
|
71
57
|
function clear<T>(data: T[], listeners: Listeners) {
|
|
@@ -128,13 +114,7 @@ function map<T, R>(
|
|
|
128
114
|
let values: R[] = new Array(n - i);
|
|
129
115
|
|
|
130
116
|
for (; i < n; i++) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
values[i] = fn.call(
|
|
134
|
-
proxy,
|
|
135
|
-
(isComputed(item) ? item.value : item) as T,
|
|
136
|
-
i
|
|
137
|
-
);
|
|
117
|
+
values[i] = fn.call(proxy, data[i], i);
|
|
138
118
|
}
|
|
139
119
|
|
|
140
120
|
return values;
|
|
@@ -205,10 +185,7 @@ function shift<T>(data: T[], listeners: Listeners) {
|
|
|
205
185
|
}
|
|
206
186
|
|
|
207
187
|
function sort<T>(data: T[], listeners: Listeners, fn: (a: T, b: T) => number) {
|
|
208
|
-
data.sort((a, b) => fn(
|
|
209
|
-
(isComputed(a) ? a.value : a) as T,
|
|
210
|
-
(isComputed(b) ? b.value : b) as T
|
|
211
|
-
));
|
|
188
|
+
data.sort((a, b) => fn(a, b));
|
|
212
189
|
dispatch(listeners, 'sort');
|
|
213
190
|
}
|
|
214
191
|
|
|
@@ -244,13 +221,7 @@ export default <T>(data: T[]) => {
|
|
|
244
221
|
proxy = new Proxy({}, {
|
|
245
222
|
get(_, key: any) {
|
|
246
223
|
if (isNumber(key)) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (isComputed(value)) {
|
|
250
|
-
return read(value);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return value;
|
|
224
|
+
return data[key];
|
|
254
225
|
}
|
|
255
226
|
else if (key in wrapper) {
|
|
256
227
|
return wrapper[key as keyof typeof wrapper];
|
|
@@ -284,7 +255,7 @@ export default <T>(data: T[]) => {
|
|
|
284
255
|
}) as API<T>,
|
|
285
256
|
wrapper = {
|
|
286
257
|
[REACTIVE_ARRAY]: true,
|
|
287
|
-
at: (i: number) =>
|
|
258
|
+
at: (i: number) => data[i],
|
|
288
259
|
clear: () => {
|
|
289
260
|
clear(data, listeners);
|
|
290
261
|
return proxy;
|