Skip to content

Commit

Permalink
fix(resources): enable early name analysis of resources
Browse files Browse the repository at this point in the history
This will allow withResources to work with convention-named resources.
  • Loading branch information
EisenbergEffect committed Jan 25, 2015
1 parent f11b2da commit 331fcfd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/attached-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ export class AttachedBehavior extends ResourceType {
}
}

load(container, target){
analyze(container, target){
configureBehavior(container, this, target);
}

load(container, target){
return Promise.resolve(this);
}

Expand Down
8 changes: 1 addition & 7 deletions src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ export class CustomElement extends ResourceType {
}
}

configure(container, target){
if(this.configured){
return;
}

analyze(container, target){
configureBehavior(container, this, target, valuePropertyName);

this.configured = true;
Expand All @@ -41,8 +37,6 @@ export class CustomElement extends ResourceType {
load(container, target, viewStrategy){
var options;

this.configure(container, target);

viewStrategy = viewStrategy || ViewStrategy.getDefault(target);
options = { targetShadowDOM:this.targetShadowDOM };

Expand Down
33 changes: 29 additions & 4 deletions src/resource-coordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class ResourceCoordinator {
throw new Error(`No element found in module "${moduleImport}".`);
}

analysis.analyze(container);

for(i = 0, ii = resources.length; i < ii; ++i){
current = resources[i];
type = current.type;
Expand All @@ -78,10 +80,7 @@ export class ResourceCoordinator {

cache[analysis.id] = analysis;

return Promise.all(loads).then(() => {
analysis.element.type.configure(container, analysis.element.value);
return analysis.element;
});
return Promise.all(loads).then(() => analysis.element);
});
}

Expand All @@ -91,12 +90,15 @@ export class ResourceCoordinator {
finalModules = [],
importIds = [], analysis, type;

var container = this.container;

for(i = 0, ii = imports.length; i < ii; ++i){
current = imports[i];
annotation = Origin.get(current);

if(!annotation){
analysis = analyzeModule({'default':current});
analysis.analyze(container);
type = (analysis.element || analysis.resources[0]).type;

if(resourceManifestUrl){
Expand Down Expand Up @@ -162,6 +164,7 @@ export class ResourceCoordinator {
}

analysis = analyzeModule(imports[i]);
analysis.analyze(container);
existing[analysis.id] = analysis;
allAnalysis[i] = analysis;
resources = analysis.resources;
Expand Down Expand Up @@ -211,6 +214,28 @@ class ResourceModule {
}
}

analyze(container){
var current = this.element,
resources = this.resources,
i, ii;

if(current){
if(!current.type.isAnalyzed){
current.type.isAnalyzed = true;
current.type.analyze(container, current.value);
}
}

for(i = 0, ii = resources.length; i < ii; ++i){
current = resources[i];

if('analyze' in current.type && !current.type.isAnalyzed){
current.type.isAnalyzed = true;
current.type.analyze(container, current.value);
}
}
}

register(registry, name){
var i, ii, resources = this.resources;

Expand Down
5 changes: 4 additions & 1 deletion src/template-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export class TemplateController extends ResourceType {
}
}

load(container, target){
analyze(container, target){
configureBehavior(container, this, target);
}

load(container, target){
return Promise.resolve(this);
}

Expand Down

0 comments on commit 331fcfd

Please sign in to comment.