zova-core 5.1.89 → 5.1.91
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/bean/beanContainer.d.ts.map +1 -1
- package/dist/bean/resource/error/type.d.ts +8 -0
- package/dist/bean/resource/error/type.d.ts.map +1 -1
- package/dist/bean/type.d.ts +15 -0
- package/dist/bean/type.d.ts.map +1 -1
- package/dist/components/component.d.ts +6 -1
- package/dist/components/component.d.ts.map +1 -1
- package/dist/composables/useController.d.ts.map +1 -1
- package/dist/core/component/error.d.ts +7 -0
- package/dist/core/component/error.d.ts.map +1 -1
- package/dist/core/context/component.d.ts +2 -0
- package/dist/core/context/component.d.ts.map +1 -1
- package/dist/core/context/hooks.d.ts +3 -2
- package/dist/core/context/hooks.d.ts.map +1 -1
- package/dist/core/context/meta.d.ts.map +1 -1
- package/dist/core/context/state.d.ts +42 -0
- package/dist/core/context/state.d.ts.map +1 -1
- package/dist/core/sys/config.d.ts +19 -7
- package/dist/core/sys/config.d.ts.map +1 -1
- package/dist/index.js +484 -126
- package/dist/index.js.map +1 -1
- package/dist/types/interface/monkey.d.ts +13 -0
- package/dist/types/interface/monkey.d.ts.map +1 -1
- package/dist/types/utils/powerPartial.d.ts +1 -1
- package/dist/types/utils/powerPartial.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/bean/beanBase.ts +1 -1
- package/src/bean/beanContainer.ts +99 -39
- package/src/bean/resource/error/type.ts +9 -0
- package/src/bean/type.ts +18 -0
- package/src/components/component.ts +2 -1
- package/src/composables/useController.ts +158 -25
- package/src/core/component/error.ts +62 -5
- package/src/core/context/component.ts +37 -2
- package/src/core/context/hooks.ts +13 -2
- package/src/core/context/meta.ts +1 -0
- package/src/core/context/state.ts +161 -0
- package/src/core/sys/config.ts +32 -7
- package/src/types/interface/monkey.ts +15 -0
- package/src/types/utils/powerPartial.ts +1 -1
|
@@ -4,6 +4,7 @@ import type { BeanContainer } from '../../bean/beanContainer.ts';
|
|
|
4
4
|
import type { IControllerData } from '../../bean/type.ts';
|
|
5
5
|
import type { ZovaApplication } from '../../core/app/application.ts';
|
|
6
6
|
import type { ZovaContext } from '../../core/context/context.ts';
|
|
7
|
+
import type { Constructable } from '../../decorator/type/constructable.ts';
|
|
7
8
|
export type TypeMonkeyName = keyof IMonkeyModuleSys | keyof IMonkeySys | keyof IMonkeyApp | keyof IMonkeyController;
|
|
8
9
|
export interface IModuleMain {
|
|
9
10
|
moduleLoading(): Promise<void>;
|
|
@@ -27,10 +28,22 @@ export interface IMonkeySys extends IMonkeySysApplicationInitialize, IMonkeySysC
|
|
|
27
28
|
}
|
|
28
29
|
export interface IMonkeyApp extends IMonkeyAppContextInitialize, IMonkeyAppInitialize, IMonkeyAppInitialized, IMonkeyAppReady, IMonkeyAppClose, IMonkeyBeanInit, IMonkeyBeanInited, IMonkeyBeanDispose, IMonkeyBeanDisposed {
|
|
29
30
|
}
|
|
31
|
+
export type ControllerLoadPhase = 'prepare' | 'fallback' | 'replay';
|
|
32
|
+
export interface IControllerLoadEvent {
|
|
33
|
+
phase: ControllerLoadPhase;
|
|
34
|
+
ctx: ZovaContext;
|
|
35
|
+
controllerBeanFullName: Constructable | string;
|
|
36
|
+
controllerBeanName?: string;
|
|
37
|
+
error?: Error;
|
|
38
|
+
controllerRecorded?: boolean;
|
|
39
|
+
replayError?: Error;
|
|
40
|
+
replayControllerRecorded?: boolean;
|
|
41
|
+
}
|
|
30
42
|
export interface IMonkeyController {
|
|
31
43
|
controllerDataPrepare(controllerData: IControllerData, ctx: ZovaContext): void;
|
|
32
44
|
controllerDataInit(controllerData: IControllerData, controller: BeanBase): void;
|
|
33
45
|
controllerDataUpdate(controller: BeanBase): void;
|
|
46
|
+
controllerLoad?(event: IControllerLoadEvent): void;
|
|
34
47
|
}
|
|
35
48
|
export interface IMonkeySysApplicationInitialize {
|
|
36
49
|
sysApplicationInitialize(app: ZovaApplication): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monkey.d.ts","sourceRoot":"","sources":["../../../src/types/interface/monkey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"monkey.d.ts","sourceRoot":"","sources":["../../../src/types/interface/monkey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,MAAM,MAAM,cAAc,GACtB,MAAM,gBAAgB,GACtB,MAAM,UAAU,GAChB,MAAM,UAAU,GAChB,MAAM,iBAAiB,CAAC;AAE5B,MAAM,WAAW,WAAW;IAC1B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,YAAY,IAAI,OAAO,C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AAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChE;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,GAAG,IAAI,CAAC;CACjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powerPartial.d.ts","sourceRoot":"","sources":["../../../src/types/utils/powerPartial.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"powerPartial.d.ts","sourceRoot":"","sources":["../../../src/types/utils/powerPartial.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChG,CAAC"}
|
package/package.json
CHANGED
package/src/bean/beanBase.ts
CHANGED
|
@@ -192,7 +192,7 @@ export class BeanBase extends BeanBaseSimple {
|
|
|
192
192
|
|
|
193
193
|
protected $controllerMounted(fn: any) {
|
|
194
194
|
return this.ctx.util.instanceScope(() => {
|
|
195
|
-
return this.ctx.meta.hooks.onMounted(fn);
|
|
195
|
+
return this.ctx.meta.hooks.onMounted(fn, this);
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -74,50 +74,90 @@ export class BeanContainer {
|
|
|
74
74
|
/** @internal */
|
|
75
75
|
public dispose() {
|
|
76
76
|
const beanInstances = this[SymbolBeanContainerInstances];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this
|
|
103
|
-
|
|
104
|
-
|
|
77
|
+
let error: Error | undefined;
|
|
78
|
+
try {
|
|
79
|
+
for (const prop in beanInstances) {
|
|
80
|
+
if (prop.startsWith('$$')) continue;
|
|
81
|
+
const beanInstance = cast(beanInstances[prop]);
|
|
82
|
+
if (!beanInstance || beanInstance instanceof BeanAopBase || !beanInstance.__dispose__)
|
|
83
|
+
continue;
|
|
84
|
+
try {
|
|
85
|
+
if (this.containerType === 'sys') {
|
|
86
|
+
this.sys.meta.module._monkeyModuleSync(
|
|
87
|
+
false,
|
|
88
|
+
'beanDispose',
|
|
89
|
+
undefined,
|
|
90
|
+
this,
|
|
91
|
+
beanInstance,
|
|
92
|
+
);
|
|
93
|
+
beanInstance.__dispose__();
|
|
94
|
+
this.sys.meta.module._monkeyModuleSync(
|
|
95
|
+
false,
|
|
96
|
+
'beanDisposed',
|
|
97
|
+
undefined,
|
|
98
|
+
this,
|
|
99
|
+
beanInstance,
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
this.app.meta.module._monkeyModuleSync(
|
|
103
|
+
false,
|
|
104
|
+
'beanDispose',
|
|
105
|
+
undefined,
|
|
106
|
+
this,
|
|
107
|
+
beanInstance,
|
|
108
|
+
);
|
|
109
|
+
this.runWithInstanceScopeOrAppContext(() => {
|
|
110
|
+
return beanInstance.__dispose__();
|
|
111
|
+
});
|
|
112
|
+
this.app.meta.module._monkeyModuleSync(
|
|
113
|
+
false,
|
|
114
|
+
'beanDisposed',
|
|
115
|
+
undefined,
|
|
116
|
+
this,
|
|
117
|
+
beanInstance,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
} catch (err) {
|
|
121
|
+
error ??= err as Error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} finally {
|
|
125
|
+
this[SymbolBeanContainerInstances] = shallowReactive({});
|
|
126
|
+
this[SymbolBeanContainerParent] = undefined;
|
|
127
|
+
this[SymbolGetBeanSelectorInnerPromises] = {};
|
|
128
|
+
}
|
|
129
|
+
// eslint-disable no-throw-literal
|
|
130
|
+
if (error) throw error;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** @internal */
|
|
134
|
+
public retryReset(ownedBeans: Set<object>) {
|
|
135
|
+
const beanInstances = this[SymbolBeanContainerInstances];
|
|
136
|
+
let error: Error | undefined;
|
|
137
|
+
try {
|
|
138
|
+
for (const prop in beanInstances) {
|
|
139
|
+
const beanInstance = cast(beanInstances[prop]);
|
|
140
|
+
if (!ownedBeans.has(beanInstance)) continue;
|
|
141
|
+
if (!beanInstance || beanInstance instanceof BeanAopBase || !beanInstance.__dispose__)
|
|
142
|
+
continue;
|
|
143
|
+
try {
|
|
105
144
|
this.runWithInstanceScopeOrAppContext(() => {
|
|
106
145
|
return beanInstance.__dispose__();
|
|
107
146
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
'beanDisposed',
|
|
111
|
-
undefined,
|
|
112
|
-
this,
|
|
113
|
-
beanInstance,
|
|
114
|
-
);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
error ??= err as Error;
|
|
115
149
|
}
|
|
116
150
|
}
|
|
151
|
+
} finally {
|
|
152
|
+
for (const prop in beanInstances) {
|
|
153
|
+
if (ownedBeans.has(cast(beanInstances[prop]))) {
|
|
154
|
+
delete beanInstances[prop];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
this[SymbolGetBeanSelectorInnerPromises] = {};
|
|
117
158
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this[SymbolGetBeanSelectorInnerPromises] = {};
|
|
159
|
+
// eslint-disable no-throw-literal
|
|
160
|
+
if (error) throw error;
|
|
121
161
|
}
|
|
122
162
|
|
|
123
163
|
get containerType(): ContainerType {
|
|
@@ -355,6 +395,7 @@ export class BeanContainer {
|
|
|
355
395
|
fullName,
|
|
356
396
|
markReactive,
|
|
357
397
|
withSelector,
|
|
398
|
+
undefined,
|
|
358
399
|
...args,
|
|
359
400
|
);
|
|
360
401
|
}
|
|
@@ -382,7 +423,16 @@ export class BeanContainer {
|
|
|
382
423
|
markReactive?: boolean,
|
|
383
424
|
...args
|
|
384
425
|
): Promise<T> {
|
|
385
|
-
return await this._newBeanInner(
|
|
426
|
+
return await this._newBeanInner(
|
|
427
|
+
false,
|
|
428
|
+
null,
|
|
429
|
+
null,
|
|
430
|
+
beanFullName,
|
|
431
|
+
markReactive,
|
|
432
|
+
false,
|
|
433
|
+
undefined,
|
|
434
|
+
...args,
|
|
435
|
+
);
|
|
386
436
|
}
|
|
387
437
|
|
|
388
438
|
async _newBeanSelector<T>(
|
|
@@ -415,6 +465,7 @@ export class BeanContainer {
|
|
|
415
465
|
beanFullName: Constructable<T> | string | undefined,
|
|
416
466
|
markReactive?: boolean,
|
|
417
467
|
withSelector?: boolean,
|
|
468
|
+
onBeanRecorded?: (beanInstance: T) => void,
|
|
418
469
|
...args
|
|
419
470
|
): Promise<T> {
|
|
420
471
|
// bean options
|
|
@@ -432,11 +483,16 @@ export class BeanContainer {
|
|
|
432
483
|
false,
|
|
433
484
|
markReactive,
|
|
434
485
|
withSelector,
|
|
486
|
+
onBeanRecorded,
|
|
435
487
|
);
|
|
436
488
|
}
|
|
437
489
|
// throw new Error(`bean not found: ${beanFullName}`);
|
|
438
490
|
return null!;
|
|
439
491
|
}
|
|
492
|
+
// controller module: ensure route resources are ready before controller data initialization
|
|
493
|
+
if (controllerData) {
|
|
494
|
+
await this._useModule(beanOptions.module);
|
|
495
|
+
}
|
|
440
496
|
// beanFullName
|
|
441
497
|
return await this._createBeanInstance<T>(
|
|
442
498
|
record,
|
|
@@ -449,6 +505,7 @@ export class BeanContainer {
|
|
|
449
505
|
// default is true: same as inject prop
|
|
450
506
|
markReactive ?? beanOptions.markReactive ?? true,
|
|
451
507
|
withSelector,
|
|
508
|
+
onBeanRecorded,
|
|
452
509
|
);
|
|
453
510
|
}
|
|
454
511
|
|
|
@@ -504,6 +561,7 @@ export class BeanContainer {
|
|
|
504
561
|
aop: boolean | undefined,
|
|
505
562
|
markReactive: boolean | undefined,
|
|
506
563
|
withSelector?: boolean,
|
|
564
|
+
onBeanRecorded?: (beanInstance: T) => void,
|
|
507
565
|
): Promise<T> {
|
|
508
566
|
// prepare
|
|
509
567
|
const beanInstance = await this._prepareBeanInstance(
|
|
@@ -530,6 +588,7 @@ export class BeanContainer {
|
|
|
530
588
|
if (recordProp) {
|
|
531
589
|
this.__recordProp(recordProp, fullName, beanInstance, true);
|
|
532
590
|
}
|
|
591
|
+
onBeanRecorded?.(beanInstance);
|
|
533
592
|
}
|
|
534
593
|
// init
|
|
535
594
|
await this._initBeanInstance(beanFullName, beanInstance, args);
|
|
@@ -781,6 +840,7 @@ export class BeanContainer {
|
|
|
781
840
|
targetBeanFullName,
|
|
782
841
|
markReactive,
|
|
783
842
|
selectorInfo.withSelector,
|
|
843
|
+
undefined,
|
|
784
844
|
...selectorInfo.args,
|
|
785
845
|
);
|
|
786
846
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComponentPublicInstance } from 'vue';
|
|
2
2
|
|
|
3
|
+
import type { ZovaContext } from '../../../core/context/context.ts';
|
|
3
4
|
import type { IErrorObject } from './errorObject.ts';
|
|
4
5
|
|
|
5
6
|
export const SymbolErrorInstanceInfo = Symbol('SymbolErrorInstanceInfo');
|
|
@@ -9,10 +10,18 @@ export interface IErrorInstanceInfo {
|
|
|
9
10
|
info?: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
export interface IErrorHandlerLoad {
|
|
14
|
+
readonly kind: 'controller-load';
|
|
15
|
+
readonly ctx: ZovaContext;
|
|
16
|
+
readonly originalError: unknown;
|
|
17
|
+
disposition: 'fallback' | 'handled';
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
export interface IErrorHandlerEventData {
|
|
13
21
|
err: Error;
|
|
14
22
|
instance?: ComponentPublicInstance | null;
|
|
15
23
|
info?: string;
|
|
24
|
+
load?: IErrorHandlerLoad;
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
export type IErrorHandlerEventResult = Error | undefined;
|
package/src/bean/type.ts
CHANGED
|
@@ -85,8 +85,26 @@ export interface DefineModelOptions<T = any, G = T, S = T> {
|
|
|
85
85
|
set?: (v: S) => any;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
export type TypeComponentBoundaryRenderMode = 'block' | 'inline';
|
|
89
|
+
export type TypeComponentBoundaryRetry = () => Promise<void>;
|
|
90
|
+
|
|
91
|
+
export interface IComponentBoundaryLoadingOptions {
|
|
92
|
+
delay?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface IComponentBoundaryOptions {
|
|
96
|
+
loading?: IComponentBoundaryLoadingOptions;
|
|
97
|
+
renderMode?: TypeComponentBoundaryRenderMode;
|
|
98
|
+
/**
|
|
99
|
+
* Declares that this Controller can safely construct a fresh load graph after a fallback error.
|
|
100
|
+
* It is disabled by default because Controller initialization may include non-idempotent work.
|
|
101
|
+
*/
|
|
102
|
+
retry?: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
88
105
|
export type IComponentOptions = Parameters<typeof defineOptions>[0] & {
|
|
89
106
|
deepExtendDefault?: boolean;
|
|
107
|
+
boundary?: IComponentBoundaryOptions;
|
|
90
108
|
};
|
|
91
109
|
|
|
92
110
|
export type IEmit = () => void;
|
|
@@ -9,11 +9,12 @@ export function createZovaComponentPage<M, R, S>(
|
|
|
9
9
|
controller: Constructable<M>,
|
|
10
10
|
render?: Constructable<R>,
|
|
11
11
|
style?: Constructable<S>,
|
|
12
|
+
componentOptions?: IComponentOptions,
|
|
12
13
|
) {
|
|
13
14
|
return defineComponent(() => {
|
|
14
15
|
useControllerPage(controller, render, style);
|
|
15
16
|
return () => {};
|
|
16
|
-
});
|
|
17
|
+
}, prepareComponentOptions(componentOptions));
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export function prepareComponentOptions(componentOptions?: IComponentOptions) {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
import type { IBeanRecord, IControllerData } from '../bean/type.ts';
|
|
11
11
|
import type { Constructable } from '../decorator/index.ts';
|
|
12
|
+
import type { IControllerLoadEvent } from '../types/interface/monkey.ts';
|
|
12
13
|
|
|
13
14
|
import {
|
|
14
15
|
BeanControllerIdentifier,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
BeanStyleIdentifier,
|
|
17
18
|
SymbolControllerRefDisable,
|
|
18
19
|
} from '../bean/type.ts';
|
|
20
|
+
import { normalizeError } from '../core/component/error.ts';
|
|
19
21
|
import { ZovaContext } from '../core/context/index.ts';
|
|
20
22
|
import { sys } from '../core/sys/sys.ts';
|
|
21
23
|
|
|
@@ -81,6 +83,7 @@ async function _useController(
|
|
|
81
83
|
) {
|
|
82
84
|
// ctx
|
|
83
85
|
const ctx = new ZovaContext(getCurrentInstance()!);
|
|
86
|
+
setLoadBoundaryOptions(controllerBeanFullName);
|
|
84
87
|
// ctx: monkey
|
|
85
88
|
if (ctx.app) {
|
|
86
89
|
ctx.app.meta.module._monkeyModuleSync(true, 'appContextInitialize', undefined, ctx);
|
|
@@ -97,24 +100,32 @@ async function _useController(
|
|
|
97
100
|
ctx,
|
|
98
101
|
);
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
onUnmounted(() => {
|
|
111
|
-
ctx.dispose();
|
|
112
|
-
});
|
|
103
|
+
|
|
104
|
+
let retryPromise: Promise<void> | undefined;
|
|
105
|
+
let loadBeans = new Set<object>();
|
|
106
|
+
|
|
107
|
+
function setLoadBoundaryOptions(controllerBeanFullName: Constructable | string) {
|
|
108
|
+
const boundary = (controllerBeanFullName as any).$componentOptions?.boundary;
|
|
109
|
+
ctx.meta.state.setLoadRenderMode(boundary?.renderMode);
|
|
110
|
+
ctx.meta.state.setLoadRetryEnabled(boundary?.retry);
|
|
113
111
|
}
|
|
114
112
|
|
|
115
|
-
|
|
113
|
+
function isAttemptActive(attemptId: number) {
|
|
114
|
+
if (ctx.disposed || !ctx.meta) return false;
|
|
115
|
+
return ctx.meta.state.isLoadAttemptActive(attemptId);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getLoadLoadingDelay() {
|
|
119
|
+
const delay =
|
|
120
|
+
(controllerBeanFullName as any).$componentOptions?.boundary?.loading?.delay ??
|
|
121
|
+
sys.config.boundary.loading?.delay;
|
|
122
|
+
const delayNumber = Number(delay);
|
|
123
|
+
return Number.isFinite(delayNumber) && delayNumber > 0 ? delayNumber : 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function __loadBeans(attemptId: number) {
|
|
116
127
|
// controller
|
|
117
|
-
if (
|
|
128
|
+
if (!isAttemptActive(attemptId)) return false;
|
|
118
129
|
await ctx.bean._newBeanInner(
|
|
119
130
|
true,
|
|
120
131
|
BeanControllerIdentifier,
|
|
@@ -122,9 +133,17 @@ async function _useController(
|
|
|
122
133
|
controllerBeanFullName,
|
|
123
134
|
true,
|
|
124
135
|
false,
|
|
136
|
+
controller => {
|
|
137
|
+
if (!isAttemptActive(attemptId)) return;
|
|
138
|
+
loadBeans.add(controller as object);
|
|
139
|
+
ctx.meta.state.setLoadBeanAttempt(controller as object, attemptId);
|
|
140
|
+
ctx.meta.state.setLoadController(controller);
|
|
141
|
+
setLoadBoundaryOptions((controller as any).constructor);
|
|
142
|
+
},
|
|
125
143
|
);
|
|
144
|
+
if (!isAttemptActive(attemptId)) return false;
|
|
145
|
+
// style
|
|
126
146
|
if (styleBeanFullName) {
|
|
127
|
-
if (ctx.disposed) return;
|
|
128
147
|
await ctx.bean._newBeanInner(
|
|
129
148
|
true,
|
|
130
149
|
BeanStyleIdentifier,
|
|
@@ -132,10 +151,16 @@ async function _useController(
|
|
|
132
151
|
styleBeanFullName,
|
|
133
152
|
true,
|
|
134
153
|
false,
|
|
154
|
+
style => {
|
|
155
|
+
if (!isAttemptActive(attemptId)) return;
|
|
156
|
+
loadBeans.add(style as object);
|
|
157
|
+
ctx.meta.state.setLoadBeanAttempt(style as object, attemptId);
|
|
158
|
+
},
|
|
135
159
|
);
|
|
136
160
|
}
|
|
161
|
+
if (!isAttemptActive(attemptId)) return false;
|
|
162
|
+
// render
|
|
137
163
|
if (renderBeanFullName) {
|
|
138
|
-
if (ctx.disposed) return;
|
|
139
164
|
await ctx.bean._newBeanInner(
|
|
140
165
|
true,
|
|
141
166
|
BeanRenderIdentifier,
|
|
@@ -143,14 +168,24 @@ async function _useController(
|
|
|
143
168
|
renderBeanFullName,
|
|
144
169
|
true,
|
|
145
170
|
false,
|
|
171
|
+
render => {
|
|
172
|
+
if (!isAttemptActive(attemptId)) return;
|
|
173
|
+
loadBeans.add(render as object);
|
|
174
|
+
ctx.meta.state.setLoadBeanAttempt(render as object, attemptId);
|
|
175
|
+
},
|
|
146
176
|
);
|
|
147
177
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
178
|
+
return isAttemptActive(attemptId);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function __load(attemptId: number) {
|
|
182
|
+
if (!(await __loadBeans(attemptId))) return;
|
|
183
|
+
if (!isAttemptActive(attemptId)) return;
|
|
184
|
+
ctx.meta.state.setLoadReady();
|
|
151
185
|
if (process.env.CLIENT) {
|
|
152
186
|
ctx.util.instanceScope(() => {
|
|
153
187
|
queuePostFlushCb(() => {
|
|
188
|
+
if (!isAttemptActive(attemptId)) return;
|
|
154
189
|
setControllerRef(ctx, true);
|
|
155
190
|
ctx.meta.hooks.invokeHook('mounted');
|
|
156
191
|
});
|
|
@@ -158,15 +193,113 @@ async function _useController(
|
|
|
158
193
|
}
|
|
159
194
|
}
|
|
160
195
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
196
|
+
async function runLoadAttempt(
|
|
197
|
+
attemptId: number,
|
|
198
|
+
beforeLoad?: () => void | Promise<void>,
|
|
199
|
+
): Promise<void> {
|
|
164
200
|
try {
|
|
165
|
-
|
|
201
|
+
await beforeLoad?.();
|
|
202
|
+
if (!isAttemptActive(attemptId)) return;
|
|
203
|
+
await __load(attemptId);
|
|
166
204
|
} catch (err) {
|
|
205
|
+
if (!isAttemptActive(attemptId)) return;
|
|
206
|
+
const result = ctx.app?.meta.error.handleLoadError(err, ctx, ctx.instance as any) ?? {
|
|
207
|
+
err: normalizeError(err),
|
|
208
|
+
disposition: 'fallback' as const,
|
|
209
|
+
};
|
|
210
|
+
if (!isAttemptActive(attemptId)) return;
|
|
211
|
+
if (result.disposition === 'handled') {
|
|
212
|
+
ctx.meta.state.setLoadHandled();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
ctx.app?.meta.module._monkeyModuleSync(true, 'controllerLoad', undefined, {
|
|
216
|
+
phase: 'fallback',
|
|
217
|
+
ctx,
|
|
218
|
+
controllerBeanFullName,
|
|
219
|
+
controllerBeanName:
|
|
220
|
+
typeof controllerBeanFullName === 'string'
|
|
221
|
+
? controllerBeanFullName
|
|
222
|
+
: controllerBeanFullName.name,
|
|
223
|
+
error: result.err,
|
|
224
|
+
controllerRecorded: !!ctx.meta.state.loadController,
|
|
225
|
+
});
|
|
226
|
+
if (!isAttemptActive(attemptId)) return;
|
|
227
|
+
ctx.meta.state.setLoadError(result.err);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function retry() {
|
|
232
|
+
if (!ctx.meta.state.isLoadRetryAvailable) return Promise.resolve();
|
|
233
|
+
if (retryPromise) return retryPromise;
|
|
234
|
+
const promise = (async () => {
|
|
235
|
+
const attemptId = ctx.meta.state.beginLoadAttempt(getLoadLoadingDelay());
|
|
236
|
+
const previousLoadBeans = loadBeans;
|
|
237
|
+
loadBeans = new Set();
|
|
238
|
+
ctx.meta.hooks.clearMounted();
|
|
239
|
+
setControllerRef(ctx, false);
|
|
240
|
+
await runLoadAttempt(attemptId, () => {
|
|
241
|
+
ctx.bean.retryReset(previousLoadBeans);
|
|
242
|
+
});
|
|
243
|
+
})();
|
|
244
|
+
retryPromise = promise;
|
|
245
|
+
void promise.finally(() => {
|
|
246
|
+
if (retryPromise === promise) {
|
|
247
|
+
retryPromise = undefined;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return promise;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
ctx.meta.state.setLoadRetry(retry);
|
|
254
|
+
if (process.env.CLIENT) {
|
|
255
|
+
ctx.meta.hooks.onHydrated(() => {
|
|
256
|
+
if (!ctx.disposed) {
|
|
257
|
+
ctx.meta.state.setLoadRetryReady();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
// dispose
|
|
261
|
+
onBeforeUnmount(() => {
|
|
167
262
|
if (ctx.disposed) return;
|
|
168
|
-
|
|
263
|
+
// undefined better than null
|
|
264
|
+
setControllerRef(ctx, false);
|
|
265
|
+
if (ctx.bean !== ctx.app.bean) {
|
|
266
|
+
ctx.bean.dispose();
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
onUnmounted(() => {
|
|
270
|
+
ctx.dispose();
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// load
|
|
275
|
+
ctx.meta.hooks.onCreated(async () => {
|
|
276
|
+
if (ctx.disposed) return;
|
|
277
|
+
const loadEvent: IControllerLoadEvent = {
|
|
278
|
+
phase: 'prepare',
|
|
279
|
+
ctx,
|
|
280
|
+
controllerBeanFullName,
|
|
281
|
+
controllerBeanName:
|
|
282
|
+
typeof controllerBeanFullName === 'string'
|
|
283
|
+
? controllerBeanFullName
|
|
284
|
+
: controllerBeanFullName.name,
|
|
285
|
+
};
|
|
286
|
+
ctx.app?.meta.module._monkeyModuleSync(true, 'controllerLoad', undefined, loadEvent);
|
|
287
|
+
if (loadEvent.replayError) {
|
|
288
|
+
const attemptId = ctx.meta.state.beginLoadAttempt();
|
|
289
|
+
if (loadEvent.replayControllerRecorded) {
|
|
290
|
+
try {
|
|
291
|
+
await __loadBeans(attemptId);
|
|
292
|
+
} catch {
|
|
293
|
+
// The server's fallback decision is authoritative during initial hydration.
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (!ctx.disposed) {
|
|
297
|
+
ctx.meta.state.setLoadError(loadEvent.replayError);
|
|
298
|
+
}
|
|
299
|
+
return;
|
|
169
300
|
}
|
|
301
|
+
const attemptId = ctx.meta.state.beginLoadAttempt(getLoadLoadingDelay());
|
|
302
|
+
await runLoadAttempt(attemptId);
|
|
170
303
|
});
|
|
171
304
|
if (process.env.SERVER) {
|
|
172
305
|
onServerPrefetch(() => {
|