@esportsplus/reactivity 0.0.5 → 0.0.6
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/index.d.ts +2 -3
- package/build/index.js +5 -1
- package/package.json +1 -1
- package/src/index.ts +11 -6
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Queue } from './types';
|
|
2
|
-
type Infer<T> = T extends (...args: any[]) => any ?
|
|
3
|
-
|
|
4
|
-
} : Reactive<T>;
|
|
2
|
+
type Infer<T> = T extends (...args: any[]) => any ? InferValue<ReturnType<T>> : InferValue<T>;
|
|
3
|
+
type InferValue<T> = T extends Record<string, any> ? T : Reactive<T>;
|
|
5
4
|
declare class Reactive<T> {
|
|
6
5
|
private effect;
|
|
7
6
|
private fn?;
|
package/build/index.js
CHANGED
|
@@ -167,7 +167,11 @@ const effect = (queue) => {
|
|
|
167
167
|
};
|
|
168
168
|
const reactive = (value) => {
|
|
169
169
|
let v;
|
|
170
|
-
if (typeof value === '
|
|
170
|
+
if (typeof value === 'function') {
|
|
171
|
+
let fn = new Reactive(value);
|
|
172
|
+
v = (...args) => fn.get()(...args);
|
|
173
|
+
}
|
|
174
|
+
else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
171
175
|
v = obj(value);
|
|
172
176
|
}
|
|
173
177
|
else {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { Queue, State } from './types';
|
|
|
3
3
|
import obj from './obj';
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
// We only unwrap the top level function
|
|
6
7
|
type Infer<T> =
|
|
7
8
|
T extends (...args: any[]) => any
|
|
8
|
-
?
|
|
9
|
-
: T
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
: Reactive<T>;
|
|
9
|
+
? InferValue<ReturnType<T>>
|
|
10
|
+
: InferValue<T>;
|
|
11
|
+
|
|
12
|
+
type InferValue<T> = T extends Record<string, any> ? T : Reactive<T>;
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
let index = 0,
|
|
@@ -241,7 +241,12 @@ const effect = (queue: Queue) => {
|
|
|
241
241
|
const reactive = <T>(value: T) => {
|
|
242
242
|
let v;
|
|
243
243
|
|
|
244
|
-
if (typeof value === '
|
|
244
|
+
if (typeof value === 'function') {
|
|
245
|
+
let fn = new Reactive(value);
|
|
246
|
+
|
|
247
|
+
v = (...args: any[]) => fn.get()(...args);
|
|
248
|
+
}
|
|
249
|
+
else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
245
250
|
v = obj(value);
|
|
246
251
|
}
|
|
247
252
|
else {
|