@viewfly/core 1.1.9 → 2.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/bundles/index.d.ts +9 -38
- package/bundles/index.esm.js +295 -135
- package/bundles/index.js +295 -136
- package/package.json +2 -2
package/bundles/index.d.ts
CHANGED
|
@@ -413,19 +413,14 @@ interface ComponentInstance<P> {
|
|
|
413
413
|
$useMemo?(currentProps: P, prevProps: P): boolean;
|
|
414
414
|
}
|
|
415
415
|
type JSXNode = JSX.Element | JSX.ElementClass | string | number | boolean | null | undefined | Iterable<JSXNode>;
|
|
416
|
-
interface ComponentAnnotation {
|
|
417
|
-
scope?: Scope;
|
|
418
|
-
providers?: Provider[];
|
|
419
|
-
}
|
|
420
416
|
interface ComponentSetup<P = any> {
|
|
421
417
|
(props: P): (() => JSXNode) | ComponentInstance<P>;
|
|
422
|
-
annotation?: ComponentAnnotation;
|
|
423
418
|
}
|
|
424
419
|
/**
|
|
425
420
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
|
426
421
|
*/
|
|
427
|
-
declare class Component
|
|
428
|
-
|
|
422
|
+
declare class Component {
|
|
423
|
+
readonly parentComponent: Component | null;
|
|
429
424
|
readonly type: ComponentSetup;
|
|
430
425
|
props: Props;
|
|
431
426
|
readonly key?: Key | undefined;
|
|
@@ -444,12 +439,11 @@ declare class Component extends ReflectiveInjector {
|
|
|
444
439
|
private isFirstRendering;
|
|
445
440
|
private refs;
|
|
446
441
|
private listener;
|
|
447
|
-
constructor(parentComponent:
|
|
442
|
+
constructor(parentComponent: Component | null, type: ComponentSetup, props: Props, key?: Key | undefined);
|
|
448
443
|
markAsDirtied(): void;
|
|
449
444
|
markAsChanged(changedComponent?: Component): void;
|
|
450
445
|
render(update: (template: JSXNode, portalHost?: NativeNode) => void): void;
|
|
451
446
|
update(newProps: Record<string, any>, updateChildren: (jsxNode: JSXNode) => void, reuseChildren: (skipSubComponentDiff: boolean) => void): void;
|
|
452
|
-
provide<T>(providers: Provider<T> | Provider<T>[]): void;
|
|
453
447
|
destroy(): void;
|
|
454
448
|
rendered(): void;
|
|
455
449
|
private invokePropsChangedHooks;
|
|
@@ -457,38 +451,15 @@ declare class Component extends ReflectiveInjector {
|
|
|
457
451
|
private invokeUpdatedHooks;
|
|
458
452
|
}
|
|
459
453
|
/**
|
|
460
|
-
*
|
|
461
|
-
* @param annotation
|
|
462
|
-
* @param componentSetup
|
|
463
|
-
* @example
|
|
464
|
-
* ```ts
|
|
465
|
-
* export customScope = new Scope('scopeName')
|
|
466
|
-
* export const App = withAnnotation({
|
|
467
|
-
* scope: customScope,
|
|
468
|
-
* providers: [
|
|
469
|
-
* ExampleService
|
|
470
|
-
* ]
|
|
471
|
-
* }, function(props: Props) {
|
|
472
|
-
* return () => {
|
|
473
|
-
* return <div>...</div>
|
|
474
|
-
* }
|
|
475
|
-
* })
|
|
476
|
-
* ```
|
|
454
|
+
* 获取当前组件实例
|
|
477
455
|
*/
|
|
478
|
-
declare function
|
|
456
|
+
declare function getCurrentInstance(): Component;
|
|
457
|
+
|
|
458
|
+
declare function createContext(providers: Provider[], scope?: Scope, parentInjector?: Injector): (props: Props) => () => JSXNode | JSXNode[];
|
|
479
459
|
/**
|
|
480
460
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
481
461
|
*/
|
|
482
462
|
declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
|
|
483
|
-
/**
|
|
484
|
-
* 获取当前组件实例
|
|
485
|
-
*/
|
|
486
|
-
declare function getCurrentInstance(): Component;
|
|
487
|
-
|
|
488
|
-
interface ContextProps extends Props {
|
|
489
|
-
providers: Provider[];
|
|
490
|
-
}
|
|
491
|
-
declare function Context(props: ContextProps): () => ViewFlyNode<string | ComponentSetup<any>>;
|
|
492
463
|
|
|
493
464
|
declare function withMemo<T extends Props = Props>(canUseMemo: ComponentInstance<T>['$useMemo'], render: () => JSXNode): ComponentInstance<T>;
|
|
494
465
|
|
|
@@ -500,7 +471,7 @@ declare function createRenderer(component: Component, nativeRenderer: NativeRend
|
|
|
500
471
|
*/
|
|
501
472
|
declare class RootComponent extends Component {
|
|
502
473
|
private refresh;
|
|
503
|
-
constructor(
|
|
474
|
+
constructor(factory: ComponentSetup, refresh: () => void);
|
|
504
475
|
markAsChanged(changedComponent?: Component): void;
|
|
505
476
|
}
|
|
506
477
|
|
|
@@ -602,4 +573,4 @@ interface Module {
|
|
|
602
573
|
}
|
|
603
574
|
declare function viewfly<T extends NativeNode>(config: Config): Application<T>;
|
|
604
575
|
|
|
605
|
-
export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassNames, type ClassProvider, Component, type
|
|
576
|
+
export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassNames, type ClassProvider, Component, type ComponentInstance, type ComponentSetup, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ElementNamespace, ElementNamespaceMap, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, JSX, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type ViewFlyNode, type WatchCallback, computed, createContext, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withMemo };
|
package/bundles/index.esm.js
CHANGED
|
@@ -2,7 +2,12 @@ import 'reflect-metadata';
|
|
|
2
2
|
|
|
3
3
|
class ForwardRef {
|
|
4
4
|
constructor(forwardRefFn) {
|
|
5
|
-
this
|
|
5
|
+
Object.defineProperty(this, "forwardRefFn", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: forwardRefFn
|
|
10
|
+
});
|
|
6
11
|
}
|
|
7
12
|
getRef() {
|
|
8
13
|
return this.forwardRefFn();
|
|
@@ -21,9 +26,24 @@ function forwardRef(fn) {
|
|
|
21
26
|
*/
|
|
22
27
|
class Annotations {
|
|
23
28
|
constructor() {
|
|
24
|
-
this
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
Object.defineProperty(this, "classes", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: new Map()
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "props", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: new Map()
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "params", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: new Map()
|
|
46
|
+
});
|
|
27
47
|
}
|
|
28
48
|
setClassMetadata(token, params) {
|
|
29
49
|
this.classes.set(token, params);
|
|
@@ -110,7 +130,12 @@ function getAnnotations(target) {
|
|
|
110
130
|
|
|
111
131
|
class Scope {
|
|
112
132
|
constructor(name) {
|
|
113
|
-
this
|
|
133
|
+
Object.defineProperty(this, "name", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
configurable: true,
|
|
136
|
+
writable: true,
|
|
137
|
+
value: name
|
|
138
|
+
});
|
|
114
139
|
}
|
|
115
140
|
toString() {
|
|
116
141
|
return this.name || '[anonymous provide scope]';
|
|
@@ -134,7 +159,12 @@ const Injectable = function InjectableDecorator(options) {
|
|
|
134
159
|
/* eslint-disable-next-line */
|
|
135
160
|
class InjectionToken {
|
|
136
161
|
constructor(description) {
|
|
137
|
-
this
|
|
162
|
+
Object.defineProperty(this, "description", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
configurable: true,
|
|
165
|
+
writable: true,
|
|
166
|
+
value: description
|
|
167
|
+
});
|
|
138
168
|
}
|
|
139
169
|
toString() {
|
|
140
170
|
return this.description || '[anonymous injection token]';
|
|
@@ -236,7 +266,12 @@ const nullInjectorErrorFn = (token) => {
|
|
|
236
266
|
};
|
|
237
267
|
class NullInjector {
|
|
238
268
|
constructor() {
|
|
239
|
-
this
|
|
269
|
+
Object.defineProperty(this, "parentInjector", {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
configurable: true,
|
|
272
|
+
writable: true,
|
|
273
|
+
value: null
|
|
274
|
+
});
|
|
240
275
|
}
|
|
241
276
|
/* eslint-disable-next-line */
|
|
242
277
|
get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
|
|
@@ -412,9 +447,30 @@ const provideScopeError = (token) => {
|
|
|
412
447
|
*/
|
|
413
448
|
class ReflectiveInjector {
|
|
414
449
|
constructor(parentInjector, staticProviders, scope) {
|
|
415
|
-
this
|
|
416
|
-
|
|
417
|
-
|
|
450
|
+
Object.defineProperty(this, "parentInjector", {
|
|
451
|
+
enumerable: true,
|
|
452
|
+
configurable: true,
|
|
453
|
+
writable: true,
|
|
454
|
+
value: parentInjector
|
|
455
|
+
});
|
|
456
|
+
Object.defineProperty(this, "scope", {
|
|
457
|
+
enumerable: true,
|
|
458
|
+
configurable: true,
|
|
459
|
+
writable: true,
|
|
460
|
+
value: scope
|
|
461
|
+
});
|
|
462
|
+
Object.defineProperty(this, "normalizedProviders", {
|
|
463
|
+
enumerable: true,
|
|
464
|
+
configurable: true,
|
|
465
|
+
writable: true,
|
|
466
|
+
value: void 0
|
|
467
|
+
});
|
|
468
|
+
Object.defineProperty(this, "recordValues", {
|
|
469
|
+
enumerable: true,
|
|
470
|
+
configurable: true,
|
|
471
|
+
writable: true,
|
|
472
|
+
value: new Map()
|
|
473
|
+
});
|
|
418
474
|
this.normalizedProviders = staticProviders.map(provide => {
|
|
419
475
|
return normalizeProvider(provide);
|
|
420
476
|
});
|
|
@@ -620,8 +676,18 @@ const ComponentAtomType = Symbol('Component');
|
|
|
620
676
|
|
|
621
677
|
class Listener {
|
|
622
678
|
constructor(effect) {
|
|
623
|
-
this
|
|
624
|
-
|
|
679
|
+
Object.defineProperty(this, "effect", {
|
|
680
|
+
enumerable: true,
|
|
681
|
+
configurable: true,
|
|
682
|
+
writable: true,
|
|
683
|
+
value: effect
|
|
684
|
+
});
|
|
685
|
+
Object.defineProperty(this, "destroyCallbacks", {
|
|
686
|
+
enumerable: true,
|
|
687
|
+
configurable: true,
|
|
688
|
+
writable: true,
|
|
689
|
+
value: []
|
|
690
|
+
});
|
|
625
691
|
}
|
|
626
692
|
destroy() {
|
|
627
693
|
this.destroyCallbacks.forEach(fn => fn());
|
|
@@ -732,9 +798,24 @@ function onUnmounted(callback) {
|
|
|
732
798
|
|
|
733
799
|
class DynamicRef {
|
|
734
800
|
constructor(callback) {
|
|
735
|
-
this
|
|
736
|
-
|
|
737
|
-
|
|
801
|
+
Object.defineProperty(this, "callback", {
|
|
802
|
+
enumerable: true,
|
|
803
|
+
configurable: true,
|
|
804
|
+
writable: true,
|
|
805
|
+
value: callback
|
|
806
|
+
});
|
|
807
|
+
Object.defineProperty(this, "unBindMap", {
|
|
808
|
+
enumerable: true,
|
|
809
|
+
configurable: true,
|
|
810
|
+
writable: true,
|
|
811
|
+
value: new Map()
|
|
812
|
+
});
|
|
813
|
+
Object.defineProperty(this, "targetCaches", {
|
|
814
|
+
enumerable: true,
|
|
815
|
+
configurable: true,
|
|
816
|
+
writable: true,
|
|
817
|
+
value: new Set()
|
|
818
|
+
});
|
|
738
819
|
}
|
|
739
820
|
bind(value) {
|
|
740
821
|
if (typeof value !== 'object' || value === null) {
|
|
@@ -793,6 +874,12 @@ class StaticRef extends DynamicRef {
|
|
|
793
874
|
isInit = true;
|
|
794
875
|
}
|
|
795
876
|
});
|
|
877
|
+
Object.defineProperty(this, "current", {
|
|
878
|
+
enumerable: true,
|
|
879
|
+
configurable: true,
|
|
880
|
+
writable: true,
|
|
881
|
+
value: void 0
|
|
882
|
+
});
|
|
796
883
|
Object.defineProperty(this, 'current', {
|
|
797
884
|
get() {
|
|
798
885
|
if (value === initValue) {
|
|
@@ -825,7 +912,7 @@ function toRefs(ref) {
|
|
|
825
912
|
/**
|
|
826
913
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
|
827
914
|
*/
|
|
828
|
-
class Component
|
|
915
|
+
class Component {
|
|
829
916
|
get dirty() {
|
|
830
917
|
return this._dirty;
|
|
831
918
|
}
|
|
@@ -833,23 +920,109 @@ class Component extends ReflectiveInjector {
|
|
|
833
920
|
return this._changed;
|
|
834
921
|
}
|
|
835
922
|
constructor(parentComponent, type, props, key) {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
this
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
this
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
923
|
+
Object.defineProperty(this, "parentComponent", {
|
|
924
|
+
enumerable: true,
|
|
925
|
+
configurable: true,
|
|
926
|
+
writable: true,
|
|
927
|
+
value: parentComponent
|
|
928
|
+
});
|
|
929
|
+
Object.defineProperty(this, "type", {
|
|
930
|
+
enumerable: true,
|
|
931
|
+
configurable: true,
|
|
932
|
+
writable: true,
|
|
933
|
+
value: type
|
|
934
|
+
});
|
|
935
|
+
Object.defineProperty(this, "props", {
|
|
936
|
+
enumerable: true,
|
|
937
|
+
configurable: true,
|
|
938
|
+
writable: true,
|
|
939
|
+
value: props
|
|
940
|
+
});
|
|
941
|
+
Object.defineProperty(this, "key", {
|
|
942
|
+
enumerable: true,
|
|
943
|
+
configurable: true,
|
|
944
|
+
writable: true,
|
|
945
|
+
value: key
|
|
946
|
+
});
|
|
947
|
+
Object.defineProperty(this, "instance", {
|
|
948
|
+
enumerable: true,
|
|
949
|
+
configurable: true,
|
|
950
|
+
writable: true,
|
|
951
|
+
value: void 0
|
|
952
|
+
});
|
|
953
|
+
Object.defineProperty(this, "changedSubComponents", {
|
|
954
|
+
enumerable: true,
|
|
955
|
+
configurable: true,
|
|
956
|
+
writable: true,
|
|
957
|
+
value: new Set()
|
|
958
|
+
});
|
|
959
|
+
Object.defineProperty(this, "unmountedCallbacks", {
|
|
960
|
+
enumerable: true,
|
|
961
|
+
configurable: true,
|
|
962
|
+
writable: true,
|
|
963
|
+
value: void 0
|
|
964
|
+
});
|
|
965
|
+
Object.defineProperty(this, "mountCallbacks", {
|
|
966
|
+
enumerable: true,
|
|
967
|
+
configurable: true,
|
|
968
|
+
writable: true,
|
|
969
|
+
value: void 0
|
|
970
|
+
});
|
|
971
|
+
Object.defineProperty(this, "propsChangedCallbacks", {
|
|
972
|
+
enumerable: true,
|
|
973
|
+
configurable: true,
|
|
974
|
+
writable: true,
|
|
975
|
+
value: void 0
|
|
976
|
+
});
|
|
977
|
+
Object.defineProperty(this, "updatedCallbacks", {
|
|
978
|
+
enumerable: true,
|
|
979
|
+
configurable: true,
|
|
980
|
+
writable: true,
|
|
981
|
+
value: void 0
|
|
982
|
+
});
|
|
983
|
+
Object.defineProperty(this, "updatedDestroyCallbacks", {
|
|
984
|
+
enumerable: true,
|
|
985
|
+
configurable: true,
|
|
986
|
+
writable: true,
|
|
987
|
+
value: void 0
|
|
988
|
+
});
|
|
989
|
+
Object.defineProperty(this, "propsChangedDestroyCallbacks", {
|
|
990
|
+
enumerable: true,
|
|
991
|
+
configurable: true,
|
|
992
|
+
writable: true,
|
|
993
|
+
value: void 0
|
|
994
|
+
});
|
|
995
|
+
Object.defineProperty(this, "_dirty", {
|
|
996
|
+
enumerable: true,
|
|
997
|
+
configurable: true,
|
|
998
|
+
writable: true,
|
|
999
|
+
value: true
|
|
1000
|
+
});
|
|
1001
|
+
Object.defineProperty(this, "_changed", {
|
|
1002
|
+
enumerable: true,
|
|
1003
|
+
configurable: true,
|
|
1004
|
+
writable: true,
|
|
1005
|
+
value: true
|
|
1006
|
+
});
|
|
1007
|
+
Object.defineProperty(this, "isFirstRendering", {
|
|
1008
|
+
enumerable: true,
|
|
1009
|
+
configurable: true,
|
|
1010
|
+
writable: true,
|
|
1011
|
+
value: true
|
|
1012
|
+
});
|
|
1013
|
+
Object.defineProperty(this, "refs", {
|
|
1014
|
+
enumerable: true,
|
|
1015
|
+
configurable: true,
|
|
1016
|
+
writable: true,
|
|
1017
|
+
value: null
|
|
1018
|
+
});
|
|
1019
|
+
Object.defineProperty(this, "listener", {
|
|
1020
|
+
enumerable: true,
|
|
1021
|
+
configurable: true,
|
|
1022
|
+
writable: true,
|
|
1023
|
+
value: new Listener(() => {
|
|
1024
|
+
this.markAsDirtied();
|
|
1025
|
+
})
|
|
853
1026
|
});
|
|
854
1027
|
}
|
|
855
1028
|
markAsDirtied() {
|
|
@@ -952,10 +1125,6 @@ class Component extends ReflectiveInjector {
|
|
|
952
1125
|
updateChildren(template);
|
|
953
1126
|
this.rendered();
|
|
954
1127
|
}
|
|
955
|
-
provide(providers) {
|
|
956
|
-
providers = Array.isArray(providers) ? providers : [providers];
|
|
957
|
-
this.normalizedProviders.unshift(...providers.map(i => normalizeProvider(i)));
|
|
958
|
-
}
|
|
959
1128
|
destroy() {
|
|
960
1129
|
var _a, _b, _c;
|
|
961
1130
|
this.listener.destroy();
|
|
@@ -972,13 +1141,12 @@ class Component extends ReflectiveInjector {
|
|
|
972
1141
|
this.parentComponent.changedSubComponents.delete(this);
|
|
973
1142
|
}
|
|
974
1143
|
this.parentComponent =
|
|
975
|
-
this.
|
|
976
|
-
this.
|
|
977
|
-
this.
|
|
978
|
-
this.
|
|
979
|
-
this.
|
|
980
|
-
this.
|
|
981
|
-
this.unmountedCallbacks = null;
|
|
1144
|
+
this.propsChangedDestroyCallbacks =
|
|
1145
|
+
this.updatedDestroyCallbacks =
|
|
1146
|
+
this.mountCallbacks =
|
|
1147
|
+
this.updatedCallbacks =
|
|
1148
|
+
this.propsChangedCallbacks =
|
|
1149
|
+
this.unmountedCallbacks = null;
|
|
982
1150
|
this.changedSubComponents.clear();
|
|
983
1151
|
}
|
|
984
1152
|
rendered() {
|
|
@@ -1056,43 +1224,44 @@ class Component extends ReflectiveInjector {
|
|
|
1056
1224
|
}
|
|
1057
1225
|
}
|
|
1058
1226
|
/**
|
|
1059
|
-
*
|
|
1060
|
-
* @param annotation
|
|
1061
|
-
* @param componentSetup
|
|
1062
|
-
* @example
|
|
1063
|
-
* ```ts
|
|
1064
|
-
* export customScope = new Scope('scopeName')
|
|
1065
|
-
* export const App = withAnnotation({
|
|
1066
|
-
* scope: customScope,
|
|
1067
|
-
* providers: [
|
|
1068
|
-
* ExampleService
|
|
1069
|
-
* ]
|
|
1070
|
-
* }, function(props: Props) {
|
|
1071
|
-
* return () => {
|
|
1072
|
-
* return <div>...</div>
|
|
1073
|
-
* }
|
|
1074
|
-
* })
|
|
1075
|
-
* ```
|
|
1227
|
+
* 获取当前组件实例
|
|
1076
1228
|
*/
|
|
1077
|
-
function
|
|
1078
|
-
|
|
1079
|
-
|
|
1229
|
+
function getCurrentInstance() {
|
|
1230
|
+
return getSetupContext();
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
const injectMap = new WeakMap();
|
|
1234
|
+
function getParentInjector(component) {
|
|
1235
|
+
let start = component.parentComponent;
|
|
1236
|
+
while (start) {
|
|
1237
|
+
const injector = injectMap.get(start);
|
|
1238
|
+
if (injector) {
|
|
1239
|
+
return injector;
|
|
1240
|
+
}
|
|
1241
|
+
start = start.parentComponent;
|
|
1242
|
+
}
|
|
1243
|
+
return new NullInjector();
|
|
1244
|
+
}
|
|
1245
|
+
function createContext(providers, scope, parentInjector) {
|
|
1246
|
+
return function context(props) {
|
|
1247
|
+
const instance = getCurrentInstance();
|
|
1248
|
+
const injector = new ReflectiveInjector(parentInjector || getParentInjector(instance), providers, scope);
|
|
1249
|
+
injectMap.set(instance, injector);
|
|
1250
|
+
return () => {
|
|
1251
|
+
return props.children;
|
|
1252
|
+
};
|
|
1080
1253
|
};
|
|
1081
|
-
setup.annotation = annotation;
|
|
1082
|
-
return setup;
|
|
1083
1254
|
}
|
|
1084
1255
|
/**
|
|
1085
1256
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1086
1257
|
*/
|
|
1087
1258
|
function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
1088
|
-
const component =
|
|
1089
|
-
|
|
1259
|
+
const component = getCurrentInstance();
|
|
1260
|
+
const injector = getParentInjector(component);
|
|
1261
|
+
return injector.get(token, notFoundValue, flags);
|
|
1090
1262
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
*/
|
|
1094
|
-
function getCurrentInstance() {
|
|
1095
|
-
return getSetupContext();
|
|
1263
|
+
|
|
1264
|
+
class NativeRenderer {
|
|
1096
1265
|
}
|
|
1097
1266
|
|
|
1098
1267
|
function Fragment(props) {
|
|
@@ -1114,33 +1283,6 @@ const JSXNodeFactory = {
|
|
|
1114
1283
|
}
|
|
1115
1284
|
};
|
|
1116
1285
|
|
|
1117
|
-
function Context(props) {
|
|
1118
|
-
function createContextComponent(providers) {
|
|
1119
|
-
return withAnnotation({
|
|
1120
|
-
providers,
|
|
1121
|
-
}, (childProps) => {
|
|
1122
|
-
return () => {
|
|
1123
|
-
return childProps.children;
|
|
1124
|
-
};
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
let contextComponent = createContextComponent(props.providers);
|
|
1128
|
-
onPropsChanged((newProps, oldProps) => {
|
|
1129
|
-
if (newProps.providers === oldProps.providers) {
|
|
1130
|
-
return;
|
|
1131
|
-
}
|
|
1132
|
-
contextComponent = createContextComponent(newProps.providers);
|
|
1133
|
-
});
|
|
1134
|
-
return () => {
|
|
1135
|
-
return jsx(contextComponent, {
|
|
1136
|
-
children: props.children
|
|
1137
|
-
});
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
class NativeRenderer {
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
1286
|
function withMemo(canUseMemo, render) {
|
|
1145
1287
|
return {
|
|
1146
1288
|
$useMemo: canUseMemo,
|
|
@@ -1228,9 +1370,8 @@ function applyChanges(nativeRenderer, component, atom, context, needMove) {
|
|
|
1228
1370
|
view.host = context.host;
|
|
1229
1371
|
view.isParent = context.isParent;
|
|
1230
1372
|
}
|
|
1231
|
-
}, () => {
|
|
1232
|
-
|
|
1233
|
-
//
|
|
1373
|
+
}, (skipSubComponentDiff) => {
|
|
1374
|
+
reuseComponentView(nativeRenderer, atom, context, needMove, skipSubComponentDiff);
|
|
1234
1375
|
});
|
|
1235
1376
|
}
|
|
1236
1377
|
function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, needMove) {
|
|
@@ -1400,27 +1541,31 @@ function cleanElementChildren(atom, nativeRenderer) {
|
|
|
1400
1541
|
}
|
|
1401
1542
|
}
|
|
1402
1543
|
function cleanView(nativeRenderer, atom, needClean) {
|
|
1403
|
-
if (atom.
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
needClean =
|
|
1407
|
-
}
|
|
1408
|
-
if (atom.type === ElementAtomType) {
|
|
1409
|
-
const ref = atom.jsxNode.props[refKey];
|
|
1410
|
-
applyRefs(ref, atom.nativeNode, false);
|
|
1544
|
+
if (atom.type === ComponentAtomType) {
|
|
1545
|
+
const jsxNode = atom.jsxNode;
|
|
1546
|
+
if (jsxNode.instance.$portalHost) {
|
|
1547
|
+
needClean = true;
|
|
1411
1548
|
}
|
|
1549
|
+
cleanChildren(atom, nativeRenderer, needClean);
|
|
1550
|
+
jsxNode.destroy();
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
if (needClean) {
|
|
1554
|
+
nativeRenderer.remove(atom.nativeNode, atom.namespace);
|
|
1555
|
+
needClean = false;
|
|
1412
1556
|
}
|
|
1557
|
+
if (atom.type === ElementAtomType) {
|
|
1558
|
+
const ref = atom.jsxNode.props[refKey];
|
|
1559
|
+
applyRefs(ref, atom.nativeNode, false);
|
|
1560
|
+
}
|
|
1561
|
+
cleanChildren(atom, nativeRenderer, needClean);
|
|
1562
|
+
}
|
|
1563
|
+
function cleanChildren(atom, nativeRenderer, needClean) {
|
|
1413
1564
|
let child = atom.child;
|
|
1414
1565
|
while (child) {
|
|
1415
|
-
if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
|
|
1416
|
-
needClean = true;
|
|
1417
|
-
}
|
|
1418
1566
|
cleanView(nativeRenderer, child, needClean);
|
|
1419
1567
|
child = child.sibling;
|
|
1420
1568
|
}
|
|
1421
|
-
if (atom.jsxNode instanceof Component) {
|
|
1422
|
-
atom.jsxNode.destroy();
|
|
1423
|
-
}
|
|
1424
1569
|
}
|
|
1425
1570
|
function componentRender(nativeRenderer, component, from, context) {
|
|
1426
1571
|
component.render((template, portalHost) => {
|
|
@@ -1473,7 +1618,9 @@ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
|
1473
1618
|
return prevAtom;
|
|
1474
1619
|
}
|
|
1475
1620
|
function createChainByChildren(children, prevAtom, elementNamespace) {
|
|
1476
|
-
|
|
1621
|
+
const len = children.length;
|
|
1622
|
+
for (let i = 0; i < len; i++) {
|
|
1623
|
+
const item = children[i];
|
|
1477
1624
|
prevAtom = createChainByNode(item, prevAtom, elementNamespace);
|
|
1478
1625
|
}
|
|
1479
1626
|
return prevAtom;
|
|
@@ -1565,7 +1712,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1565
1712
|
let unBindRefs;
|
|
1566
1713
|
let bindRefs;
|
|
1567
1714
|
let updatedChildren = false;
|
|
1568
|
-
|
|
1715
|
+
let len = changes.remove.length;
|
|
1716
|
+
for (let i = 0; i < len; i++) {
|
|
1717
|
+
const [key, value] = changes.remove[i];
|
|
1569
1718
|
if (key === 'children') {
|
|
1570
1719
|
updatedChildren = true;
|
|
1571
1720
|
cleanElementChildren(oldAtom, nativeRenderer);
|
|
@@ -1593,7 +1742,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1593
1742
|
}
|
|
1594
1743
|
nativeRenderer.removeProperty(nativeNode, key, isSvg);
|
|
1595
1744
|
}
|
|
1596
|
-
|
|
1745
|
+
len = changes.replace.length;
|
|
1746
|
+
for (let i = 0; i < len; i++) {
|
|
1747
|
+
const [key, newValue, oldValue] = changes.replace[i];
|
|
1597
1748
|
if (key === 'children') {
|
|
1598
1749
|
updatedChildren = true;
|
|
1599
1750
|
newAtom.child = createChildChain(newValue, isSvg);
|
|
@@ -1638,7 +1789,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1638
1789
|
}
|
|
1639
1790
|
nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
|
|
1640
1791
|
}
|
|
1641
|
-
|
|
1792
|
+
len = changes.add.length;
|
|
1793
|
+
for (let i = 0; i < len; i++) {
|
|
1794
|
+
const [key, value] = changes.add[i];
|
|
1642
1795
|
if (key === 'children') {
|
|
1643
1796
|
updatedChildren = true;
|
|
1644
1797
|
newAtom.child = createChildChain(value, isSvg);
|
|
@@ -1678,7 +1831,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1678
1831
|
function applyRefs(refs, nativeNode, binding) {
|
|
1679
1832
|
if (refs) {
|
|
1680
1833
|
const refList = Array.isArray(refs) ? refs : [refs];
|
|
1681
|
-
|
|
1834
|
+
const len = refList.length;
|
|
1835
|
+
for (let i = 0; i < len; i++) {
|
|
1836
|
+
const item = refList[i];
|
|
1682
1837
|
if (item instanceof DynamicRef) {
|
|
1683
1838
|
binding ? item.bind(nativeNode) : item.unBind(nativeNode);
|
|
1684
1839
|
}
|
|
@@ -1690,9 +1845,14 @@ function applyRefs(refs, nativeNode, binding) {
|
|
|
1690
1845
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
1691
1846
|
*/
|
|
1692
1847
|
class RootComponent extends Component {
|
|
1693
|
-
constructor(
|
|
1694
|
-
super(
|
|
1695
|
-
this
|
|
1848
|
+
constructor(factory, refresh) {
|
|
1849
|
+
super(null, factory, {});
|
|
1850
|
+
Object.defineProperty(this, "refresh", {
|
|
1851
|
+
enumerable: true,
|
|
1852
|
+
configurable: true,
|
|
1853
|
+
writable: true,
|
|
1854
|
+
value: refresh
|
|
1855
|
+
});
|
|
1696
1856
|
}
|
|
1697
1857
|
markAsChanged(changedComponent) {
|
|
1698
1858
|
this._changed = true;
|
|
@@ -1836,16 +1996,15 @@ function viewfly(config) {
|
|
|
1836
1996
|
const modules = [];
|
|
1837
1997
|
let destroyed = false;
|
|
1838
1998
|
let appHost = null;
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
useValue: nativeRenderer
|
|
1843
|
-
}]
|
|
1844
|
-
}, () => {
|
|
1999
|
+
const rootProviders = [];
|
|
2000
|
+
const rootComponent = new RootComponent(() => {
|
|
2001
|
+
const rootContext = createContext(rootProviders, void 0, context);
|
|
1845
2002
|
return () => {
|
|
1846
|
-
return
|
|
2003
|
+
return jsx(rootContext, {
|
|
2004
|
+
children: destroyed ? null : root
|
|
2005
|
+
});
|
|
1847
2006
|
};
|
|
1848
|
-
}
|
|
2007
|
+
}, function () {
|
|
1849
2008
|
if (destroyed || !autoUpdate) {
|
|
1850
2009
|
return;
|
|
1851
2010
|
}
|
|
@@ -1867,7 +2026,8 @@ function viewfly(config) {
|
|
|
1867
2026
|
}
|
|
1868
2027
|
const app = {
|
|
1869
2028
|
provide(providers) {
|
|
1870
|
-
|
|
2029
|
+
providers = Array.isArray(providers) ? providers : [providers];
|
|
2030
|
+
rootProviders.push(...providers);
|
|
1871
2031
|
return app;
|
|
1872
2032
|
},
|
|
1873
2033
|
use(module) {
|
|
@@ -1917,4 +2077,4 @@ function viewfly(config) {
|
|
|
1917
2077
|
return app;
|
|
1918
2078
|
}
|
|
1919
2079
|
|
|
1920
|
-
export { Component,
|
|
2080
|
+
export { Component, DynamicRef, ElementNamespaceMap, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, computed, createContext, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withMemo };
|
package/bundles/index.js
CHANGED
|
@@ -4,7 +4,12 @@ require('reflect-metadata');
|
|
|
4
4
|
|
|
5
5
|
class ForwardRef {
|
|
6
6
|
constructor(forwardRefFn) {
|
|
7
|
-
this
|
|
7
|
+
Object.defineProperty(this, "forwardRefFn", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: forwardRefFn
|
|
12
|
+
});
|
|
8
13
|
}
|
|
9
14
|
getRef() {
|
|
10
15
|
return this.forwardRefFn();
|
|
@@ -23,9 +28,24 @@ function forwardRef(fn) {
|
|
|
23
28
|
*/
|
|
24
29
|
class Annotations {
|
|
25
30
|
constructor() {
|
|
26
|
-
this
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
Object.defineProperty(this, "classes", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: new Map()
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "props", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: new Map()
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "params", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: new Map()
|
|
48
|
+
});
|
|
29
49
|
}
|
|
30
50
|
setClassMetadata(token, params) {
|
|
31
51
|
this.classes.set(token, params);
|
|
@@ -112,7 +132,12 @@ function getAnnotations(target) {
|
|
|
112
132
|
|
|
113
133
|
class Scope {
|
|
114
134
|
constructor(name) {
|
|
115
|
-
this
|
|
135
|
+
Object.defineProperty(this, "name", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
configurable: true,
|
|
138
|
+
writable: true,
|
|
139
|
+
value: name
|
|
140
|
+
});
|
|
116
141
|
}
|
|
117
142
|
toString() {
|
|
118
143
|
return this.name || '[anonymous provide scope]';
|
|
@@ -136,7 +161,12 @@ const Injectable = function InjectableDecorator(options) {
|
|
|
136
161
|
/* eslint-disable-next-line */
|
|
137
162
|
class InjectionToken {
|
|
138
163
|
constructor(description) {
|
|
139
|
-
this
|
|
164
|
+
Object.defineProperty(this, "description", {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
configurable: true,
|
|
167
|
+
writable: true,
|
|
168
|
+
value: description
|
|
169
|
+
});
|
|
140
170
|
}
|
|
141
171
|
toString() {
|
|
142
172
|
return this.description || '[anonymous injection token]';
|
|
@@ -238,7 +268,12 @@ const nullInjectorErrorFn = (token) => {
|
|
|
238
268
|
};
|
|
239
269
|
class NullInjector {
|
|
240
270
|
constructor() {
|
|
241
|
-
this
|
|
271
|
+
Object.defineProperty(this, "parentInjector", {
|
|
272
|
+
enumerable: true,
|
|
273
|
+
configurable: true,
|
|
274
|
+
writable: true,
|
|
275
|
+
value: null
|
|
276
|
+
});
|
|
242
277
|
}
|
|
243
278
|
/* eslint-disable-next-line */
|
|
244
279
|
get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
|
|
@@ -414,9 +449,30 @@ const provideScopeError = (token) => {
|
|
|
414
449
|
*/
|
|
415
450
|
class ReflectiveInjector {
|
|
416
451
|
constructor(parentInjector, staticProviders, scope) {
|
|
417
|
-
this
|
|
418
|
-
|
|
419
|
-
|
|
452
|
+
Object.defineProperty(this, "parentInjector", {
|
|
453
|
+
enumerable: true,
|
|
454
|
+
configurable: true,
|
|
455
|
+
writable: true,
|
|
456
|
+
value: parentInjector
|
|
457
|
+
});
|
|
458
|
+
Object.defineProperty(this, "scope", {
|
|
459
|
+
enumerable: true,
|
|
460
|
+
configurable: true,
|
|
461
|
+
writable: true,
|
|
462
|
+
value: scope
|
|
463
|
+
});
|
|
464
|
+
Object.defineProperty(this, "normalizedProviders", {
|
|
465
|
+
enumerable: true,
|
|
466
|
+
configurable: true,
|
|
467
|
+
writable: true,
|
|
468
|
+
value: void 0
|
|
469
|
+
});
|
|
470
|
+
Object.defineProperty(this, "recordValues", {
|
|
471
|
+
enumerable: true,
|
|
472
|
+
configurable: true,
|
|
473
|
+
writable: true,
|
|
474
|
+
value: new Map()
|
|
475
|
+
});
|
|
420
476
|
this.normalizedProviders = staticProviders.map(provide => {
|
|
421
477
|
return normalizeProvider(provide);
|
|
422
478
|
});
|
|
@@ -622,8 +678,18 @@ const ComponentAtomType = Symbol('Component');
|
|
|
622
678
|
|
|
623
679
|
class Listener {
|
|
624
680
|
constructor(effect) {
|
|
625
|
-
this
|
|
626
|
-
|
|
681
|
+
Object.defineProperty(this, "effect", {
|
|
682
|
+
enumerable: true,
|
|
683
|
+
configurable: true,
|
|
684
|
+
writable: true,
|
|
685
|
+
value: effect
|
|
686
|
+
});
|
|
687
|
+
Object.defineProperty(this, "destroyCallbacks", {
|
|
688
|
+
enumerable: true,
|
|
689
|
+
configurable: true,
|
|
690
|
+
writable: true,
|
|
691
|
+
value: []
|
|
692
|
+
});
|
|
627
693
|
}
|
|
628
694
|
destroy() {
|
|
629
695
|
this.destroyCallbacks.forEach(fn => fn());
|
|
@@ -734,9 +800,24 @@ function onUnmounted(callback) {
|
|
|
734
800
|
|
|
735
801
|
class DynamicRef {
|
|
736
802
|
constructor(callback) {
|
|
737
|
-
this
|
|
738
|
-
|
|
739
|
-
|
|
803
|
+
Object.defineProperty(this, "callback", {
|
|
804
|
+
enumerable: true,
|
|
805
|
+
configurable: true,
|
|
806
|
+
writable: true,
|
|
807
|
+
value: callback
|
|
808
|
+
});
|
|
809
|
+
Object.defineProperty(this, "unBindMap", {
|
|
810
|
+
enumerable: true,
|
|
811
|
+
configurable: true,
|
|
812
|
+
writable: true,
|
|
813
|
+
value: new Map()
|
|
814
|
+
});
|
|
815
|
+
Object.defineProperty(this, "targetCaches", {
|
|
816
|
+
enumerable: true,
|
|
817
|
+
configurable: true,
|
|
818
|
+
writable: true,
|
|
819
|
+
value: new Set()
|
|
820
|
+
});
|
|
740
821
|
}
|
|
741
822
|
bind(value) {
|
|
742
823
|
if (typeof value !== 'object' || value === null) {
|
|
@@ -795,6 +876,12 @@ class StaticRef extends DynamicRef {
|
|
|
795
876
|
isInit = true;
|
|
796
877
|
}
|
|
797
878
|
});
|
|
879
|
+
Object.defineProperty(this, "current", {
|
|
880
|
+
enumerable: true,
|
|
881
|
+
configurable: true,
|
|
882
|
+
writable: true,
|
|
883
|
+
value: void 0
|
|
884
|
+
});
|
|
798
885
|
Object.defineProperty(this, 'current', {
|
|
799
886
|
get() {
|
|
800
887
|
if (value === initValue) {
|
|
@@ -827,7 +914,7 @@ function toRefs(ref) {
|
|
|
827
914
|
/**
|
|
828
915
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
|
829
916
|
*/
|
|
830
|
-
class Component
|
|
917
|
+
class Component {
|
|
831
918
|
get dirty() {
|
|
832
919
|
return this._dirty;
|
|
833
920
|
}
|
|
@@ -835,23 +922,109 @@ class Component extends ReflectiveInjector {
|
|
|
835
922
|
return this._changed;
|
|
836
923
|
}
|
|
837
924
|
constructor(parentComponent, type, props, key) {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
this
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
this
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
925
|
+
Object.defineProperty(this, "parentComponent", {
|
|
926
|
+
enumerable: true,
|
|
927
|
+
configurable: true,
|
|
928
|
+
writable: true,
|
|
929
|
+
value: parentComponent
|
|
930
|
+
});
|
|
931
|
+
Object.defineProperty(this, "type", {
|
|
932
|
+
enumerable: true,
|
|
933
|
+
configurable: true,
|
|
934
|
+
writable: true,
|
|
935
|
+
value: type
|
|
936
|
+
});
|
|
937
|
+
Object.defineProperty(this, "props", {
|
|
938
|
+
enumerable: true,
|
|
939
|
+
configurable: true,
|
|
940
|
+
writable: true,
|
|
941
|
+
value: props
|
|
942
|
+
});
|
|
943
|
+
Object.defineProperty(this, "key", {
|
|
944
|
+
enumerable: true,
|
|
945
|
+
configurable: true,
|
|
946
|
+
writable: true,
|
|
947
|
+
value: key
|
|
948
|
+
});
|
|
949
|
+
Object.defineProperty(this, "instance", {
|
|
950
|
+
enumerable: true,
|
|
951
|
+
configurable: true,
|
|
952
|
+
writable: true,
|
|
953
|
+
value: void 0
|
|
954
|
+
});
|
|
955
|
+
Object.defineProperty(this, "changedSubComponents", {
|
|
956
|
+
enumerable: true,
|
|
957
|
+
configurable: true,
|
|
958
|
+
writable: true,
|
|
959
|
+
value: new Set()
|
|
960
|
+
});
|
|
961
|
+
Object.defineProperty(this, "unmountedCallbacks", {
|
|
962
|
+
enumerable: true,
|
|
963
|
+
configurable: true,
|
|
964
|
+
writable: true,
|
|
965
|
+
value: void 0
|
|
966
|
+
});
|
|
967
|
+
Object.defineProperty(this, "mountCallbacks", {
|
|
968
|
+
enumerable: true,
|
|
969
|
+
configurable: true,
|
|
970
|
+
writable: true,
|
|
971
|
+
value: void 0
|
|
972
|
+
});
|
|
973
|
+
Object.defineProperty(this, "propsChangedCallbacks", {
|
|
974
|
+
enumerable: true,
|
|
975
|
+
configurable: true,
|
|
976
|
+
writable: true,
|
|
977
|
+
value: void 0
|
|
978
|
+
});
|
|
979
|
+
Object.defineProperty(this, "updatedCallbacks", {
|
|
980
|
+
enumerable: true,
|
|
981
|
+
configurable: true,
|
|
982
|
+
writable: true,
|
|
983
|
+
value: void 0
|
|
984
|
+
});
|
|
985
|
+
Object.defineProperty(this, "updatedDestroyCallbacks", {
|
|
986
|
+
enumerable: true,
|
|
987
|
+
configurable: true,
|
|
988
|
+
writable: true,
|
|
989
|
+
value: void 0
|
|
990
|
+
});
|
|
991
|
+
Object.defineProperty(this, "propsChangedDestroyCallbacks", {
|
|
992
|
+
enumerable: true,
|
|
993
|
+
configurable: true,
|
|
994
|
+
writable: true,
|
|
995
|
+
value: void 0
|
|
996
|
+
});
|
|
997
|
+
Object.defineProperty(this, "_dirty", {
|
|
998
|
+
enumerable: true,
|
|
999
|
+
configurable: true,
|
|
1000
|
+
writable: true,
|
|
1001
|
+
value: true
|
|
1002
|
+
});
|
|
1003
|
+
Object.defineProperty(this, "_changed", {
|
|
1004
|
+
enumerable: true,
|
|
1005
|
+
configurable: true,
|
|
1006
|
+
writable: true,
|
|
1007
|
+
value: true
|
|
1008
|
+
});
|
|
1009
|
+
Object.defineProperty(this, "isFirstRendering", {
|
|
1010
|
+
enumerable: true,
|
|
1011
|
+
configurable: true,
|
|
1012
|
+
writable: true,
|
|
1013
|
+
value: true
|
|
1014
|
+
});
|
|
1015
|
+
Object.defineProperty(this, "refs", {
|
|
1016
|
+
enumerable: true,
|
|
1017
|
+
configurable: true,
|
|
1018
|
+
writable: true,
|
|
1019
|
+
value: null
|
|
1020
|
+
});
|
|
1021
|
+
Object.defineProperty(this, "listener", {
|
|
1022
|
+
enumerable: true,
|
|
1023
|
+
configurable: true,
|
|
1024
|
+
writable: true,
|
|
1025
|
+
value: new Listener(() => {
|
|
1026
|
+
this.markAsDirtied();
|
|
1027
|
+
})
|
|
855
1028
|
});
|
|
856
1029
|
}
|
|
857
1030
|
markAsDirtied() {
|
|
@@ -954,10 +1127,6 @@ class Component extends ReflectiveInjector {
|
|
|
954
1127
|
updateChildren(template);
|
|
955
1128
|
this.rendered();
|
|
956
1129
|
}
|
|
957
|
-
provide(providers) {
|
|
958
|
-
providers = Array.isArray(providers) ? providers : [providers];
|
|
959
|
-
this.normalizedProviders.unshift(...providers.map(i => normalizeProvider(i)));
|
|
960
|
-
}
|
|
961
1130
|
destroy() {
|
|
962
1131
|
var _a, _b, _c;
|
|
963
1132
|
this.listener.destroy();
|
|
@@ -974,13 +1143,12 @@ class Component extends ReflectiveInjector {
|
|
|
974
1143
|
this.parentComponent.changedSubComponents.delete(this);
|
|
975
1144
|
}
|
|
976
1145
|
this.parentComponent =
|
|
977
|
-
this.
|
|
978
|
-
this.
|
|
979
|
-
this.
|
|
980
|
-
this.
|
|
981
|
-
this.
|
|
982
|
-
this.
|
|
983
|
-
this.unmountedCallbacks = null;
|
|
1146
|
+
this.propsChangedDestroyCallbacks =
|
|
1147
|
+
this.updatedDestroyCallbacks =
|
|
1148
|
+
this.mountCallbacks =
|
|
1149
|
+
this.updatedCallbacks =
|
|
1150
|
+
this.propsChangedCallbacks =
|
|
1151
|
+
this.unmountedCallbacks = null;
|
|
984
1152
|
this.changedSubComponents.clear();
|
|
985
1153
|
}
|
|
986
1154
|
rendered() {
|
|
@@ -1058,43 +1226,44 @@ class Component extends ReflectiveInjector {
|
|
|
1058
1226
|
}
|
|
1059
1227
|
}
|
|
1060
1228
|
/**
|
|
1061
|
-
*
|
|
1062
|
-
* @param annotation
|
|
1063
|
-
* @param componentSetup
|
|
1064
|
-
* @example
|
|
1065
|
-
* ```ts
|
|
1066
|
-
* export customScope = new Scope('scopeName')
|
|
1067
|
-
* export const App = withAnnotation({
|
|
1068
|
-
* scope: customScope,
|
|
1069
|
-
* providers: [
|
|
1070
|
-
* ExampleService
|
|
1071
|
-
* ]
|
|
1072
|
-
* }, function(props: Props) {
|
|
1073
|
-
* return () => {
|
|
1074
|
-
* return <div>...</div>
|
|
1075
|
-
* }
|
|
1076
|
-
* })
|
|
1077
|
-
* ```
|
|
1229
|
+
* 获取当前组件实例
|
|
1078
1230
|
*/
|
|
1079
|
-
function
|
|
1080
|
-
|
|
1081
|
-
|
|
1231
|
+
function getCurrentInstance() {
|
|
1232
|
+
return getSetupContext();
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
const injectMap = new WeakMap();
|
|
1236
|
+
function getParentInjector(component) {
|
|
1237
|
+
let start = component.parentComponent;
|
|
1238
|
+
while (start) {
|
|
1239
|
+
const injector = injectMap.get(start);
|
|
1240
|
+
if (injector) {
|
|
1241
|
+
return injector;
|
|
1242
|
+
}
|
|
1243
|
+
start = start.parentComponent;
|
|
1244
|
+
}
|
|
1245
|
+
return new NullInjector();
|
|
1246
|
+
}
|
|
1247
|
+
function createContext(providers, scope, parentInjector) {
|
|
1248
|
+
return function context(props) {
|
|
1249
|
+
const instance = getCurrentInstance();
|
|
1250
|
+
const injector = new ReflectiveInjector(parentInjector || getParentInjector(instance), providers, scope);
|
|
1251
|
+
injectMap.set(instance, injector);
|
|
1252
|
+
return () => {
|
|
1253
|
+
return props.children;
|
|
1254
|
+
};
|
|
1082
1255
|
};
|
|
1083
|
-
setup.annotation = annotation;
|
|
1084
|
-
return setup;
|
|
1085
1256
|
}
|
|
1086
1257
|
/**
|
|
1087
1258
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1088
1259
|
*/
|
|
1089
1260
|
function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
1090
|
-
const component =
|
|
1091
|
-
|
|
1261
|
+
const component = getCurrentInstance();
|
|
1262
|
+
const injector = getParentInjector(component);
|
|
1263
|
+
return injector.get(token, notFoundValue, flags);
|
|
1092
1264
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
*/
|
|
1096
|
-
function getCurrentInstance() {
|
|
1097
|
-
return getSetupContext();
|
|
1265
|
+
|
|
1266
|
+
class NativeRenderer {
|
|
1098
1267
|
}
|
|
1099
1268
|
|
|
1100
1269
|
function Fragment(props) {
|
|
@@ -1116,33 +1285,6 @@ const JSXNodeFactory = {
|
|
|
1116
1285
|
}
|
|
1117
1286
|
};
|
|
1118
1287
|
|
|
1119
|
-
function Context(props) {
|
|
1120
|
-
function createContextComponent(providers) {
|
|
1121
|
-
return withAnnotation({
|
|
1122
|
-
providers,
|
|
1123
|
-
}, (childProps) => {
|
|
1124
|
-
return () => {
|
|
1125
|
-
return childProps.children;
|
|
1126
|
-
};
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
let contextComponent = createContextComponent(props.providers);
|
|
1130
|
-
onPropsChanged((newProps, oldProps) => {
|
|
1131
|
-
if (newProps.providers === oldProps.providers) {
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
contextComponent = createContextComponent(newProps.providers);
|
|
1135
|
-
});
|
|
1136
|
-
return () => {
|
|
1137
|
-
return jsx(contextComponent, {
|
|
1138
|
-
children: props.children
|
|
1139
|
-
});
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
class NativeRenderer {
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
1288
|
function withMemo(canUseMemo, render) {
|
|
1147
1289
|
return {
|
|
1148
1290
|
$useMemo: canUseMemo,
|
|
@@ -1230,9 +1372,8 @@ function applyChanges(nativeRenderer, component, atom, context, needMove) {
|
|
|
1230
1372
|
view.host = context.host;
|
|
1231
1373
|
view.isParent = context.isParent;
|
|
1232
1374
|
}
|
|
1233
|
-
}, () => {
|
|
1234
|
-
|
|
1235
|
-
//
|
|
1375
|
+
}, (skipSubComponentDiff) => {
|
|
1376
|
+
reuseComponentView(nativeRenderer, atom, context, needMove, skipSubComponentDiff);
|
|
1236
1377
|
});
|
|
1237
1378
|
}
|
|
1238
1379
|
function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, needMove) {
|
|
@@ -1402,27 +1543,31 @@ function cleanElementChildren(atom, nativeRenderer) {
|
|
|
1402
1543
|
}
|
|
1403
1544
|
}
|
|
1404
1545
|
function cleanView(nativeRenderer, atom, needClean) {
|
|
1405
|
-
if (atom.
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
needClean =
|
|
1409
|
-
}
|
|
1410
|
-
if (atom.type === ElementAtomType) {
|
|
1411
|
-
const ref = atom.jsxNode.props[refKey];
|
|
1412
|
-
applyRefs(ref, atom.nativeNode, false);
|
|
1546
|
+
if (atom.type === ComponentAtomType) {
|
|
1547
|
+
const jsxNode = atom.jsxNode;
|
|
1548
|
+
if (jsxNode.instance.$portalHost) {
|
|
1549
|
+
needClean = true;
|
|
1413
1550
|
}
|
|
1551
|
+
cleanChildren(atom, nativeRenderer, needClean);
|
|
1552
|
+
jsxNode.destroy();
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
if (needClean) {
|
|
1556
|
+
nativeRenderer.remove(atom.nativeNode, atom.namespace);
|
|
1557
|
+
needClean = false;
|
|
1414
1558
|
}
|
|
1559
|
+
if (atom.type === ElementAtomType) {
|
|
1560
|
+
const ref = atom.jsxNode.props[refKey];
|
|
1561
|
+
applyRefs(ref, atom.nativeNode, false);
|
|
1562
|
+
}
|
|
1563
|
+
cleanChildren(atom, nativeRenderer, needClean);
|
|
1564
|
+
}
|
|
1565
|
+
function cleanChildren(atom, nativeRenderer, needClean) {
|
|
1415
1566
|
let child = atom.child;
|
|
1416
1567
|
while (child) {
|
|
1417
|
-
if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
|
|
1418
|
-
needClean = true;
|
|
1419
|
-
}
|
|
1420
1568
|
cleanView(nativeRenderer, child, needClean);
|
|
1421
1569
|
child = child.sibling;
|
|
1422
1570
|
}
|
|
1423
|
-
if (atom.jsxNode instanceof Component) {
|
|
1424
|
-
atom.jsxNode.destroy();
|
|
1425
|
-
}
|
|
1426
1571
|
}
|
|
1427
1572
|
function componentRender(nativeRenderer, component, from, context) {
|
|
1428
1573
|
component.render((template, portalHost) => {
|
|
@@ -1475,7 +1620,9 @@ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
|
1475
1620
|
return prevAtom;
|
|
1476
1621
|
}
|
|
1477
1622
|
function createChainByChildren(children, prevAtom, elementNamespace) {
|
|
1478
|
-
|
|
1623
|
+
const len = children.length;
|
|
1624
|
+
for (let i = 0; i < len; i++) {
|
|
1625
|
+
const item = children[i];
|
|
1479
1626
|
prevAtom = createChainByNode(item, prevAtom, elementNamespace);
|
|
1480
1627
|
}
|
|
1481
1628
|
return prevAtom;
|
|
@@ -1567,7 +1714,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1567
1714
|
let unBindRefs;
|
|
1568
1715
|
let bindRefs;
|
|
1569
1716
|
let updatedChildren = false;
|
|
1570
|
-
|
|
1717
|
+
let len = changes.remove.length;
|
|
1718
|
+
for (let i = 0; i < len; i++) {
|
|
1719
|
+
const [key, value] = changes.remove[i];
|
|
1571
1720
|
if (key === 'children') {
|
|
1572
1721
|
updatedChildren = true;
|
|
1573
1722
|
cleanElementChildren(oldAtom, nativeRenderer);
|
|
@@ -1595,7 +1744,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1595
1744
|
}
|
|
1596
1745
|
nativeRenderer.removeProperty(nativeNode, key, isSvg);
|
|
1597
1746
|
}
|
|
1598
|
-
|
|
1747
|
+
len = changes.replace.length;
|
|
1748
|
+
for (let i = 0; i < len; i++) {
|
|
1749
|
+
const [key, newValue, oldValue] = changes.replace[i];
|
|
1599
1750
|
if (key === 'children') {
|
|
1600
1751
|
updatedChildren = true;
|
|
1601
1752
|
newAtom.child = createChildChain(newValue, isSvg);
|
|
@@ -1640,7 +1791,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1640
1791
|
}
|
|
1641
1792
|
nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
|
|
1642
1793
|
}
|
|
1643
|
-
|
|
1794
|
+
len = changes.add.length;
|
|
1795
|
+
for (let i = 0; i < len; i++) {
|
|
1796
|
+
const [key, value] = changes.add[i];
|
|
1644
1797
|
if (key === 'children') {
|
|
1645
1798
|
updatedChildren = true;
|
|
1646
1799
|
newAtom.child = createChildChain(value, isSvg);
|
|
@@ -1680,7 +1833,9 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1680
1833
|
function applyRefs(refs, nativeNode, binding) {
|
|
1681
1834
|
if (refs) {
|
|
1682
1835
|
const refList = Array.isArray(refs) ? refs : [refs];
|
|
1683
|
-
|
|
1836
|
+
const len = refList.length;
|
|
1837
|
+
for (let i = 0; i < len; i++) {
|
|
1838
|
+
const item = refList[i];
|
|
1684
1839
|
if (item instanceof DynamicRef) {
|
|
1685
1840
|
binding ? item.bind(nativeNode) : item.unBind(nativeNode);
|
|
1686
1841
|
}
|
|
@@ -1692,9 +1847,14 @@ function applyRefs(refs, nativeNode, binding) {
|
|
|
1692
1847
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
1693
1848
|
*/
|
|
1694
1849
|
class RootComponent extends Component {
|
|
1695
|
-
constructor(
|
|
1696
|
-
super(
|
|
1697
|
-
this
|
|
1850
|
+
constructor(factory, refresh) {
|
|
1851
|
+
super(null, factory, {});
|
|
1852
|
+
Object.defineProperty(this, "refresh", {
|
|
1853
|
+
enumerable: true,
|
|
1854
|
+
configurable: true,
|
|
1855
|
+
writable: true,
|
|
1856
|
+
value: refresh
|
|
1857
|
+
});
|
|
1698
1858
|
}
|
|
1699
1859
|
markAsChanged(changedComponent) {
|
|
1700
1860
|
this._changed = true;
|
|
@@ -1838,16 +1998,15 @@ function viewfly(config) {
|
|
|
1838
1998
|
const modules = [];
|
|
1839
1999
|
let destroyed = false;
|
|
1840
2000
|
let appHost = null;
|
|
1841
|
-
const
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
useValue: nativeRenderer
|
|
1845
|
-
}]
|
|
1846
|
-
}, () => {
|
|
2001
|
+
const rootProviders = [];
|
|
2002
|
+
const rootComponent = new RootComponent(() => {
|
|
2003
|
+
const rootContext = createContext(rootProviders, void 0, context);
|
|
1847
2004
|
return () => {
|
|
1848
|
-
return
|
|
2005
|
+
return jsx(rootContext, {
|
|
2006
|
+
children: destroyed ? null : root
|
|
2007
|
+
});
|
|
1849
2008
|
};
|
|
1850
|
-
}
|
|
2009
|
+
}, function () {
|
|
1851
2010
|
if (destroyed || !autoUpdate) {
|
|
1852
2011
|
return;
|
|
1853
2012
|
}
|
|
@@ -1869,7 +2028,8 @@ function viewfly(config) {
|
|
|
1869
2028
|
}
|
|
1870
2029
|
const app = {
|
|
1871
2030
|
provide(providers) {
|
|
1872
|
-
|
|
2031
|
+
providers = Array.isArray(providers) ? providers : [providers];
|
|
2032
|
+
rootProviders.push(...providers);
|
|
1873
2033
|
return app;
|
|
1874
2034
|
},
|
|
1875
2035
|
use(module) {
|
|
@@ -1920,7 +2080,6 @@ function viewfly(config) {
|
|
|
1920
2080
|
}
|
|
1921
2081
|
|
|
1922
2082
|
exports.Component = Component;
|
|
1923
|
-
exports.Context = Context;
|
|
1924
2083
|
exports.DynamicRef = DynamicRef;
|
|
1925
2084
|
exports.ElementNamespaceMap = ElementNamespaceMap;
|
|
1926
2085
|
exports.ForwardRef = ForwardRef;
|
|
@@ -1943,6 +2102,7 @@ exports.StaticRef = StaticRef;
|
|
|
1943
2102
|
exports.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
|
|
1944
2103
|
exports.Type = Type;
|
|
1945
2104
|
exports.computed = computed;
|
|
2105
|
+
exports.createContext = createContext;
|
|
1946
2106
|
exports.createDerived = createDerived;
|
|
1947
2107
|
exports.createDynamicRef = createDynamicRef;
|
|
1948
2108
|
exports.createRef = createRef;
|
|
@@ -1962,5 +2122,4 @@ exports.onUnmounted = onUnmounted;
|
|
|
1962
2122
|
exports.onUpdated = onUpdated;
|
|
1963
2123
|
exports.viewfly = viewfly;
|
|
1964
2124
|
exports.watch = watch;
|
|
1965
|
-
exports.withAnnotation = withAnnotation;
|
|
1966
2125
|
exports.withMemo = withMemo;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"bugs": {
|
|
51
51
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5fdcdcdca224d1eecdfd6a68abb1c3fb9c01d88a",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"reflect-metadata": "^0.2.2"
|
|
56
56
|
}
|