Skip to content

Commit d09aee0

Browse files
author
craig
committed
2.0.2 / 2022-03-30
================== * Fix run default true - @craigparra
1 parent 3b9d880 commit d09aee0

8 files changed

+82
-39
lines changed

ApplicationContext.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export default class ApplicationContext {
439439
}
440440

441441
async run(options) {
442-
if (null || options || options?.run) {
442+
if (!(options) || options?.run) {
443443
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle run phase started.`);
444444

445445
const keys = Object.keys(this.components);

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.0.2 / 2022-03-30
2+
==================
3+
* Fix run default true - @craigparra
4+
5+
16
2.0.1 / 2022-03-28
27
==================
38

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: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,26 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
112112
this.logger = LoggerFactory__default.getLogger('@alt-javascript/cdi/ApplicationContext', this.config);
113113
}
114114

115-
async start() {
116-
await this.lifeCycle();
115+
async start(options) {
116+
this.logger.verbose('Application context starting.');
117+
await this.lifeCycle(options);
118+
this.logger.verbose('Application context started.');
117119
}
118120

119-
async lifeCycle() {
121+
async lifeCycle(options) {
120122
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle started.`);
123+
await this.prepare();
124+
return this.run(options);
125+
}
126+
127+
async prepare() {
128+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle prepare phase started.`);
121129
await this.parseContexts();
122130
this.createSingletons();
123131
this.injectSingletonDependencies();
124132
this.initialiseSingletons();
125133
this.registerSingletonDestroyers();
126-
return this.run();
134+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle prepare phase completed.`);
127135
}
128136

129137
detectConfigContext() {
@@ -182,8 +190,10 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
182190
for (let i = 0; i < this.contexts.length; i++) {
183191
if (this.contexts[i]) {
184192
if (this.contexts[i]?.constructor?.name === 'Context') {
193+
// eslint-disable-next-line no-await-in-loop
185194
await this.parseContextComponents(this.contexts[i]);
186195
} else {
196+
// eslint-disable-next-line no-await-in-loop
187197
await this.parseContextComponents(new Context(this.contexts[i]));
188198
}
189199
} else {
@@ -205,6 +215,7 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
205215
const name = contextKeys[i];
206216
const component = contextComponent[name];
207217
component.name = name;
218+
// eslint-disable-next-line no-await-in-loop
208219
await this.parseContextComponent(component);
209220
}
210221
}
@@ -215,6 +226,7 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
215226
if (context.components) {
216227
if (Array.isArray(context.components)) {
217228
for (let i = 0; i < context.components.length; i++) {
229+
// eslint-disable-next-line no-await-in-loop
218230
await this.deriveContextComponent(context.components[i]);
219231
}
220232
}
@@ -249,17 +261,16 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
249261
$component.wireFactory = component.wireFactory;
250262
// TODO - dynamic import (async)
251263
if (component.require) {
252-
try{
264+
try {
253265
// eslint-disable-next-line
254266
let module = await import(component.require);
255267
$component.Reference = module.default;
256268
$component.isClass = ($component?.Reference?.prototype?.constructor !== undefined);
257269
} catch (err) {
258-
this.logger.error(err);
270+
this.logger.error(err);
259271
}
260272
}
261273

262-
263274
$component.properties = component.properties || constructr?.properties;
264275
$component.profiles = component.profiles || constructr?.profiles;
265276
if (!$component.profiles) {
@@ -474,19 +485,27 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
474485
this.logger.verbose('Registering singleton destroyers completed');
475486
}
476487

477-
async run() {
478-
const keys = Object.keys(this.components);
479-
for (let i = 0; i < keys.length; i++) {
480-
const component = this.components[keys[i]];
481-
if (component.scope === Scopes.SINGLETON) {
482-
if (typeof component.instance.run === 'function') {
483-
component.instance.run();
484-
} else if (typeof component.run === 'string') {
485-
component.instance[component.run]();
488+
async run(options) {
489+
if ( !(options) || options?.run) {
490+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle run phase started.`);
491+
492+
const keys = Object.keys(this.components);
493+
for (let i = 0; i < keys.length; i++) {
494+
const component = this.components[keys[i]];
495+
if (component.scope === Scopes.SINGLETON) {
496+
if (typeof component.run === 'string') {
497+
component.instance[component.run]();
498+
} else if (typeof component.instance.run === 'function') {
499+
component.instance.run();
500+
}
486501
}
502+
503+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle run phase completed.`);
487504
}
505+
} else {
506+
this.logger.verbose(`ApplicationContext (${this.name}) skipping lifecycle run phase.`);
488507
}
489-
this.logger.verbose('Application context started');
508+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle completed.`);
490509
}
491510

492511
get(reference, defaultValue, targetArgs) {

0 commit comments

Comments
 (0)