@viewfly/core 2.2.0 → 3.0.0-alpha.0
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/dist/base/_api.d.ts +0 -1
- package/dist/base/component.d.ts +19 -7
- package/dist/base/context.d.ts +70 -0
- package/dist/base/jsx-element.d.ts +1 -1
- package/dist/base/lifecycle.d.ts +24 -7
- package/dist/base/ref.d.ts +36 -30
- package/dist/base/types.d.ts +4 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +344 -285
- package/dist/index.js +1034 -416
- package/dist/reactive/_api.d.ts +2 -0
- package/dist/reactive/computed.d.ts +7 -1
- package/dist/reactive/reactive.d.ts +52 -0
- package/dist/reactive/watch-effect.d.ts +7 -0
- package/dist/reactive/watch.d.ts +8 -1
- package/package.json +8 -8
- package/dist/base/memo.d.ts +0 -8
- package/dist/signals/_api.d.ts +0 -3
- package/dist/signals/derived.d.ts +0 -9
- package/dist/signals/effect.d.ts +0 -22
- /package/dist/{signals → reactive}/signal.d.ts +0 -0
package/dist/base/_api.d.ts
CHANGED
package/dist/base/component.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { Key
|
|
1
|
+
import { Key } from './jsx-element';
|
|
2
2
|
import { NativeNode } from './injection-tokens';
|
|
3
3
|
import { JSX } from './types';
|
|
4
4
|
import { LifeCycleCallback } from './lifecycle';
|
|
5
5
|
import { ComponentAtom } from './_utils';
|
|
6
6
|
export declare function getSetupContext(need?: boolean): Component;
|
|
7
7
|
export type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
|
|
8
|
-
export interface ComponentInstance
|
|
8
|
+
export interface ComponentInstance {
|
|
9
9
|
$portalHost?: NativeNode;
|
|
10
10
|
$render(): JSXNode;
|
|
11
|
-
$useMemo?(currentProps: P, prevProps: P): boolean;
|
|
12
11
|
}
|
|
13
12
|
export type JSXNode = JSX.Element | JSX.ElementClass | string | number | boolean | null | undefined | Iterable<JSXNode>;
|
|
14
13
|
export interface ComponentSetup<P = any> {
|
|
15
|
-
(props: P): (() => JSXNode) | ComponentInstance
|
|
14
|
+
(props: P): (() => JSXNode) | ComponentInstance;
|
|
16
15
|
}
|
|
17
16
|
export interface ComponentViewMetadata {
|
|
18
17
|
atom: ComponentAtom;
|
|
@@ -28,7 +27,7 @@ export declare class Component {
|
|
|
28
27
|
readonly type: ComponentSetup;
|
|
29
28
|
props: Record<string, any>;
|
|
30
29
|
readonly key?: Key;
|
|
31
|
-
instance: ComponentInstance
|
|
30
|
+
instance: ComponentInstance;
|
|
32
31
|
changedSubComponents: Set<Component>;
|
|
33
32
|
get dirty(): boolean;
|
|
34
33
|
get changed(): boolean;
|
|
@@ -44,14 +43,13 @@ export declare class Component {
|
|
|
44
43
|
protected _changed: boolean;
|
|
45
44
|
private isFirstRendering;
|
|
46
45
|
private rawProps;
|
|
47
|
-
private
|
|
46
|
+
private refEffects;
|
|
48
47
|
private listener;
|
|
49
48
|
constructor(parentComponent: Component | null, type: ComponentSetup, props: Record<string, any>, key?: Key);
|
|
50
49
|
markAsDirtied(): void;
|
|
51
50
|
markAsChanged(changedComponent?: Component): void;
|
|
52
51
|
render(update: (template: JSXNode, portalHost?: NativeNode) => void): void;
|
|
53
52
|
updateProps(newProps: Record<string, any>): void;
|
|
54
|
-
canUpdate(oldProps: Record<string, any>, newProps: Record<string, any>): boolean;
|
|
55
53
|
rerender(): JSXNode;
|
|
56
54
|
destroy(): void;
|
|
57
55
|
rendered(): void;
|
|
@@ -60,6 +58,20 @@ export declare class Component {
|
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
62
60
|
* 获取当前组件实例
|
|
61
|
+
* @returns 当前组件实例
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function App() {
|
|
65
|
+
* const instance = getCurrentInstance()
|
|
66
|
+
* console.log(instance)
|
|
67
|
+
* return () => <div>...</div>
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
63
70
|
*/
|
|
64
71
|
export declare function getCurrentInstance(): Component;
|
|
72
|
+
/**
|
|
73
|
+
* 注册组件销毁回调函数
|
|
74
|
+
* @param fn 要注册的回调函数
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
65
77
|
export declare function registryComponentDestroyCallback(fn: () => void): void;
|
package/dist/base/context.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { AbstractType, ClassProvider, ExistingProvider, ExtractValueType, FactoryProvider, InjectFlags, InjectionToken, Injector, Provider, Scope, Type, ValueProvider } from '../di/_api';
|
|
2
2
|
import { Props } from './jsx-element';
|
|
3
3
|
import { ComponentSetup } from './component';
|
|
4
|
+
/**
|
|
5
|
+
* 创建一个上下文,用于在组件之间共享数据
|
|
6
|
+
* @param providers 提供者,用于提供数据
|
|
7
|
+
* @param scope 作用域,用于限制提供者的作用域
|
|
8
|
+
* @param parentInjector 父注入器,用于自定义父注入器,默认从当前组件树中自动获取
|
|
9
|
+
* @returns 一个上下文组件,组件的子元素都可以通过 inject 获取到提供者提供的数据
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* @Injectable()
|
|
13
|
+
* class ExampleService {}
|
|
14
|
+
*
|
|
15
|
+
* function Child(props) {
|
|
16
|
+
* const exampleService = inject(ExampleService)
|
|
17
|
+
* console.log(exampleService)
|
|
18
|
+
* return () => {
|
|
19
|
+
* return <div>{props.children}</div>
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* function App() {
|
|
23
|
+
* const Context = createContext([
|
|
24
|
+
* ExampleService
|
|
25
|
+
* ])
|
|
26
|
+
* return () => {
|
|
27
|
+
* return <Context>
|
|
28
|
+
* <Child>test</Child>
|
|
29
|
+
* </Context>
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
4
34
|
export declare function createContext(providers: Provider[], scope?: Scope | null, parentInjector?: Injector): (props: Props) => () => import('./component').JSXNode | import('./component').JSXNode[];
|
|
5
35
|
export interface ContextProviderParams<T> {
|
|
6
36
|
provide: Type<T> | AbstractType<T> | InjectionToken<T>;
|
|
@@ -11,9 +41,49 @@ export interface ContextProvider<T> extends Props {
|
|
|
11
41
|
useValue?: ValueProvider<T>['useValue'];
|
|
12
42
|
useExisting?: ExistingProvider<T>['useExisting'];
|
|
13
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* 创建一个上下文提供者组件,组件的子元素都可以通过 inject 获取到提供者提供的数据
|
|
46
|
+
* @param params 提供者参数
|
|
47
|
+
* @returns 一个上下文提供者组件,组件的子元素都可以通过 inject 获取到提供者提供的数据
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const ExampleService = createContextProvider({
|
|
51
|
+
* provide: ExampleService
|
|
52
|
+
* })
|
|
53
|
+
*
|
|
54
|
+
* function Child() {
|
|
55
|
+
* const exampleService = inject(ExampleService)
|
|
56
|
+
* console.log(exampleService)
|
|
57
|
+
* return () => {
|
|
58
|
+
* return <div>{exampleService.name}</div>
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* function App() {
|
|
63
|
+
* const value = new ExampleService()
|
|
64
|
+
* return () => {
|
|
65
|
+
* return <ExampleService useValue={value}>
|
|
66
|
+
* <Child/>
|
|
67
|
+
* </ExampleService>
|
|
68
|
+
* }
|
|
69
|
+
* }
|
|
70
|
+
*/
|
|
14
71
|
export declare function createContextProvider<T>(params: ContextProviderParams<T>): (props: ContextProvider<T>) => () => import('./jsx-element').ViewFlyNode<string | ComponentSetup<any>>;
|
|
15
72
|
/**
|
|
16
73
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
74
|
+
* @param token 注入的 token
|
|
75
|
+
* @param notFoundValue 未找到时的值
|
|
76
|
+
* @param flags 注入标志
|
|
77
|
+
* @returns 注入的值
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* function ChildComponent() {
|
|
81
|
+
* const exampleService = inject(ExampleService)
|
|
82
|
+
* console.log(exampleService)
|
|
83
|
+
* return () => {
|
|
84
|
+
* return <div>{exampleService.name}</div>
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
17
87
|
*/
|
|
18
88
|
export declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
|
|
19
89
|
export interface ComponentAnnotation {
|
|
@@ -4,7 +4,7 @@ export interface Props {
|
|
|
4
4
|
children?: JSXNode | JSXNode[];
|
|
5
5
|
}
|
|
6
6
|
export declare function Fragment(props: Props): () => JSXNode | JSXNode[];
|
|
7
|
-
export type Key =
|
|
7
|
+
export type Key = any;
|
|
8
8
|
export declare function jsx(type: string | ComponentSetup, props: Props & Record<string, any>, key?: Key): ViewFlyNode;
|
|
9
9
|
export declare const jsxs: typeof jsx;
|
|
10
10
|
export interface ViewFlyNode<T = string | ComponentSetup> {
|
package/dist/base/lifecycle.d.ts
CHANGED
|
@@ -2,12 +2,17 @@ export interface LifeCycleCallback {
|
|
|
2
2
|
(): void | (() => void);
|
|
3
3
|
}
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param callback
|
|
5
|
+
* 当组件挂载后调用回调函数
|
|
6
|
+
* @param callback 回调函数
|
|
7
|
+
* @returns 一个函数,用于停止监听
|
|
8
|
+
* @example
|
|
7
9
|
* ```tsx
|
|
8
10
|
* function App() {
|
|
9
|
-
*
|
|
11
|
+
* onMounted(() => {
|
|
10
12
|
* console.log('App mounted!')
|
|
13
|
+
* return () => {
|
|
14
|
+
* console.log('destroy prev mount!')
|
|
15
|
+
* }
|
|
11
16
|
* })
|
|
12
17
|
* return () => <div>...</div>
|
|
13
18
|
* }
|
|
@@ -15,8 +20,10 @@ export interface LifeCycleCallback {
|
|
|
15
20
|
*/
|
|
16
21
|
export declare function onMounted(callback: LifeCycleCallback): void;
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param callback
|
|
23
|
+
* 当组件视图更新后调用回调函数
|
|
24
|
+
* @param callback 回调函数
|
|
25
|
+
* @returns 一个函数,用于停止监听
|
|
26
|
+
* @example
|
|
20
27
|
* ```tsx
|
|
21
28
|
* function App() {
|
|
22
29
|
* onUpdated(() => {
|
|
@@ -31,7 +38,17 @@ export declare function onMounted(callback: LifeCycleCallback): void;
|
|
|
31
38
|
*/
|
|
32
39
|
export declare function onUpdated(callback: LifeCycleCallback): () => void;
|
|
33
40
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param callback
|
|
41
|
+
* 当组件销毁后调用回调函数
|
|
42
|
+
* @param callback 回调函数
|
|
43
|
+
* @returns 一个函数,用于停止监听
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* function App() {
|
|
47
|
+
* onUnmounted(() => {
|
|
48
|
+
* console.log('App unmounted!')
|
|
49
|
+
* })
|
|
50
|
+
* return () => <div>...</div>
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
36
53
|
*/
|
|
37
54
|
export declare function onUnmounted(callback: () => void): void;
|
package/dist/base/ref.d.ts
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
import { ComponentInstance } from './component';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export interface AbstractInstanceType<T extends Record<string, any>> {
|
|
7
|
-
(): T & ComponentInstance<any>;
|
|
8
|
-
}
|
|
9
|
-
export declare class DynamicRef<T> {
|
|
10
|
-
private callback;
|
|
11
|
-
private unBindMap;
|
|
12
|
-
private targetCaches;
|
|
13
|
-
constructor(callback: RefListener<T>);
|
|
14
|
-
bind(value: T): void;
|
|
15
|
-
unBind(value: T): void;
|
|
2
|
+
import { RefProp } from './types';
|
|
3
|
+
export type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends ComponentInstance ? Omit<U, keyof ComponentInstance> : U extends Function ? never : T;
|
|
4
|
+
export interface DynamicRef<T> {
|
|
5
|
+
(value: T): void | (() => void);
|
|
16
6
|
}
|
|
17
7
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param
|
|
8
|
+
* 创建一个动态 ref,当 ref 的绑定的元素或组件初始化后,会调用副作用函数,并把元素或组件的实例作为参数传入。
|
|
9
|
+
* @param effect 用于接收实例的副作用函数,该函数还可以返回一个清理副作用的函数,当元素或组件销毁时调用
|
|
10
|
+
* @returns 一个函数,用于清理副作用
|
|
20
11
|
* @example
|
|
21
12
|
* ```tsx
|
|
22
13
|
* function App() {
|
|
23
|
-
* const ref = createDynamicRef(node => {
|
|
24
|
-
*
|
|
25
|
-
* // do something...
|
|
26
|
-
* }
|
|
27
|
-
* node.addEventListener('click', fn)
|
|
14
|
+
* const ref = createDynamicRef<HTMLDivElement>((node) => {
|
|
15
|
+
* console.log(node)
|
|
28
16
|
* return () => {
|
|
29
|
-
*
|
|
17
|
+
* console.log('destroy')
|
|
30
18
|
* }
|
|
31
19
|
* })
|
|
32
20
|
* return () => {
|
|
33
|
-
* return <div ref={ref}>
|
|
21
|
+
* return <div ref={ref}>test</div>
|
|
34
22
|
* }
|
|
35
23
|
* }
|
|
36
24
|
* ```
|
|
37
25
|
*/
|
|
38
|
-
export declare function createDynamicRef<T, U = ExtractInstanceType<T>>(
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
export declare function createDynamicRef<T, U = ExtractInstanceType<T>>(effect: DynamicRef<U>): DynamicRef<U>;
|
|
27
|
+
export type Ref<T> = {
|
|
28
|
+
readonly value: T;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 创建一个引用对象,并添加到 JSX 节点上属性上,当组件渲染后,即可通过 .value 获取到绑定节点的实例
|
|
32
|
+
* - 当绑定到虚拟 DOM 元素节点上时,value 为当前节点的 DOM 元素
|
|
33
|
+
* - 当绑定到组件节点上时,value 为组件函数返回的对象
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* function App() {
|
|
37
|
+
* const ref = createRef<HTMLDivElement>()
|
|
38
|
+
* onMounted(() => {
|
|
39
|
+
* console.log(ref.value)
|
|
40
|
+
* })
|
|
41
|
+
* return () => {
|
|
42
|
+
* return <div ref={ref}>...</div>
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createRef<T, U = ExtractInstanceType<T> | null>(): Ref<U | null>;
|
|
48
|
+
export type RefEffects = Map<RefProp<any>, (() => void) | void>;
|
|
49
|
+
export declare function applyRefs(ref: RefProp<any> | RefProp<any>[], value: object, refEffects: RefEffects): void;
|
|
50
|
+
export declare function updateRefs(ref: RefProp<any> | RefProp<any>[], value: object, refEffects: RefEffects): void;
|
package/dist/base/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Key, ViewFlyNode } from './jsx-element';
|
|
2
2
|
import { ComponentInstance, ComponentSetup } from './component';
|
|
3
|
-
import { DynamicRef, ExtractInstanceType } from './ref';
|
|
3
|
+
import { DynamicRef, ExtractInstanceType, Ref } from './ref';
|
|
4
|
+
export type RefProp<T> = Ref<ExtractInstanceType<T> | null> | DynamicRef<ExtractInstanceType<T>>;
|
|
4
5
|
export declare namespace JSX {
|
|
5
6
|
type ElementType = keyof IntrinsicElements | ComponentSetup;
|
|
6
7
|
interface Element extends ViewFlyNode {
|
|
@@ -10,12 +11,8 @@ export declare namespace JSX {
|
|
|
10
11
|
}
|
|
11
12
|
interface IntrinsicAttributes extends KeyedAttributes {
|
|
12
13
|
ref?: any;
|
|
13
|
-
[key: string]: any;
|
|
14
14
|
}
|
|
15
|
-
interface
|
|
16
|
-
ref?: DynamicRef<ExtractInstanceType<T>> | DynamicRef<ExtractInstanceType<T>>[];
|
|
17
|
-
}
|
|
18
|
-
interface ElementClass<P = any> extends ComponentInstance<P> {
|
|
15
|
+
interface ElementClass extends ComponentInstance {
|
|
19
16
|
}
|
|
20
17
|
interface ElementAttributesProperty {
|
|
21
18
|
props: {};
|
|
@@ -27,6 +24,6 @@ export declare namespace JSX {
|
|
|
27
24
|
[name: string]: any;
|
|
28
25
|
}
|
|
29
26
|
interface IntrinsicClassAttributes<T> {
|
|
30
|
-
ref?:
|
|
27
|
+
ref?: RefProp<T>;
|
|
31
28
|
}
|
|
32
29
|
}
|
package/dist/index.d.ts
CHANGED