leaner 0.0.1 → 0.1.1
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/README.md +25 -2
- package/dist/core.js +257 -193
- package/dist/web.js +263 -103
- package/package.json +30 -10
- package/types/core.d.ts +47 -0
- package/types/web.d.ts +16 -0
package/types/core.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type DeepReadonly<T> = T extends object ? {
|
|
2
|
+
readonly [ K in keyof T ]: DeepReadonly<T[ K ]>;
|
|
3
|
+
} : T;
|
|
4
|
+
|
|
5
|
+
type PropGetter<T> = {
|
|
6
|
+
readonly [ K in keyof T ]: Getter<T[ K ]>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type ObjectGetter<T> = PropGetter<T> & {
|
|
10
|
+
get( prop: string | ( () => string ) ): Getter<any>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ArrayGetter<T> = {
|
|
14
|
+
readonly [ index: number ]: Getter<T>;
|
|
15
|
+
get( index: number | ( () => number ) ): Getter<T>;
|
|
16
|
+
length(): number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class Mutator<T> {
|
|
20
|
+
private callback: ( value: T ) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Getter<T> = ( () => DeepReadonly<T> ) & ( T extends Array<infer U> ? ArrayGetter<U> : T extends object ? ObjectGetter<T> : {} );
|
|
24
|
+
|
|
25
|
+
type Setter<T> = ( value: ( T extends Function ? never : T ) | ( ( value: DeepReadonly<T> ) => T ) | Mutator<T> ) => void;
|
|
26
|
+
|
|
27
|
+
export declare function state<T>( initial: T ): [ Getter<T>, Setter<T> ];
|
|
28
|
+
|
|
29
|
+
export declare function watch<T>( getter: () => T, callback: ( value: T, oldValue: T ) => void ): void;
|
|
30
|
+
|
|
31
|
+
export declare function effect( callback: () => void ): void;
|
|
32
|
+
|
|
33
|
+
export declare function reactive<T>( getter: () => T, callback: ( value: T, oldValue: T | undefined ) => void ): void;
|
|
34
|
+
|
|
35
|
+
export declare function computed<T>( callback: () => T ): Getter<T>;
|
|
36
|
+
|
|
37
|
+
export declare function constant<T>( value: T ): Getter<T>;
|
|
38
|
+
|
|
39
|
+
export declare function transform<T, U>( value: T | ( () => T ), callback: ( value: T ) => U ): U | ( () => U );
|
|
40
|
+
|
|
41
|
+
export declare function mutate<T>( callback: ( value: T ) => void ): Mutator<T>;
|
|
42
|
+
|
|
43
|
+
export declare function schedule( callback: () => void ): void;
|
|
44
|
+
|
|
45
|
+
export declare function withScope<T>( scope: any[], callback: () => T ): T;
|
|
46
|
+
|
|
47
|
+
export declare function destroyScope( scope: any[] ): void;
|
package/types/web.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface App {
|
|
2
|
+
mount( target: HTMLElement ): void;
|
|
3
|
+
destroy(): void;
|
|
4
|
+
provide( key: string | symbol, value: any ): void;
|
|
5
|
+
use( callback: () => void ): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare function createApp( component: ( props: object, children: any[] ) => any ): App;
|
|
9
|
+
|
|
10
|
+
export declare function inject( key: string | symbol ): any;
|
|
11
|
+
|
|
12
|
+
export declare function provide( key: string | symbol, value: any ): void;
|
|
13
|
+
|
|
14
|
+
export declare function onMount( callback: () => void ): void;
|
|
15
|
+
|
|
16
|
+
export declare function onDestroy( callback: () => void ): void;
|