@esportsplus/reactivity 0.0.14 → 0.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/build/methods/reactive.js +8 -9
- package/build/types.d.ts +3 -5
- package/package.json +1 -1
- package/src/methods/reactive.ts +13 -18
- package/src/types.ts +3 -11
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import Reactive from '../reactive';
|
|
2
|
-
function factory(value
|
|
3
|
-
if (typeof value === 'function') {
|
|
4
|
-
return fn(value, wrap);
|
|
5
|
-
}
|
|
2
|
+
function factory(value) {
|
|
6
3
|
if (typeof value === 'object' && value !== null && (value.constructor === Object)) {
|
|
7
4
|
return obj(value);
|
|
8
5
|
}
|
|
9
6
|
return new Reactive(value);
|
|
10
7
|
}
|
|
11
|
-
function fn(value
|
|
8
|
+
function fn(value) {
|
|
12
9
|
let fn = new Reactive(value);
|
|
13
|
-
if (!wrap) {
|
|
14
|
-
return fn;
|
|
15
|
-
}
|
|
16
10
|
return (...args) => {
|
|
17
11
|
let value = fn.get();
|
|
18
12
|
if (args.length && typeof value === 'function') {
|
|
@@ -50,4 +44,9 @@ function obj(values) {
|
|
|
50
44
|
return Object.defineProperties({}, properties);
|
|
51
45
|
}
|
|
52
46
|
;
|
|
53
|
-
export default (value) =>
|
|
47
|
+
export default (value) => {
|
|
48
|
+
if (typeof value === 'function') {
|
|
49
|
+
return fn(value);
|
|
50
|
+
}
|
|
51
|
+
return factory(value);
|
|
52
|
+
};
|
package/build/types.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { CLEAN, CHECK, DIRTY } from './symbols';
|
|
2
|
-
import Reactive from './reactive';
|
|
3
2
|
type Fn = () => Promise<unknown> | unknown;
|
|
4
|
-
type Infer<T> = T extends (...args: any[]) => any ?
|
|
5
|
-
|
|
6
|
-
type InferNested<T> = T extends (...args: any[]) => any ? ReturnType<T> : T extends Record<string, Primitives> ? {
|
|
7
|
-
[K in keyof T]: InferNested<T[K]>;
|
|
3
|
+
type Infer<T> = T extends (...args: any[]) => any ? ReturnType<T> : T extends Record<string, Primitives> ? {
|
|
4
|
+
[K in keyof T]: Infer<T[K]>;
|
|
8
5
|
} : T;
|
|
6
|
+
type Primitives = any[] | boolean | number | string | null | undefined | ((...args: any[]) => any);
|
|
9
7
|
type ReactiveFn<T> = (onCleanup?: (fn: VoidFunction) => void) => T;
|
|
10
8
|
type Scheduler = {
|
|
11
9
|
schedule(): void;
|
package/package.json
CHANGED
package/src/methods/reactive.ts
CHANGED
|
@@ -2,27 +2,18 @@ import { Infer } from '~/types';
|
|
|
2
2
|
import Reactive from '~/reactive';
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
function factory<T>(value: T
|
|
6
|
-
if (typeof value === 'function') {
|
|
7
|
-
return fn(value, wrap);
|
|
8
|
-
}
|
|
9
|
-
|
|
5
|
+
function factory<T>(value: T) {
|
|
10
6
|
if (typeof value === 'object' && value !== null && (value.constructor === Object)) {
|
|
11
7
|
return obj(value);
|
|
12
8
|
}
|
|
13
9
|
|
|
14
|
-
return new Reactive(value)
|
|
10
|
+
return new Reactive(value);
|
|
15
11
|
}
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
// Functions are wrapped to remove '.get' usage
|
|
14
|
+
function fn<T>(value: T) {
|
|
18
15
|
let fn = new Reactive(value);
|
|
19
16
|
|
|
20
|
-
// We're inside an object, it will unwrap reactive values
|
|
21
|
-
if (!wrap) {
|
|
22
|
-
return fn;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Factory functions are wrapped to remove '.get' usage
|
|
26
17
|
return (...args: any[]) => {
|
|
27
18
|
let value = fn.get();
|
|
28
19
|
|
|
@@ -30,9 +21,7 @@ function fn<T>(value: T, wrap: boolean) {
|
|
|
30
21
|
value = value(...args);
|
|
31
22
|
}
|
|
32
23
|
|
|
33
|
-
return value
|
|
34
|
-
? ReturnType<typeof value>
|
|
35
|
-
: typeof value;
|
|
24
|
+
return value;
|
|
36
25
|
};
|
|
37
26
|
}
|
|
38
27
|
|
|
@@ -69,8 +58,14 @@ function obj<T>(values: T) {
|
|
|
69
58
|
};
|
|
70
59
|
}
|
|
71
60
|
|
|
72
|
-
return Object.defineProperties({}, properties)
|
|
61
|
+
return Object.defineProperties({}, properties);
|
|
73
62
|
};
|
|
74
63
|
|
|
75
64
|
|
|
76
|
-
export default <T>(value: T) =>
|
|
65
|
+
export default <T>(value: T) => {
|
|
66
|
+
if (typeof value === 'function') {
|
|
67
|
+
return fn(value) as Infer<T>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return factory(value) as Infer<T>;
|
|
71
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
import { CLEAN, CHECK, DIRTY } from './symbols';
|
|
2
|
-
import Reactive from './reactive';
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
type Fn = () => Promise<unknown> | unknown;
|
|
6
5
|
|
|
7
6
|
type Infer<T> =
|
|
8
|
-
T extends (...args: any[]) => any
|
|
9
|
-
? Reactive<T>
|
|
10
|
-
: T extends Record<string, any>
|
|
11
|
-
? InferNested<T>
|
|
12
|
-
: Reactive<T>;
|
|
13
|
-
|
|
14
|
-
type Primitives = any[] | boolean | number | string | null | undefined | ((...args: any[]) => any);
|
|
15
|
-
|
|
16
|
-
type InferNested<T> =
|
|
17
7
|
T extends (...args: any[]) => any
|
|
18
8
|
? ReturnType<T>
|
|
19
9
|
: T extends Record<string, Primitives>
|
|
20
|
-
? { [K in keyof T]:
|
|
10
|
+
? { [K in keyof T]: Infer<T[K]> }
|
|
21
11
|
: T;
|
|
22
12
|
|
|
13
|
+
type Primitives = any[] | boolean | number | string | null | undefined | ((...args: any[]) => any);
|
|
14
|
+
|
|
23
15
|
type ReactiveFn<T> = (onCleanup?: (fn: VoidFunction) => void) => T;
|
|
24
16
|
|
|
25
17
|
type Scheduler = {
|