Skip to content

Commit f29e6bd

Browse files
author
craig
committed
2.0.0 / 2022-03-23
================== * Initial esm support - @craigparra
1 parent de6faa6 commit f29e6bd

5 files changed

+47
-27
lines changed

dist/alt-javascript-applicationcontext-iife-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/alt-javascript-applicationcontext-iife-min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/alt-javascript-applicationcontext-iife.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
113113
}
114114

115115
async start() {
116-
return this.lifeCycle();
116+
await this.lifeCycle();
117117
}
118118

119119
async lifeCycle() {
120120
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle started.`);
121-
this.parseContexts();
121+
await this.parseContexts();
122122
this.createSingletons();
123123
this.injectSingletonDependencies();
124124
this.initialiseSingletons();
@@ -176,15 +176,15 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
176176
this.logger.verbose('Detecting global context components completed.');
177177
}
178178

179-
parseContexts() {
179+
async parseContexts() {
180180
this.logger.verbose('Parsing configured contexts started.');
181181
this.detectConfigContext();
182182
for (let i = 0; i < this.contexts.length; i++) {
183183
if (this.contexts[i]) {
184184
if (this.contexts[i]?.constructor?.name === 'Context') {
185-
this.parseContextComponents(this.contexts[i]);
185+
await this.parseContextComponents(this.contexts[i]);
186186
} else {
187-
this.parseContextComponents(new Context(this.contexts[i]));
187+
await this.parseContextComponents(new Context(this.contexts[i]));
188188
}
189189
} else {
190190
const msg = `ApplicationContext (${this.name}) received a nullish context.`;
@@ -196,33 +196,33 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
196196
this.logger.verbose('Parsing configured contexts completed.');
197197
}
198198

199-
deriveContextComponent(contextComponent) {
199+
async deriveContextComponent(contextComponent) {
200200
if (contextComponent.name || contextComponent.Reference || contextComponent.factory) {
201-
this.parseContextComponent(contextComponent);
201+
await this.parseContextComponent(contextComponent);
202202
} else {
203203
const contextKeys = Object.keys(contextComponent);
204204
for (let i = 0; i < contextKeys.length; i++) {
205205
const name = contextKeys[i];
206206
const component = contextComponent[name];
207207
component.name = name;
208-
this.parseContextComponent(component);
208+
await this.parseContextComponent(component);
209209
}
210210
}
211211
}
212212

213-
parseContextComponents(context) {
213+
async parseContextComponents(context) {
214214
this.logger.verbose('Processing context components started');
215215
if (context.components) {
216216
if (Array.isArray(context.components)) {
217217
for (let i = 0; i < context.components.length; i++) {
218-
this.deriveContextComponent(context.components[i]);
218+
await this.deriveContextComponent(context.components[i]);
219219
}
220220
}
221221
}
222222
this.logger.verbose('Processing context components completed');
223223
}
224224

225-
parseContextComponent(componentArg) {
225+
async parseContextComponent(componentArg) {
226226
let component = componentArg;
227227
if (component?.constructor?.name !== 'Component'
228228
&& component?.constructor?.name !== 'Singleton'
@@ -248,7 +248,17 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
248248
$component.factoryArgs = component.factoryArgs;
249249
$component.wireFactory = component.wireFactory;
250250
// TODO - dynamic import (async)
251-
if (component.require) ;
251+
if (component.require) {
252+
try{
253+
// eslint-disable-next-line
254+
let module = await import(component.require);
255+
$component.Reference = module.default;
256+
$component.isClass = ($component?.Reference?.prototype?.constructor !== undefined);
257+
} catch (err) {
258+
this.logger.error(err);
259+
}
260+
}
261+
252262

253263
$component.properties = component.properties || constructr?.properties;
254264
$component.profiles = component.profiles || constructr?.profiles;

dist/alt-javascript-cdi-esm-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/alt-javascript-cdi-esm.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ class ApplicationContext {
109109
}
110110

111111
async start() {
112-
return this.lifeCycle();
112+
await this.lifeCycle();
113113
}
114114

115115
async lifeCycle() {
116116
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle started.`);
117-
this.parseContexts();
117+
await this.parseContexts();
118118
this.createSingletons();
119119
this.injectSingletonDependencies();
120120
this.initialiseSingletons();
@@ -172,15 +172,15 @@ class ApplicationContext {
172172
this.logger.verbose('Detecting global context components completed.');
173173
}
174174

175-
parseContexts() {
175+
async parseContexts() {
176176
this.logger.verbose('Parsing configured contexts started.');
177177
this.detectConfigContext();
178178
for (let i = 0; i < this.contexts.length; i++) {
179179
if (this.contexts[i]) {
180180
if (this.contexts[i]?.constructor?.name === 'Context') {
181-
this.parseContextComponents(this.contexts[i]);
181+
await this.parseContextComponents(this.contexts[i]);
182182
} else {
183-
this.parseContextComponents(new Context(this.contexts[i]));
183+
await this.parseContextComponents(new Context(this.contexts[i]));
184184
}
185185
} else {
186186
const msg = `ApplicationContext (${this.name}) received a nullish context.`;
@@ -192,33 +192,33 @@ class ApplicationContext {
192192
this.logger.verbose('Parsing configured contexts completed.');
193193
}
194194

195-
deriveContextComponent(contextComponent) {
195+
async deriveContextComponent(contextComponent) {
196196
if (contextComponent.name || contextComponent.Reference || contextComponent.factory) {
197-
this.parseContextComponent(contextComponent);
197+
await this.parseContextComponent(contextComponent);
198198
} else {
199199
const contextKeys = Object.keys(contextComponent);
200200
for (let i = 0; i < contextKeys.length; i++) {
201201
const name = contextKeys[i];
202202
const component = contextComponent[name];
203203
component.name = name;
204-
this.parseContextComponent(component);
204+
await this.parseContextComponent(component);
205205
}
206206
}
207207
}
208208

209-
parseContextComponents(context) {
209+
async parseContextComponents(context) {
210210
this.logger.verbose('Processing context components started');
211211
if (context.components) {
212212
if (Array.isArray(context.components)) {
213213
for (let i = 0; i < context.components.length; i++) {
214-
this.deriveContextComponent(context.components[i]);
214+
await this.deriveContextComponent(context.components[i]);
215215
}
216216
}
217217
}
218218
this.logger.verbose('Processing context components completed');
219219
}
220220

221-
parseContextComponent(componentArg) {
221+
async parseContextComponent(componentArg) {
222222
let component = componentArg;
223223
if (component?.constructor?.name !== 'Component'
224224
&& component?.constructor?.name !== 'Singleton'
@@ -244,7 +244,17 @@ class ApplicationContext {
244244
$component.factoryArgs = component.factoryArgs;
245245
$component.wireFactory = component.wireFactory;
246246
// TODO - dynamic import (async)
247-
if (component.require) ;
247+
if (component.require) {
248+
try{
249+
// eslint-disable-next-line
250+
let module = await import(component.require);
251+
$component.Reference = module.default;
252+
$component.isClass = ($component?.Reference?.prototype?.constructor !== undefined);
253+
} catch (err) {
254+
this.logger.error(err);
255+
}
256+
}
257+
248258

249259
$component.properties = component.properties || constructr?.properties;
250260
$component.profiles = component.profiles || constructr?.profiles;

0 commit comments

Comments
 (0)