Skip to content

Commit

Permalink
chore(all): prepare release 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Oct 2, 2017
1 parent f3755a8 commit dffe907
Show file tree
Hide file tree
Showing 12 changed files with 785 additions and 601 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-router",
"version": "1.3.0",
"version": "1.4.0",
"description": "A powerful client-side router.",
"keywords": [
"aurelia",
Expand Down
274 changes: 141 additions & 133 deletions dist/amd/aurelia-router.js

Large diffs are not rendered by default.

44 changes: 38 additions & 6 deletions dist/aurelia-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export declare interface RouteConfig {
* Add to specify an activation strategy if it is always the same and you do not want that
* to be in your view-model code. Available values are 'replace' and 'invoke-lifecycle'.
*/
activationStrategy?: string;
activationStrategy?: 'no-change' | 'invoke-lifecycle' | 'replace';

/**
* specifies the file name of a layout view to use.
Expand Down Expand Up @@ -261,7 +261,7 @@ export declare interface RoutableComponentDetermineActivationStrategy {
* Implement this hook if you want to give hints to the router about the activation strategy, when reusing
* a view model for different routes. Available values are 'replace' and 'invoke-lifecycle'.
*/
determineActivationStrategy(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): string;
determineActivationStrategy(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): 'no-change' | 'invoke-lifecycle' | 'replace';
}

/**
Expand All @@ -278,6 +278,30 @@ export declare interface ConfiguresRouter {
configureRouter(config: RouterConfiguration, router: Router): Promise<void> | PromiseLike<void> | void;
}

/**
* An optional interface describing the available activation strategies.
*/
/**
* An optional interface describing the available activation strategies.
*/
export declare interface ActivationStrategy {

/**
* Reuse the existing view model, without invoking Router lifecycle hooks.
*/
noChange: 'no-change';

/**
* Reuse the existing view model, invoking Router lifecycle hooks.
*/
invokeLifecycle: 'invoke-lifecycle';

/**
* Replace the existing view model, invoking Router lifecycle hooks.
*/
replace: 'replace';
}

/**
* When a navigation command is encountered, the current navigation
* will be cancelled and control will be passed to the navigation
Expand Down Expand Up @@ -500,6 +524,11 @@ export declare function isNavigationCommand(obj: any): boolean;
* Used during the activation lifecycle to cause a redirect.
*/
export declare class Redirect {

/**
* @param url The URL fragment to use as the navigation destination.
* @param options The navigation options.
*/
constructor(url: string, options?: any);

/**
Expand All @@ -519,11 +548,14 @@ export declare class Redirect {

/**
* Used during the activation lifecycle to cause a redirect to a named route.
* @param route The name of the route.
* @param params The parameters to be sent to the activation method.
* @param options The options to use for navigation.
*/
export declare class RedirectToRoute {

/**
* @param route The name of the route.
* @param params The parameters to be sent to the activation method.
* @param options The options to use for navigation.
*/
constructor(route: string, params?: any, options?: any);

/**
Expand Down Expand Up @@ -638,7 +670,7 @@ export declare class RouterConfiguration {
/**
* The strategy to use when activating modules during navigation.
*/
export declare const activationStrategy: any;
export declare const activationStrategy: ActivationStrategy;
export declare class BuildNavigationPlanStep {
run(navigationInstruction: NavigationInstruction, next: Function): any;
}
Expand Down
119 changes: 91 additions & 28 deletions dist/aurelia-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class NavigationInstruction {
* Gets the instruction's base URL, accounting for wildcard route parameters.
*/
getBaseUrl(): string {
let fragment = this.fragment;
let fragment = decodeURI(this.fragment);

if (fragment === '') {
let nonEmptyRoute = this.router.routes.find(route => {
Expand All @@ -362,18 +362,17 @@ export class NavigationInstruction {
}

if (!this.params) {
return fragment;
return encodeURI(fragment);
}

let wildcardName = this.getWildCardName();
let path = this.params[wildcardName] || '';

if (!path) {
return fragment;
return encodeURI(fragment);
}

path = encodeURI(path);
return fragment.substr(0, fragment.lastIndexOf(path));
return encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));
}

_commitChanges(waitToSwap: boolean) {
Expand Down Expand Up @@ -401,17 +400,20 @@ export class NavigationInstruction {
}

if (viewPortInstruction.strategy === activationStrategy.replace) {
if (waitToSwap) {
delaySwaps.push({viewPort, viewPortInstruction});
}

loads.push(viewPort.process(viewPortInstruction, waitToSwap).then((x) => {
if (viewPortInstruction.childNavigationInstruction) {
return viewPortInstruction.childNavigationInstruction._commitChanges();
if (viewPortInstruction.childNavigationInstruction && viewPortInstruction.childNavigationInstruction.parentCatchHandler) {
loads.push(viewPortInstruction.childNavigationInstruction._commitChanges());
} else {
if (waitToSwap) {
delaySwaps.push({viewPort, viewPortInstruction});
}
loads.push(viewPort.process(viewPortInstruction, waitToSwap).then((x) => {
if (viewPortInstruction.childNavigationInstruction) {
return viewPortInstruction.childNavigationInstruction._commitChanges();
}

return undefined;
}));
return undefined;
}));
}
} else {
if (viewPortInstruction.childNavigationInstruction) {
loads.push(viewPortInstruction.childNavigationInstruction._commitChanges(waitToSwap));
Expand Down Expand Up @@ -614,7 +616,7 @@ interface RouteConfig {
* Add to specify an activation strategy if it is always the same and you do not want that
* to be in your view-model code. Available values are 'replace' and 'invoke-lifecycle'.
*/
activationStrategy?: string;
activationStrategy?: 'no-change' | 'invoke-lifecycle'| 'replace';

/**
* specifies the file name of a layout view to use.
Expand Down Expand Up @@ -689,7 +691,7 @@ interface RoutableComponentDetermineActivationStrategy {
* Implement this hook if you want to give hints to the router about the activation strategy, when reusing
* a view model for different routes. Available values are 'replace' and 'invoke-lifecycle'.
*/
determineActivationStrategy: (params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction) => string;
determineActivationStrategy: (params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction) => 'no-change' | 'invoke-lifecycle'| 'replace';
}

/**
Expand All @@ -702,6 +704,24 @@ interface ConfiguresRouter {
configureRouter(config: RouterConfiguration, router: Router): Promise<void>|PromiseLike<void>|void;
}

/**
* An optional interface describing the available activation strategies.
*/
interface ActivationStrategy {
/**
* Reuse the existing view model, without invoking Router lifecycle hooks.
*/
noChange: 'no-change';
/**
* Reuse the existing view model, invoking Router lifecycle hooks.
*/
invokeLifecycle: 'invoke-lifecycle';
/**
* Replace the existing view model, invoking Router lifecycle hooks.
*/
replace: 'replace';
}

/**
* When a navigation command is encountered, the current navigation
* will be cancelled and control will be passed to the navigation
Expand All @@ -725,6 +745,10 @@ export function isNavigationCommand(obj: any): boolean {
* Used during the activation lifecycle to cause a redirect.
*/
export class Redirect {
/**
* @param url The URL fragment to use as the navigation destination.
* @param options The navigation options.
*/
constructor(url: string, options: any = {}) {
this.url = url;
this.options = Object.assign({ trigger: true, replace: true }, options);
Expand Down Expand Up @@ -753,11 +777,13 @@ export class Redirect {

/**
* Used during the activation lifecycle to cause a redirect to a named route.
* @param route The name of the route.
* @param params The parameters to be sent to the activation method.
* @param options The options to use for navigation.
*/
export class RedirectToRoute {
/**
* @param route The name of the route.
* @param params The parameters to be sent to the activation method.
* @param options The options to use for navigation.
*/
constructor(route: string, params: any = {}, options: any = {}) {
this.route = route;
this.params = params;
Expand Down Expand Up @@ -965,7 +991,7 @@ export class RouterConfiguration {
/**
* The strategy to use when activating modules during navigation.
*/
export const activationStrategy = {
export const activationStrategy: ActivationStrategy = {
noChange: 'no-change',
invokeLifecycle: 'invoke-lifecycle',
replace: 'replace'
Expand Down Expand Up @@ -1536,16 +1562,52 @@ export class Router {
} else if (this.catchAllHandler) {
let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {
params: { path: fragment },
queryParams: results && results.queryParams,
queryParams: results ? results.queryParams : {},
config: null // config will be created by the catchAllHandler
}));

return evaluateNavigationStrategy(instruction, this.catchAllHandler);
} else if (this.parent) {
let router = this._parentCatchAllHandler(this.parent);

if (router) {
let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);

let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {
params: { path: fragment },
queryParams: results ? results.queryParams : {},
router: router,
parentInstruction: newParentInstruction,
parentCatchHandler: true,
config: null // config will be created by the chained parent catchAllHandler
}));

return evaluateNavigationStrategy(instruction, router.catchAllHandler);
}
}

return Promise.reject(new Error(`Route not found: ${url}`));
}

_findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {
if (instruction.router === router) {
instruction.fragment = router.baseUrl; //need to change the fragment in case of a redirect instead of moduleId
return instruction;
} else if (instruction.parentInstruction) {
return this._findParentInstructionFromRouter(router, instruction.parentInstruction);
}
return undefined;
}

_parentCatchAllHandler(router): Function|Boolean {
if (router.catchAllHandler) {
return router;
} else if (router.parent) {
return this._parentCatchAllHandler(router.parent);
}
return false;
}

_createRouteConfig(config, instruction) {
return Promise.resolve(config)
.then(c => {
Expand Down Expand Up @@ -1602,7 +1664,7 @@ function evaluateNavigationStrategy(instruction: NavigationInstruction, evaluato

export class CanDeactivatePreviousStep {
run(navigationInstruction: NavigationInstruction, next: Function) {
return processDeactivatable(navigationInstruction.plan, 'canDeactivate', next);
return processDeactivatable(navigationInstruction, 'canDeactivate', next);
}
}

Expand All @@ -1614,7 +1676,7 @@ export class CanActivateNextStep {

export class DeactivatePreviousStep {
run(navigationInstruction: NavigationInstruction, next: Function) {
return processDeactivatable(navigationInstruction.plan, 'deactivate', next, true);
return processDeactivatable(navigationInstruction, 'deactivate', next, true);
}
}

Expand All @@ -1624,7 +1686,8 @@ export class ActivateNextStep {
}
}

function processDeactivatable(plan, callbackName, next, ignoreResult) {
function processDeactivatable(navigationInstruction: NavigationInstruction, callbackName: string, next: Funcion, ignoreResult: boolean) {
const plan = navigationInstruction.plan;
let infos = findDeactivatable(plan, callbackName);
let i = infos.length; //query from inside out

Expand All @@ -1640,7 +1703,7 @@ function processDeactivatable(plan, callbackName, next, ignoreResult) {
if (i--) {
try {
let viewModel = infos[i];
let result = viewModel[callbackName]();
let result = viewModel[callbackName](navigationInstruction);
return processPotential(result, inspect, next.cancel);
} catch (error) {
return next.cancel(error);
Expand Down Expand Up @@ -1668,10 +1731,10 @@ function findDeactivatable(plan, callbackName, list: Array<Object> = []): Array<
}
}

if (viewPortPlan.childNavigationInstruction) {
findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);
} else if (prevComponent) {
if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {
addPreviousDeactivatable(prevComponent, callbackName, list);
} else if (viewPortPlan.childNavigationInstruction) {
findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);
}
}

Expand Down
Loading

0 comments on commit dffe907

Please sign in to comment.