@esportsplus/reactivity 0.19.3 → 0.20.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.d.ts +5 -0
- package/build/reactive/array.js +20 -0
- package/package.json +1 -1
- package/src/reactive/array.ts +30 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { REACTIVE_ARRAY } from '../constants.js';
|
|
2
2
|
type Events<T> = {
|
|
3
3
|
clear: undefined;
|
|
4
|
+
concat: {
|
|
5
|
+
items: T[];
|
|
6
|
+
};
|
|
4
7
|
pop: {
|
|
5
8
|
item: T;
|
|
6
9
|
};
|
|
@@ -35,6 +38,8 @@ declare class ReactiveArray<T> extends Array<T> {
|
|
|
35
38
|
listeners: Listeners;
|
|
36
39
|
constructor(...items: T[]);
|
|
37
40
|
clear(): void;
|
|
41
|
+
concat(...items: ConcatArray<T>[]): ReactiveArray<T>;
|
|
42
|
+
concat(...items: (T | ConcatArray<T>)[]): ReactiveArray<T>;
|
|
38
43
|
dispatch<K extends keyof Events<T>, V>(event: K, value?: V): void;
|
|
39
44
|
dispose(): void;
|
|
40
45
|
on<K extends keyof Events<T>>(event: K, listener: Listener<Events<T>[K]>): void;
|
package/build/reactive/array.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isArray } from '@esportsplus/utilities';
|
|
1
2
|
import { REACTIVE_ARRAY } from '../constants.js';
|
|
2
3
|
import { isReactiveObject } from './object.js';
|
|
3
4
|
class ReactiveArray extends Array {
|
|
@@ -10,6 +11,25 @@ class ReactiveArray extends Array {
|
|
|
10
11
|
this.dispose();
|
|
11
12
|
this.dispatch('clear');
|
|
12
13
|
}
|
|
14
|
+
concat(...items) {
|
|
15
|
+
let added = [];
|
|
16
|
+
for (let i = 0, n = items.length; i < n; i++) {
|
|
17
|
+
let item = items[i];
|
|
18
|
+
if (isArray(item)) {
|
|
19
|
+
for (let j = 0, o = item.length; j < o; j++) {
|
|
20
|
+
added.push(item[j]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
added.push(item);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (added.length) {
|
|
28
|
+
super.push(...added);
|
|
29
|
+
this.dispatch('concat', { items: added });
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
13
33
|
dispatch(event, value) {
|
|
14
34
|
let listeners = this.listeners[event];
|
|
15
35
|
if (!listeners) {
|
package/package.json
CHANGED
package/src/reactive/array.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { isArray } from '@esportsplus/utilities';
|
|
1
2
|
import { REACTIVE_ARRAY } from '~/constants';
|
|
2
3
|
import { isReactiveObject } from './object';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
type Events<T> = {
|
|
6
7
|
clear: undefined,
|
|
8
|
+
concat: {
|
|
9
|
+
items: T[];
|
|
10
|
+
};
|
|
7
11
|
pop: {
|
|
8
12
|
item: T;
|
|
9
13
|
};
|
|
@@ -52,6 +56,32 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
52
56
|
this.dispatch('clear');
|
|
53
57
|
}
|
|
54
58
|
|
|
59
|
+
concat(...items: ConcatArray<T>[]): ReactiveArray<T>;
|
|
60
|
+
concat(...items: (T | ConcatArray<T>)[]): ReactiveArray<T>;
|
|
61
|
+
concat(...items: (T | ConcatArray<T>)[]) {
|
|
62
|
+
let added: T[] = [];
|
|
63
|
+
|
|
64
|
+
for (let i = 0, n = items.length; i < n; i++) {
|
|
65
|
+
let item = items[i];
|
|
66
|
+
|
|
67
|
+
if (isArray(item)) {
|
|
68
|
+
for (let j = 0, o = item.length; j < o; j++) {
|
|
69
|
+
added.push(item[j]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
added.push(item as T);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (added.length) {
|
|
78
|
+
super.push(...added);
|
|
79
|
+
this.dispatch('concat', { items: added });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
55
85
|
dispatch<K extends keyof Events<T>, V>(event: K, value?: V) {
|
|
56
86
|
let listeners = this.listeners[event];
|
|
57
87
|
|