@esportsplus/reactivity 0.1.21 → 0.1.23
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/macro.d.ts +1 -1
- package/build/macro.js +4 -4
- package/build/reactive/array.d.ts +2 -2
- package/build/reactive/array.js +13 -13
- package/build/resource.d.ts +3 -1
- package/build/resource.js +18 -18
- package/package.json +2 -2
- package/src/macro.ts +4 -4
- package/src/reactive/array.ts +13 -13
- package/src/resource.ts +18 -18
package/build/macro.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import CustomFunction from '@esportsplus/custom-function';
|
|
|
2
2
|
import { Computed, Options } from './types';
|
|
3
3
|
type Function<A extends unknown[], R> = Computed<(...args: A) => R>['fn'];
|
|
4
4
|
declare class Macro<A extends unknown[], R> extends CustomFunction {
|
|
5
|
-
|
|
5
|
+
private factory;
|
|
6
6
|
constructor(fn: Function<A, R>, options?: Options);
|
|
7
7
|
dispose(): void;
|
|
8
8
|
}
|
package/build/macro.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
2
|
import { computed } from './signal';
|
|
3
3
|
class Macro extends CustomFunction {
|
|
4
|
-
|
|
4
|
+
factory;
|
|
5
5
|
constructor(fn, options = {}) {
|
|
6
6
|
super((...args) => {
|
|
7
|
-
return this
|
|
7
|
+
return this.factory.get()(...args);
|
|
8
8
|
});
|
|
9
|
-
this
|
|
9
|
+
this.factory = computed(fn, options);
|
|
10
10
|
}
|
|
11
11
|
dispose() {
|
|
12
|
-
this
|
|
12
|
+
this.factory.dispose();
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export default (fn, options = {}) => {
|
|
@@ -26,7 +26,7 @@ type Events<T> = {
|
|
|
26
26
|
};
|
|
27
27
|
type Node<T extends Object> = ReactiveObject<T>;
|
|
28
28
|
declare class ReactiveArray<T> extends Array<T> {
|
|
29
|
-
|
|
29
|
+
private signal;
|
|
30
30
|
constructor(data: T[]);
|
|
31
31
|
set length(n: number);
|
|
32
32
|
private trigger;
|
|
@@ -45,7 +45,7 @@ declare class ReactiveArray<T> extends Array<T> {
|
|
|
45
45
|
unshift(...items: T[]): number;
|
|
46
46
|
}
|
|
47
47
|
declare class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T>> {
|
|
48
|
-
|
|
48
|
+
private options;
|
|
49
49
|
constructor(data: T[], options?: Options);
|
|
50
50
|
fill(): never;
|
|
51
51
|
reverse(): never;
|
package/build/reactive/array.js
CHANGED
|
@@ -11,10 +11,10 @@ function unsupported(method) {
|
|
|
11
11
|
throw new Error(`Reactivity: '${method}' is not supported on reactive object array`);
|
|
12
12
|
}
|
|
13
13
|
class ReactiveArray extends Array {
|
|
14
|
-
|
|
14
|
+
signal;
|
|
15
15
|
constructor(data) {
|
|
16
16
|
super(...data);
|
|
17
|
-
this
|
|
17
|
+
this.signal = signal(false);
|
|
18
18
|
}
|
|
19
19
|
set length(n) {
|
|
20
20
|
if (n > this.length) {
|
|
@@ -23,13 +23,13 @@ class ReactiveArray extends Array {
|
|
|
23
23
|
this.splice(n);
|
|
24
24
|
}
|
|
25
25
|
trigger() {
|
|
26
|
-
this
|
|
26
|
+
this.signal.set(!this.signal.value);
|
|
27
27
|
}
|
|
28
28
|
dispatch(event, data) {
|
|
29
|
-
this
|
|
29
|
+
this.signal.dispatch(event, data);
|
|
30
30
|
}
|
|
31
31
|
dispose() {
|
|
32
|
-
this
|
|
32
|
+
this.signal.dispose();
|
|
33
33
|
}
|
|
34
34
|
fill(value, start, end) {
|
|
35
35
|
super.fill(value, start, end);
|
|
@@ -38,10 +38,10 @@ class ReactiveArray extends Array {
|
|
|
38
38
|
return this;
|
|
39
39
|
}
|
|
40
40
|
on(event, listener) {
|
|
41
|
-
this
|
|
41
|
+
this.signal.on(event, listener);
|
|
42
42
|
}
|
|
43
43
|
once(event, listener) {
|
|
44
|
-
this
|
|
44
|
+
this.signal.once(event, listener);
|
|
45
45
|
}
|
|
46
46
|
pop() {
|
|
47
47
|
let item = super.pop();
|
|
@@ -90,7 +90,7 @@ class ReactiveArray extends Array {
|
|
|
90
90
|
return removed;
|
|
91
91
|
}
|
|
92
92
|
track() {
|
|
93
|
-
this
|
|
93
|
+
this.signal.get();
|
|
94
94
|
}
|
|
95
95
|
unshift(...items) {
|
|
96
96
|
let length = super.unshift(...items);
|
|
@@ -100,10 +100,10 @@ class ReactiveArray extends Array {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
class ReactiveObjectArray extends ReactiveArray {
|
|
103
|
-
|
|
103
|
+
options;
|
|
104
104
|
constructor(data, options = {}) {
|
|
105
105
|
super(factory(data, options));
|
|
106
|
-
this
|
|
106
|
+
this.options = options;
|
|
107
107
|
}
|
|
108
108
|
fill() {
|
|
109
109
|
return unsupported('fill');
|
|
@@ -115,7 +115,7 @@ class ReactiveObjectArray extends ReactiveArray {
|
|
|
115
115
|
return dispose(super.pop());
|
|
116
116
|
}
|
|
117
117
|
push(...values) {
|
|
118
|
-
return super.push(...factory(values, this
|
|
118
|
+
return super.push(...factory(values, this.options));
|
|
119
119
|
}
|
|
120
120
|
shift() {
|
|
121
121
|
return dispose(super.shift());
|
|
@@ -124,10 +124,10 @@ class ReactiveObjectArray extends ReactiveArray {
|
|
|
124
124
|
return unsupported('sort');
|
|
125
125
|
}
|
|
126
126
|
splice(start, deleteCount = super.length, ...values) {
|
|
127
|
-
return dispose(super.splice(start, deleteCount, ...factory(values, this
|
|
127
|
+
return dispose(super.splice(start, deleteCount, ...factory(values, this.options)));
|
|
128
128
|
}
|
|
129
129
|
unshift(...values) {
|
|
130
|
-
return super.unshift(...factory(values, this
|
|
130
|
+
return super.unshift(...factory(values, this.options));
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
export { ReactiveArray, ReactiveObjectArray };
|
package/build/resource.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import CustomFunction from '@esportsplus/custom-function';
|
|
|
2
2
|
import { Options } from './types';
|
|
3
3
|
type Function<A extends unknown[], R extends Promise<unknown>> = (...args: A) => R;
|
|
4
4
|
declare class Resource<A extends unknown[], R extends Promise<unknown>> extends CustomFunction {
|
|
5
|
-
|
|
5
|
+
private arguments;
|
|
6
|
+
private okay;
|
|
7
|
+
private response;
|
|
6
8
|
stop: boolean | null;
|
|
7
9
|
constructor(fn: Function<A, R>, options?: Options);
|
|
8
10
|
get data(): Awaited<R>;
|
package/build/resource.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
2
|
import { signal } from './signal';
|
|
3
3
|
class Resource extends CustomFunction {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
arguments;
|
|
5
|
+
okay;
|
|
6
|
+
response;
|
|
7
7
|
stop = null;
|
|
8
8
|
constructor(fn, options = {}) {
|
|
9
9
|
super((...args) => {
|
|
10
10
|
this.stop = null;
|
|
11
|
-
this
|
|
12
|
-
this
|
|
11
|
+
this.arguments.set(args);
|
|
12
|
+
this.okay.set(null);
|
|
13
13
|
fn(...args)
|
|
14
14
|
.then((value) => {
|
|
15
15
|
if (this.stop === true) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
this
|
|
19
|
-
this
|
|
18
|
+
this.response.set(value);
|
|
19
|
+
this.okay.set(true);
|
|
20
20
|
})
|
|
21
21
|
.catch(() => {
|
|
22
22
|
if (this.stop === true) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
this
|
|
26
|
-
this
|
|
25
|
+
this.response.set(undefined);
|
|
26
|
+
this.okay.set(false);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
-
this
|
|
30
|
-
this
|
|
31
|
-
this
|
|
29
|
+
this.response = signal(undefined, options);
|
|
30
|
+
this.arguments = signal(null, options);
|
|
31
|
+
this.okay = signal(null, options);
|
|
32
32
|
}
|
|
33
33
|
get data() {
|
|
34
|
-
return this
|
|
34
|
+
return this.response.get();
|
|
35
35
|
}
|
|
36
36
|
get input() {
|
|
37
|
-
return this
|
|
37
|
+
return this.arguments.get();
|
|
38
38
|
}
|
|
39
39
|
get ok() {
|
|
40
|
-
return this
|
|
40
|
+
return this.okay.get();
|
|
41
41
|
}
|
|
42
42
|
dispose() {
|
|
43
|
-
this
|
|
44
|
-
this
|
|
45
|
-
this
|
|
43
|
+
this.arguments.dispose();
|
|
44
|
+
this.okay.dispose();
|
|
45
|
+
this.response.dispose();
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
export default (fn, options = {}) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@esportsplus/custom-function": "^0.0.
|
|
4
|
+
"@esportsplus/custom-function": "^0.0.4"
|
|
5
5
|
},
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@esportsplus/typescript": "^0.1.2"
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"prepublishOnly": "npm run build"
|
|
17
17
|
},
|
|
18
18
|
"types": "build/index.d.ts",
|
|
19
|
-
"version": "0.1.
|
|
19
|
+
"version": "0.1.23"
|
|
20
20
|
}
|
package/src/macro.ts
CHANGED
|
@@ -7,19 +7,19 @@ type Function<A extends unknown[], R> = Computed<(...args: A) => R>['fn'];
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class Macro<A extends unknown[], R> extends CustomFunction {
|
|
10
|
-
|
|
10
|
+
private factory: Computed<(...args: A) => R>;
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
constructor(fn: Function<A,R>, options: Options = {}) {
|
|
14
14
|
super((...args: A) => {
|
|
15
|
-
return this
|
|
15
|
+
return this.factory.get()(...args);
|
|
16
16
|
});
|
|
17
|
-
this
|
|
17
|
+
this.factory = computed(fn, options);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
dispose() {
|
|
22
|
-
this
|
|
22
|
+
this.factory.dispose();
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
package/src/reactive/array.ts
CHANGED
|
@@ -33,12 +33,12 @@ function unsupported(method: string): never {
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
class ReactiveArray<T> extends Array<T> {
|
|
36
|
-
|
|
36
|
+
private signal: Signal<boolean>;
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
constructor(data: T[]) {
|
|
40
40
|
super(...data);
|
|
41
|
-
this
|
|
41
|
+
this.signal = signal(false);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
|
|
@@ -52,16 +52,16 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
private trigger() {
|
|
55
|
-
this
|
|
55
|
+
this.signal.set(!this.signal.value);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
dispatch<E extends keyof Events<T>>(event: E, data?: Events<T>[E]) {
|
|
60
|
-
this
|
|
60
|
+
this.signal.dispatch(event, data);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
dispose() {
|
|
64
|
-
this
|
|
64
|
+
this.signal.dispose();
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
fill(value: T, start?: number, end?: number) {
|
|
@@ -74,11 +74,11 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
on<E extends keyof Events<T>>(event: E, listener: Listener<Events<T>[E]>) {
|
|
77
|
-
this
|
|
77
|
+
this.signal.on(event, listener);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
once<E extends keyof Events<T>>(event: E, listener: Listener<Events<T>[E]>) {
|
|
81
|
-
this
|
|
81
|
+
this.signal.once(event, listener);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
pop() {
|
|
@@ -146,7 +146,7 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
track() {
|
|
149
|
-
this
|
|
149
|
+
this.signal.get();
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
unshift(...items: T[]) {
|
|
@@ -164,12 +164,12 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
164
164
|
// - @ts-ignore flags are supressing a type mismatch error
|
|
165
165
|
// - Input values are being transformed by this class into nodes
|
|
166
166
|
class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T>> {
|
|
167
|
-
|
|
167
|
+
private options: Options;
|
|
168
168
|
|
|
169
169
|
|
|
170
170
|
constructor(data: T[], options: Options = {}) {
|
|
171
171
|
super( factory(data, options) );
|
|
172
|
-
this
|
|
172
|
+
this.options = options;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
|
|
@@ -187,7 +187,7 @@ class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T>> {
|
|
|
187
187
|
|
|
188
188
|
// @ts-ignore
|
|
189
189
|
push(...values: T[]) {
|
|
190
|
-
return super.push(...factory(values, this
|
|
190
|
+
return super.push(...factory(values, this.options));
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
shift() {
|
|
@@ -200,12 +200,12 @@ class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T>> {
|
|
|
200
200
|
|
|
201
201
|
// @ts-ignore
|
|
202
202
|
splice(start: number, deleteCount: number = super.length, ...values: T[]) {
|
|
203
|
-
return dispose( super.splice(start, deleteCount, ...factory(values, this
|
|
203
|
+
return dispose( super.splice(start, deleteCount, ...factory(values, this.options)) );
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
// @ts-ignore
|
|
207
207
|
unshift(...values: T[]) {
|
|
208
|
-
return super.unshift(...factory(values, this
|
|
208
|
+
return super.unshift(...factory(values, this.options));
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
package/src/resource.ts
CHANGED
|
@@ -7,9 +7,9 @@ type Function<A extends unknown[], R extends Promise<unknown>> = (...args: A) =>
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class Resource<A extends unknown[], R extends Promise<unknown>> extends CustomFunction {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
private arguments: Signal<A | null>;
|
|
11
|
+
private okay: Signal<boolean | null>;
|
|
12
|
+
private response: Signal<Awaited<R>>;
|
|
13
13
|
|
|
14
14
|
stop: boolean | null = null;
|
|
15
15
|
|
|
@@ -18,8 +18,8 @@ class Resource<A extends unknown[], R extends Promise<unknown>> extends CustomFu
|
|
|
18
18
|
super((...args: A) => {
|
|
19
19
|
this.stop = null;
|
|
20
20
|
|
|
21
|
-
this
|
|
22
|
-
this
|
|
21
|
+
this.arguments.set(args);
|
|
22
|
+
this.okay.set(null);
|
|
23
23
|
|
|
24
24
|
fn(...args)
|
|
25
25
|
.then((value) => {
|
|
@@ -27,41 +27,41 @@ class Resource<A extends unknown[], R extends Promise<unknown>> extends CustomFu
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
this
|
|
31
|
-
this
|
|
30
|
+
this.response.set(value as Awaited<R>);
|
|
31
|
+
this.okay.set(true);
|
|
32
32
|
})
|
|
33
33
|
.catch(() => {
|
|
34
34
|
if (this.stop === true) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
this
|
|
39
|
-
this
|
|
38
|
+
this.response.set(undefined as Awaited<R>);
|
|
39
|
+
this.okay.set(false);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
-
this
|
|
43
|
-
this
|
|
44
|
-
this
|
|
42
|
+
this.response = signal(undefined as Awaited<R>, options);
|
|
43
|
+
this.arguments = signal<A | null>(null, options);
|
|
44
|
+
this.okay = signal<boolean | null>(null, options);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
get data() {
|
|
49
|
-
return this
|
|
49
|
+
return this.response.get();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
get input() {
|
|
53
|
-
return this
|
|
53
|
+
return this.arguments.get();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
get ok() {
|
|
57
|
-
return this
|
|
57
|
+
return this.okay.get();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
dispose() {
|
|
62
|
-
this
|
|
63
|
-
this
|
|
64
|
-
this
|
|
62
|
+
this.arguments.dispose();
|
|
63
|
+
this.okay.dispose();
|
|
64
|
+
this.response.dispose();
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|