Skip to content

Commit

Permalink
load behaviors in post task
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Feb 5, 2018
1 parent ce467bc commit f2dd6da
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/framework-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ function loadResources(aurelia, resourcesToLoad, appResources: ViewResources) {
}
}

function loadBehaviors(container: Container, behaviors: HtmlBehaviorResource[]) {
let current;
let next = () => {
current = behaviors.shift();
if (current) {
return current.load(container, current.target).then(next);
}

return Promise.resolve();
};

return next();
}

function getExt(name) { // eslint-disable-line consistent-return
let match = name.match(extPattern);
if (match && match.length > 0) {
Expand Down Expand Up @@ -151,12 +165,19 @@ export class FrameworkConfiguration {
this.container = aurelia.container;
/**@type {ConfigInfo[]} */
this.info = [];
/**@type {HtmlBehaviorResource[]} */
this.globalBehaviors = [];
this.processed = false;
this.preTasks = [];
this.postTasks = [];
this.resourcesToLoad = {};
this.preTask(() => aurelia.loader.normalize('aurelia-bootstrapper').then(name => this.bootstrapperName = name));
this.postTask(() => loadResources(aurelia, this.resourcesToLoad, aurelia.resources));
this.postTask(() => {
return Promise.all([
loadResources(aurelia, this.resourcesToLoad, aurelia.resources),
loadBehaviors(this.container, this.globalBehaviors)
]);
});
}

/**
Expand Down Expand Up @@ -295,7 +316,7 @@ export class FrameworkConfiguration {
resourceTypeMeta.register(this.aurelia.resources);

if (resourceTypeMeta.elementName) {
this.info.push(resourceTypeMeta);
this.globalBehaviors.push(resourceTypeMeta);
}
} else {
// When there is no explicit configuration and there is no convention
Expand Down Expand Up @@ -473,9 +494,6 @@ export class FrameworkConfiguration {
let next = () => {
current = info.shift();
if (current) {
if (current instanceof HtmlBehaviorResource) {
return current.load(this.container, current.target).then(next);
}
return loadPlugin(this, loader, current).then(next);
}

Expand All @@ -498,7 +516,7 @@ export class FrameworkConfiguration {
}
resource.initialize(aurelia.container, impl);
resource.register(aurelia.resources);
this.info.push(resource);
this.globalBehaviors.push(resource);
}

customAttribute(impl: Function) {
Expand Down

0 comments on commit f2dd6da

Please sign in to comment.