Skip to content

Commit

Permalink
fix(view-strategy): dynamic strategy hook results should be relative …
Browse files Browse the repository at this point in the history
…to view-model
  • Loading branch information
EisenbergEffect committed Jan 13, 2015
1 parent f4fa9be commit ae6cf40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/composition-engine.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Origin} from 'aurelia-metadata';
import {ViewStrategy, UseView} from './view-strategy';
import {ResourceCoordinator} from './resource-coordinator';
import {ViewEngine} from './view-engine';
Expand Down Expand Up @@ -36,14 +37,22 @@ export class CompositionEngine {
viewModel = instruction.viewModel;

return this.activate(instruction).then(() => {
var doneLoading;
var doneLoading, viewStrategyFromViewModel, origin;

if('getViewStrategy' in viewModel && !instruction.view){
viewStrategyFromViewModel = true;
instruction.view = ViewStrategy.normalize(viewModel.getViewStrategy());
}

if(instruction.view && instruction.viewResources){
instruction.view.makeRelativeTo(instruction.viewResources.viewUrl);
if (instruction.view) {
if(viewStrategyFromViewModel){
origin = Origin.get(viewModel.constructor);
if(origin){
instruction.view.makeRelativeTo(origin.moduleId);
}
}else if(instruction.viewResources){
instruction.view.makeRelativeTo(instruction.viewResources.viewUrl);
}
}

if(viewModelInfo){
Expand Down Expand Up @@ -86,6 +95,10 @@ export class CompositionEngine {
return this.createBehaviorAndSwap(instruction);
}
}else if(instruction.view){
if(instruction.viewResources){
instruction.view.makeRelativeTo(instruction.viewResources.viewUrl);
}

return instruction.view.loadViewFactory(this.viewEngine).then(viewFactory => {
result = viewFactory.create(childContainer, instruction.executionContext);
instruction.viewSlot.swap(result);
Expand Down
4 changes: 4 additions & 0 deletions src/view-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class UseView extends ViewStrategy {
}

loadViewFactory(viewEngine, options){
if(!this.absolutePath && this.moduleId){
this.absolutePath = relativeToFile(this.path, this.moduleId);
}

return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId);
}

Expand Down

0 comments on commit ae6cf40

Please sign in to comment.