From 1898e1e6db78d4105bf5f5ed7c8308212c910173 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Mon, 22 Dec 2014 01:35:46 -0500 Subject: [PATCH] chore(*): prepare release 0.5.0 --- bower.json | 2 +- dist/amd/route-loader.js | 2 +- dist/amd/router-view.js | 36 +++++++++++++++++++++++++++------ dist/commonjs/route-loader.js | 2 +- dist/commonjs/router-view.js | 34 ++++++++++++++++++++++++++----- dist/es6/route-loader.js | 2 +- dist/es6/router-view.js | 38 ++++++++++++++++++++++++++++------- doc/CHANGELOG.md | 14 +++++++++++++ package.json | 2 +- 9 files changed, 109 insertions(+), 23 deletions(-) diff --git a/bower.json b/bower.json index efd67c5..7b6df33 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-router", - "version": "0.4.1", + "version": "0.5.0", "description": "An implementation of the RouteLoader interface for use with the router module. Also contains a custom element that allows the templating engine to display the current route.", "keywords": [ "aurelia", diff --git a/dist/amd/route-loader.js b/dist/amd/route-loader.js index a76b10c..7104854 100644 --- a/dist/amd/route-loader.js +++ b/dist/amd/route-loader.js @@ -27,7 +27,7 @@ define(["exports", "aurelia-templating", "aurelia-router"], function (exports, _ }; TemplatingRouteLoader.prototype.loadRoute = function (config) { - return this.resourceCoordinator.loadAnonymousElement(config.moduleId, null, config.view); + return this.resourceCoordinator.loadViewModelType(config.moduleId); }; return TemplatingRouteLoader; diff --git a/dist/amd/router-view.js b/dist/amd/router-view.js index fb663ec..a7f75f4 100644 --- a/dist/amd/router-view.js +++ b/dist/amd/router-view.js @@ -1,14 +1,21 @@ -define(["exports", "aurelia-dependency-injection", "aurelia-templating", "aurelia-router"], function (exports, _aureliaDependencyInjection, _aureliaTemplating, _aureliaRouter) { +define(["exports", "aurelia-dependency-injection", "aurelia-templating", "aurelia-router", "aurelia-metadata", "aurelia-path"], function (exports, _aureliaDependencyInjection, _aureliaTemplating, _aureliaRouter, _aureliaMetadata, _aureliaPath) { "use strict"; var Container = _aureliaDependencyInjection.Container; var CustomElement = _aureliaTemplating.CustomElement; var ViewSlot = _aureliaTemplating.ViewSlot; + var ViewStrategy = _aureliaTemplating.ViewStrategy; + var UseView = _aureliaTemplating.UseView; var NoView = _aureliaTemplating.NoView; var Router = _aureliaRouter.Router; + var Origin = _aureliaMetadata.Origin; + var relativeToFile = _aureliaPath.relativeToFile; - var defaultInstruction = { suppressBind: true }; + function makeViewRelative(executionContext, viewPath) { + var origin = Origin.get(executionContext.constructor); + return relativeToFile(viewPath, origin.moduleId); + } var RouterView = (function () { var RouterView = function RouterView(element, container, viewSlot) { @@ -39,17 +46,34 @@ define(["exports", "aurelia-dependency-injection", "aurelia-templating", "aureli } if ("router" in executionContext) { + this.executionContext = executionContext; executionContext.router.registerViewPort(this, this.element.getAttribute("name")); } }; - RouterView.prototype.getComponent = function (type, createChildRouter) { - var childContainer = this.container.createChild(); + RouterView.prototype.getComponent = function (viewModelType, createChildRouter, config) { + var childContainer = this.container.createChild(), viewStrategy = config.view || config.viewStrategy, viewModel; childContainer.registerHandler(Router, createChildRouter); - childContainer.autoRegister(type.target); + childContainer.autoRegister(viewModelType); - return type.create(childContainer, defaultInstruction); + viewModel = childContainer.get(viewModelType); + + if ("getViewStrategy" in viewModel && !viewStrategy) { + viewStrategy = viewModel.getViewStrategy(); + } + + if (typeof viewStrategy === "string") { + viewStrategy = new UseView(makeViewRelative(this.executionContext, viewStrategy)); + } + + if (viewStrategy && !(viewStrategy instanceof ViewStrategy)) { + throw new Error("The view must be a string or an instance of ViewStrategy."); + } + + CustomElement.anonymous(this.container, viewModel, viewStrategy).then(function (behaviorType) { + return behaviorType.create(childContainer, { executionContext: viewModel, suppressBind: true }); + }); }; RouterView.prototype.process = function (viewPortInstruction) { diff --git a/dist/commonjs/route-loader.js b/dist/commonjs/route-loader.js index 0387dd1..e40849f 100644 --- a/dist/commonjs/route-loader.js +++ b/dist/commonjs/route-loader.js @@ -26,7 +26,7 @@ var TemplatingRouteLoader = (function (RouteLoader) { }; TemplatingRouteLoader.prototype.loadRoute = function (config) { - return this.resourceCoordinator.loadAnonymousElement(config.moduleId, null, config.view); + return this.resourceCoordinator.loadViewModelType(config.moduleId); }; return TemplatingRouteLoader; diff --git a/dist/commonjs/router-view.js b/dist/commonjs/router-view.js index 0e7287e..10cea48 100644 --- a/dist/commonjs/router-view.js +++ b/dist/commonjs/router-view.js @@ -3,11 +3,18 @@ var Container = require('aurelia-dependency-injection').Container; var CustomElement = require('aurelia-templating').CustomElement; var ViewSlot = require('aurelia-templating').ViewSlot; +var ViewStrategy = require('aurelia-templating').ViewStrategy; +var UseView = require('aurelia-templating').UseView; var NoView = require('aurelia-templating').NoView; var Router = require('aurelia-router').Router; +var Origin = require('aurelia-metadata').Origin; +var relativeToFile = require('aurelia-path').relativeToFile; -var defaultInstruction = { suppressBind: true }; +function makeViewRelative(executionContext, viewPath) { + var origin = Origin.get(executionContext.constructor); + return relativeToFile(viewPath, origin.moduleId); +} var RouterView = (function () { var RouterView = function RouterView(element, container, viewSlot) { @@ -38,17 +45,34 @@ var RouterView = (function () { } if ("router" in executionContext) { + this.executionContext = executionContext; executionContext.router.registerViewPort(this, this.element.getAttribute("name")); } }; - RouterView.prototype.getComponent = function (type, createChildRouter) { - var childContainer = this.container.createChild(); + RouterView.prototype.getComponent = function (viewModelType, createChildRouter, config) { + var childContainer = this.container.createChild(), viewStrategy = config.view || config.viewStrategy, viewModel; childContainer.registerHandler(Router, createChildRouter); - childContainer.autoRegister(type.target); + childContainer.autoRegister(viewModelType); - return type.create(childContainer, defaultInstruction); + viewModel = childContainer.get(viewModelType); + + if ("getViewStrategy" in viewModel && !viewStrategy) { + viewStrategy = viewModel.getViewStrategy(); + } + + if (typeof viewStrategy === "string") { + viewStrategy = new UseView(makeViewRelative(this.executionContext, viewStrategy)); + } + + if (viewStrategy && !(viewStrategy instanceof ViewStrategy)) { + throw new Error("The view must be a string or an instance of ViewStrategy."); + } + + CustomElement.anonymous(this.container, viewModel, viewStrategy).then(function (behaviorType) { + return behaviorType.create(childContainer, { executionContext: viewModel, suppressBind: true }); + }); }; RouterView.prototype.process = function (viewPortInstruction) { diff --git a/dist/es6/route-loader.js b/dist/es6/route-loader.js index be387f8..6a7c8cc 100644 --- a/dist/es6/route-loader.js +++ b/dist/es6/route-loader.js @@ -8,6 +8,6 @@ export class TemplatingRouteLoader extends RouteLoader { } loadRoute(config){ - return this.resourceCoordinator.loadAnonymousElement(config.moduleId, null, config.view); + return this.resourceCoordinator.loadViewModelType(config.moduleId); } } \ No newline at end of file diff --git a/dist/es6/router-view.js b/dist/es6/router-view.js index e12ac5e..a1c5110 100644 --- a/dist/es6/router-view.js +++ b/dist/es6/router-view.js @@ -1,8 +1,13 @@ import {Container} from 'aurelia-dependency-injection'; -import {CustomElement, ViewSlot, NoView} from 'aurelia-templating'; +import {CustomElement, ViewSlot, ViewStrategy, UseView, NoView} from 'aurelia-templating'; import {Router} from 'aurelia-router'; +import {Origin} from 'aurelia-metadata'; +import {relativeToFile} from 'aurelia-path'; -var defaultInstruction = {suppressBind:true}; +function makeViewRelative(executionContext, viewPath){ + var origin = Origin.get(executionContext.constructor); + return relativeToFile(viewPath, origin.moduleId); +} export class RouterView { static annotations(){ @@ -33,17 +38,36 @@ export class RouterView { } if ('router' in executionContext) { + this.executionContext = executionContext; executionContext.router.registerViewPort(this, this.element.getAttribute('name')); } } - getComponent(type, createChildRouter){ - var childContainer = this.container.createChild(); - + getComponent(viewModelType, createChildRouter, config){ + var childContainer = this.container.createChild(), + viewStrategy = config.view || config.viewStrategy, + viewModel; + childContainer.registerHandler(Router, createChildRouter); - childContainer.autoRegister(type.target); + childContainer.autoRegister(viewModelType); + + viewModel = childContainer.get(viewModelType); + + if('getViewStrategy' in viewModel && !viewStrategy){ + viewStrategy = viewModel.getViewStrategy(); + } + + if(typeof viewStrategy === 'string'){ + viewStrategy = new UseView(makeViewRelative(this.executionContext, viewStrategy)); + } + + if(viewStrategy && !(viewStrategy instanceof ViewStrategy)){ + throw new Error('The view must be a string or an instance of ViewStrategy.'); + } - return type.create(childContainer, defaultInstruction); + CustomElement.anonymous(this.container, viewModel, viewStrategy).then(behaviorType => { + return behaviorType.create(childContainer, {executionContext:viewModel, suppressBind:true}); + }); } process(viewPortInstruction) { diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index cdd43dc..26edc0c 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,17 @@ +## 0.5.0 (2014-12-22) + + +#### Bug Fixes + +* **package:** update dependencies to latest versions ([9102ed05](http://github.com/aurelia/templating-router/commit/9102ed05892dc23859bc8f6129b27e87d8c30d39)) +* **router-view:** ensure that execution context is always set ([609b8ec1](http://github.com/aurelia/templating-router/commit/609b8ec170054417e58944a6dd3341c38e9fb947)) + + +#### Features + +* **router-view:** enable getViewStrategy on view models ([5aea8b3e](http://github.com/aurelia/templating-router/commit/5aea8b3eb0ede9c08fe728299a95689c503b32e3)) + + ### 0.4.1 (2014-12-18) diff --git a/package.json b/package.json index ab459d3..2f766c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-router", - "version": "0.4.1", + "version": "0.5.0", "description": "An implementation of the RouteLoader interface for use with the router module. Also contains a custom element that allows the templating engine to display the current route.", "keywords": [ "aurelia",