Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(resolved-view): use ResolvedViewStrategy instead of Container.ins…
Browse files Browse the repository at this point in the history
…tance
  • Loading branch information
doktordirk committed Jul 28, 2016
1 parent 52a4eed commit db85ea1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 35 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"aurelia-dependency-injection": "^1.0.0-rc.1.0.0",
"aurelia-logging": "^1.0.0-rc.1.0.0",
"aurelia-path": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"extend": "^3.0.0"
}
Expand Down
61 changes: 31 additions & 30 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,44 @@ System.config({
},

map: {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-polyfills": "npm:aurelia-polyfills@1.0.0-rc.1.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0-rc.1.0.3",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0",
"aurelia-polyfills": "npm:aurelia-polyfills@1.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0",
"extend": "npm:extend@3.0.0",
"npm:aurelia-binding@1.0.0-rc.1.0.4": {
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-rc.1.0.0"
"npm:aurelia-binding@1.0.0": {
"aurelia-logging": "npm:aurelia-logging@1.0.0",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0"
},
"npm:aurelia-dependency-injection@1.0.0-rc.1.0.1": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
"npm:aurelia-dependency-injection@1.0.0": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0"
},
"npm:aurelia-loader@1.0.0-rc.1.0.0": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0"
"npm:aurelia-loader@1.0.0": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0"
},
"npm:aurelia-metadata@1.0.0-rc.1.0.1": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
"npm:aurelia-metadata@1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0"
},
"npm:aurelia-polyfills@1.0.0-rc.1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
"npm:aurelia-polyfills@1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0"
},
"npm:aurelia-task-queue@1.0.0-rc.1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
"npm:aurelia-task-queue@1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0"
},
"npm:aurelia-templating@1.0.0-rc.1.0.3": {
"aurelia-binding": "npm:aurelia-binding@1.0.0-rc.1.0.4",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-loader": "npm:aurelia-loader@1.0.0-rc.1.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-rc.1.0.0"
"npm:aurelia-templating@1.0.0": {
"aurelia-binding": "npm:aurelia-binding@1.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0",
"aurelia-loader": "npm:aurelia-loader@1.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0"
}
}
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
"dependencies": {
"aurelia-dependency-injection": "^1.0.0-rc.1.0.0",
"aurelia-logging": "^1.0.0-rc.1.0.0",
"aurelia-path": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"extend": "^3.0.0"
},
"peerDependencies": {
"aurelia-dependency-injection": "^1.0.0-rc.1.0.0",
"aurelia-logging": "^1.0.0-rc.1.0.0",
"aurelia-path": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"extend": "^3.0.0"
},
Expand All @@ -52,6 +54,7 @@
"dependencies": {
"aurelia-dependency-injection": "^1.0.0-rc.1.0.0",
"aurelia-logging": "^1.0.0-rc.1.0.0",
"aurelia-path": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"extend": "^3.0.0"
},
Expand Down
8 changes: 3 additions & 5 deletions src/decorators/resolved-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Container} from 'aurelia-dependency-injection';
import {ViewManager} from './../view-manager';
import {RelativeViewStrategy, useViewStrategy} from 'aurelia-templating';
import {ResolvedViewStrategy} from './../resolved-view-strategy';
import {useViewStrategy} from 'aurelia-templating';

/**
* Decorates a custome element class in a way that it loads it's view from
Expand All @@ -11,8 +12,5 @@ import {RelativeViewStrategy, useViewStrategy} from 'aurelia-templating';
* @returns {function} that takes the target and sets the view strategy on the element
*/
export function resolvedView(namespace, view) {
let viewManager = Container.instance.get(ViewManager);
let path = viewManager.resolve(namespace, view);

return useViewStrategy(new RelativeViewStrategy(path));
return useViewStrategy(new ResolvedViewStrategy(namespace, view));
}
33 changes: 33 additions & 0 deletions src/resolved-view-strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {ViewManager} from './view-manager';
import {viewStrategy} from 'aurelia-templating';
import {relativeToFile} from 'aurelia-path';
/**
* A view strategy that loads a view based on namespace and view name registered with the ViewManager
*/
@viewStrategy()
export class ResolvedViewStrategy {
/**
* Creates an instance of ResolvedViewStrategy.
* @param namespace The namespace of the view.
* @param view The name of the view.
*/
constructor(namespace: string, view: string) {
this.namespace = namespace;
this.view = view;
}

/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext): Promise<ViewFactory> {
let viewManager = viewEngine.container.get(ViewManager);
let path = viewManager.resolve(this.namespace, this.view);

compileInstruction.associatedModuleId = this.moduleId;
return viewEngine.loadViewFactory(this.moduleId ? relativeToFile(path, this.moduleId) : path, compileInstruction, loadContext);
}
}

0 comments on commit db85ea1

Please sign in to comment.