@@ -12,7 +12,7 @@ import { Loader, TemplateManager, JavaScriptManager } from '@garfish/loader';
12
12
import {
13
13
deepMergeConfig ,
14
14
filterNestedConfig ,
15
- filterGlobalConfig ,
15
+ generateAppOptions ,
16
16
createDefaultOptions ,
17
17
} from './config' ;
18
18
import { interfaces } from './interface' ;
@@ -52,51 +52,6 @@ export class Garfish implements interfaces.Garfish {
52
52
options ?. plugins ?. forEach ( ( plugin ) => this . usePlugin ( plugin ) ) ;
53
53
}
54
54
55
- private registerDefaultPlugin ( options ?: interfaces . Options ) {
56
- this . usePlugin ( GarfishHMRPlugin ( ) ) ;
57
- this . usePlugin ( GarfishOptionsLife ( options ) ) ;
58
- this . usePlugin ( GarfishPerformance ( ) ) ;
59
- if ( ! options . disablePreloadApp ) {
60
- this . usePlugin ( GarfishPreloadPlugin ( ) ) ;
61
- }
62
- }
63
-
64
- private async mergeAppOptions (
65
- appName : string ,
66
- options ?: Partial < interfaces . LoadAppOptions > | string ,
67
- ) {
68
- options = options || { } ;
69
- // `Garfish.loadApp('appName', 'https://xx.html');`
70
- if ( typeof options === 'string' ) {
71
- options = {
72
- name : appName ,
73
- entry : options ,
74
- basename : '/' ,
75
- } as interfaces . AppInfo ;
76
- }
77
-
78
- let appInfo = this . appInfos [ appName ] ;
79
- if ( appInfo ) {
80
- appInfo = deepMergeConfig ( appInfo , options ) ;
81
- } else {
82
- appInfo = deepMergeConfig ( this . options , options ) ;
83
- filterGlobalConfig ( appInfo ) ;
84
- }
85
-
86
- // Does not support does not have remote resources application
87
- assert (
88
- appInfo . entry ,
89
- `Can't load unexpected child app "${ appName } ", ` +
90
- 'Please provide the entry parameters or registered in advance of the app.' ,
91
- ) ;
92
- appInfo . name = appName ;
93
- // Initialize the mount point, support domGetter as promise, is advantageous for the compatibility
94
- if ( appInfo . domGetter ) {
95
- appInfo . domGetter = await getRenderNode ( appInfo . domGetter ) ;
96
- }
97
- return appInfo as AppInfo ;
98
- }
99
-
100
55
private setOptions ( options : Partial < interfaces . Options > ) {
101
56
assert ( ! this . running , 'Garfish is running, can`t set options' ) ;
102
57
if ( isPlainObject ( options ) ) {
@@ -134,23 +89,24 @@ export class Garfish implements interfaces.Garfish {
134
89
if ( this . running ) {
135
90
// Nested scene can be repeated registration application
136
91
if ( options . nested ) {
137
- const hooks = globalLifecycle ( ) ;
92
+ const nestedHooks = globalLifecycle ( ) ;
138
93
const mainOptions = createDefaultOptions ( true ) ;
139
- options = filterNestedConfig ( deepMergeConfig ( mainOptions , options ) ) ;
94
+ options = deepMergeConfig ( mainOptions , options ) ;
95
+ options = filterNestedConfig ( options ) ;
140
96
141
97
// Register plugins
142
98
options . plugins ?. forEach ( ( plugin ) => this . usePlugin ( plugin ) ) ;
99
+
143
100
// Nested applications have independent life cycles
144
- this . usePlugin ( GarfishOptionsLife ( options ) ) ;
101
+ nestedHooks . usePlugin ( GarfishOptionsLife ( options ) ) ;
145
102
146
103
if ( options . apps ) {
147
- // usage :
104
+ // Usage :
148
105
// `Garfish.run({ apps: [{ props: Garfish.props }] })`
149
106
this . registerApp (
150
107
options . apps . map ( ( app ) => {
151
108
const appConf = deepMergeConfig ( options , app ) ;
152
- filterGlobalConfig ( appConf ) ;
153
- appConf . hooks = hooks ;
109
+ appConf . hooks = nestedHooks ;
154
110
appConf . sandbox = this . options . sandbox ;
155
111
return appConf ;
156
112
} ) ,
@@ -165,10 +121,15 @@ export class Garfish implements interfaces.Garfish {
165
121
this . setOptions ( options ) ;
166
122
167
123
// Register plugins
168
- this . registerDefaultPlugin ( this . options ) ;
124
+ this . usePlugin ( GarfishHMRPlugin ( ) ) ;
125
+ this . usePlugin ( GarfishOptionsLife ( this . options ) ) ;
126
+ this . usePlugin ( GarfishPerformance ( ) ) ;
127
+ if ( ! options . disablePreloadApp ) {
128
+ this . usePlugin ( GarfishPreloadPlugin ( ) ) ;
129
+ }
169
130
options ?. plugins ?. forEach ( ( plugin ) => this . usePlugin ( plugin , this ) ) ;
170
131
171
- // Emit hooks
132
+ // Emit hooks and register apps
172
133
this . hooks . lifecycle . beforeBootstrap . emit ( this . options ) ;
173
134
this . registerApp ( options . apps || [ ] ) ;
174
135
this . running = true ;
@@ -190,7 +151,6 @@ export class Garfish implements interfaces.Garfish {
190
151
// Deep merge this.options
191
152
if ( ! info . nested ) {
192
153
info = deepMergeConfig ( this . options , info ) ;
193
- filterGlobalConfig ( info ) ;
194
154
}
195
155
currentAdds [ info . name ] = info ;
196
156
this . appInfos [ info . name ] = info ;
@@ -220,10 +180,10 @@ export class Garfish implements interfaces.Garfish {
220
180
221
181
async loadApp (
222
182
appName : string ,
223
- options ?: Partial < interfaces . LoadAppOptions > | string ,
183
+ options ?: interfaces . LoadAppOptions | string ,
224
184
) : Promise < interfaces . App | null > {
225
185
assert ( appName , 'Miss appName.' ) ;
226
- const appInfo = await this . mergeAppOptions ( appName , options ) ;
186
+ const appInfo = await generateAppOptions ( appName , this , options ) ;
227
187
228
188
const asyncLoadProcess = async ( ) => {
229
189
// Return not undefined type data directly to end loading
0 commit comments