Permalink
Browse files

fix(resolved-view): use ResolvedViewStrategy instead of Container.ins…

…tance
  • Loading branch information...
doktordirk committed Jul 28, 2016
1 parent 52a4eed commit db85ea1709034dc9a80a58ec91f93ba4138e2778
Showing with 71 additions and 35 deletions.
  1. +1 −0 bower.json
  2. +31 −30 config.js
  3. +3 −0 package.json
  4. +3 −5 src/decorators/resolved-view.js
  5. +33 −0 src/resolved-view-strategy.js
@@ -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"
}
@@ -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"
}
}
});
@@ -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"
},
@@ -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"
},
@@ -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
@@ -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));
}
@@ -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.