@esportsplus/reactivity 0.25.5 → 0.25.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/reactive/index.d.ts +1 -16
- package/build/reactive/index.js +3 -3
- package/build/types.d.ts +12 -2
- package/package.json +1 -1
- package/src/reactive/index.ts +4 -31
- package/src/types.ts +14 -4
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import { Prettify } from '@esportsplus/utilities';
|
|
2
1
|
import { ReactiveArray } from './array.js';
|
|
3
2
|
import { Reactive } from '../types.js';
|
|
4
|
-
declare const READONLY: unique symbol;
|
|
5
3
|
type Guard<T> = T extends Record<PropertyKey, unknown> ? T extends {
|
|
6
4
|
dispose: any;
|
|
7
5
|
} ? {
|
|
8
6
|
never: '[ dispose ] is a reserved key';
|
|
9
7
|
} : T : never;
|
|
10
|
-
|
|
11
|
-
[K in keyof T]: T[K];
|
|
12
|
-
} : T;
|
|
13
|
-
type ReactiveObject<T> = T extends Record<PropertyKey, unknown> ? Reactive<Prettify<{
|
|
14
|
-
[K in keyof T]: Infer<T[K]>;
|
|
15
|
-
} & {
|
|
16
|
-
dispose: VoidFunction;
|
|
17
|
-
}>> : T extends (infer U)[] ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'> : never;
|
|
18
|
-
declare function reactive<T extends () => unknown>(_input: T): Reactive<ReturnType<T> & {
|
|
19
|
-
readonly [READONLY]: true;
|
|
20
|
-
}>;
|
|
21
|
-
declare function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): ReactiveObject<T>;
|
|
22
|
-
declare function reactive<T>(_input: T[]): Reactive<T[] & Pick<ReactiveArray<T>, 'clear' | 'on' | 'once'>>;
|
|
8
|
+
declare function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): Reactive<T>;
|
|
23
9
|
export default reactive;
|
|
24
10
|
export { reactive, ReactiveArray };
|
|
25
|
-
export type { Reactive, ReactiveObject };
|
package/build/reactive/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactiveArray } from './array.js';
|
|
2
|
-
import { PACKAGE } from '../constants.js';
|
|
2
|
+
import { COMPILATION_ENTRYPOINT, PACKAGE } from '../constants.js';
|
|
3
3
|
function reactive(_input) {
|
|
4
|
-
throw new Error(`${PACKAGE}:
|
|
5
|
-
'Ensure vite
|
|
4
|
+
throw new Error(`${PACKAGE}: ${COMPILATION_ENTRYPOINT}() called at runtime. ` +
|
|
5
|
+
'Ensure vite plugin is configured.');
|
|
6
6
|
}
|
|
7
7
|
export default reactive;
|
|
8
8
|
export { reactive, ReactiveArray };
|
package/build/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants.js';
|
|
2
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
|
+
import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants.js';
|
|
3
|
+
import { ReactiveArray } from './reactive/index.js';
|
|
3
4
|
type BindingType = 'array' | 'computed' | 'object' | 'signal';
|
|
4
5
|
type Bindings = Map<string, BindingType>;
|
|
5
6
|
interface Computed<T> {
|
|
@@ -24,7 +25,16 @@ interface Link {
|
|
|
24
25
|
sub: Computed<unknown>;
|
|
25
26
|
version: number;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
declare const READONLY: unique symbol;
|
|
29
|
+
type Reactive<T> = T extends (...args: unknown[]) => Promise<infer R> ? (R | undefined) & {
|
|
30
|
+
readonly [READONLY]: true;
|
|
31
|
+
} : T extends (...args: any[]) => infer R ? R & {
|
|
32
|
+
readonly [READONLY]: true;
|
|
33
|
+
} : T extends (infer U)[] ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'> : T extends Record<PropertyKey, unknown> ? {
|
|
34
|
+
[K in keyof T]: T[K];
|
|
35
|
+
} & {
|
|
36
|
+
dispose: VoidFunction;
|
|
37
|
+
} : T;
|
|
28
38
|
type Signal<T> = {
|
|
29
39
|
subs: Link | null;
|
|
30
40
|
subsTail: Link | null;
|
package/package.json
CHANGED
package/src/reactive/index.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Prettify } from '@esportsplus/utilities';
|
|
2
1
|
import { ReactiveArray } from './array';
|
|
3
|
-
import { PACKAGE } from '~/constants';
|
|
2
|
+
import { COMPILATION_ENTRYPOINT, PACKAGE } from '~/constants';
|
|
4
3
|
import { Reactive } from '~/types';
|
|
5
4
|
|
|
6
5
|
|
|
7
|
-
// Branded type to prevent assignment to computed values
|
|
8
|
-
declare const READONLY: unique symbol;
|
|
9
|
-
|
|
10
6
|
type Guard<T> =
|
|
11
7
|
T extends Record<PropertyKey, unknown>
|
|
12
8
|
? T extends { dispose: any }
|
|
@@ -14,38 +10,15 @@ type Guard<T> =
|
|
|
14
10
|
: T
|
|
15
11
|
: never;
|
|
16
12
|
|
|
17
|
-
type Infer<T> =
|
|
18
|
-
T extends (...args: unknown[]) => Promise<infer R>
|
|
19
|
-
? R | undefined
|
|
20
|
-
: T extends (...args: any[]) => infer R
|
|
21
|
-
? R
|
|
22
|
-
: T extends (infer U)[]
|
|
23
|
-
? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'>
|
|
24
|
-
: T extends ReactiveObject<any>
|
|
25
|
-
? T
|
|
26
|
-
: T extends Record<PropertyKey, unknown>
|
|
27
|
-
? { [K in keyof T]: T[K] }
|
|
28
|
-
: T;
|
|
29
|
-
|
|
30
|
-
type ReactiveObject<T> =
|
|
31
|
-
T extends Record<PropertyKey, unknown>
|
|
32
|
-
? Reactive< Prettify<{ [K in keyof T]: Infer<T[K]> } & { dispose: VoidFunction }> >
|
|
33
|
-
: T extends (infer U)[]
|
|
34
|
-
? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'>
|
|
35
|
-
: never;
|
|
36
|
-
|
|
37
13
|
|
|
38
|
-
function reactive<T extends
|
|
39
|
-
function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): ReactiveObject<T>;
|
|
40
|
-
function reactive<T>(_input: T[]): Reactive< T[] & Pick<ReactiveArray<T>, 'clear' | 'on' | 'once'> >;
|
|
14
|
+
function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): Reactive<T>;
|
|
41
15
|
function reactive<T>(_input: T): Reactive<T> {
|
|
42
16
|
throw new Error(
|
|
43
|
-
`${PACKAGE}:
|
|
44
|
-
'Ensure vite
|
|
17
|
+
`${PACKAGE}: ${COMPILATION_ENTRYPOINT}() called at runtime. ` +
|
|
18
|
+
'Ensure vite plugin is configured.'
|
|
45
19
|
);
|
|
46
20
|
}
|
|
47
21
|
|
|
48
22
|
|
|
49
23
|
export default reactive;
|
|
50
24
|
export { reactive, ReactiveArray };
|
|
51
|
-
export type { Reactive, ReactiveObject };
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
|
|
2
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
|
+
import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
|
|
3
|
+
import { ReactiveArray } from './reactive';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
type BindingType = 'array' | 'computed' | 'object' | 'signal';
|
|
@@ -37,7 +38,17 @@ interface Link {
|
|
|
37
38
|
|
|
38
39
|
// If we expose internals optimizing compiler may break api.
|
|
39
40
|
// Instead we will use this as a shim.
|
|
40
|
-
|
|
41
|
+
declare const READONLY: unique symbol;
|
|
42
|
+
|
|
43
|
+
type Reactive<T> = T extends (...args: unknown[]) => Promise<infer R>
|
|
44
|
+
? (R | undefined) & { readonly [READONLY]: true }
|
|
45
|
+
: T extends (...args: any[]) => infer R
|
|
46
|
+
? R & { readonly [READONLY]: true }
|
|
47
|
+
: T extends (infer U)[]
|
|
48
|
+
? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'>
|
|
49
|
+
: T extends Record<PropertyKey, unknown>
|
|
50
|
+
? { [K in keyof T]: T[K] } & { dispose: VoidFunction }
|
|
51
|
+
: T;
|
|
41
52
|
|
|
42
53
|
type Signal<T> = {
|
|
43
54
|
subs: Link | null;
|
|
@@ -54,8 +65,7 @@ interface TransformResult {
|
|
|
54
65
|
|
|
55
66
|
|
|
56
67
|
export type {
|
|
57
|
-
BindingType,
|
|
58
|
-
Bindings,
|
|
68
|
+
BindingType, Bindings,
|
|
59
69
|
Computed,
|
|
60
70
|
Link,
|
|
61
71
|
Reactive,
|