Skip to content

Commit

Permalink
refactor(all): restructure files/utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Apr 13, 2019
1 parent 509adc0 commit a801ea2
Show file tree
Hide file tree
Showing 16 changed files with 438 additions and 337 deletions.
51 changes: 51 additions & 0 deletions src/activation-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* An optional interface describing the available activation strategies.
* @internal Used internally.
*/
export const enum InternalActivationStrategy {
/**
* 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'
}

/**
* The strategy to use when activating modules during navigation.
*/
// kept for compat reason
export const activationStrategy: ActivationStrategy = {
noChange: InternalActivationStrategy.NoChange,
invokeLifecycle: InternalActivationStrategy.InvokeLifecycle,
replace: InternalActivationStrategy.Replace
};

/**
* An optional interface describing the available activation strategies.
*/
export 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';
}

/**
* Enum like type for activation strategy built-in values
*/
export type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];
16 changes: 10 additions & 6 deletions src/app-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,18 @@ export class AppRouter extends Router {
this.isNavigating = true;

let navtracker: number = this.history.getState('NavigationTracker');
if (!navtracker && !this.currentNavigationTracker) {
let currentNavTracker = this.currentNavigationTracker;

if (!navtracker && !currentNavTracker) {
this.isNavigatingFirst = true;
this.isNavigatingNew = true;
} else if (!navtracker) {
this.isNavigatingNew = true;
} else if (!this.currentNavigationTracker) {
} else if (!currentNavTracker) {
this.isNavigatingRefresh = true;
} else if (this.currentNavigationTracker < navtracker) {
} else if (currentNavTracker < navtracker) {
this.isNavigatingForward = true;
} else if (this.currentNavigationTracker > navtracker) {
} else if (currentNavTracker > navtracker) {
this.isNavigatingBack = true;
} if (!navtracker) {
navtracker = Date.now();
Expand All @@ -191,13 +193,15 @@ export class AppRouter extends Router {

instruction.previousInstruction = this.currentInstruction;

let maxInstructionCount = this.maxInstructionCount;

if (!instructionCount) {
this.events.publish(RouterEvent.Processing, { instruction });
} else if (instructionCount === this.maxInstructionCount - 1) {
} else if (instructionCount === maxInstructionCount - 1) {
logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);
restorePreviousLocation(this);
return this._dequeueInstruction(instructionCount + 1);
} else if (instructionCount > this.maxInstructionCount) {
} else if (instructionCount > maxInstructionCount) {
throw new Error('Maximum navigation attempts exceeded. Giving up.');
}

Expand Down
28 changes: 19 additions & 9 deletions src/aurelia-router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export {
ActivationStrategy,
RoutableComponentCanActivate,
RoutableComponentActivate,
RoutableComponentCanDeactivate,
Expand All @@ -21,23 +20,34 @@ export {
*/
} from './interfaces';
export {
ActivateNextStep,
CanActivateNextStep,
CanDeactivatePreviousStep,
DeactivatePreviousStep,
IObservable,
IObservableConfig
} from './activation';
} from './utilities-activation';
export { AppRouter } from './app-router';
export { NavModel } from './nav-model';
export { Redirect, RedirectToRoute, NavigationCommand, isNavigationCommand } from './navigation-commands';
export { activationStrategy, BuildNavigationPlanStep } from './navigation-plan';

export {
CommitChangesStep,
NavigationInstruction,
NavigationInstructionInit
} from './navigation-instruction';

export {
ActivateNextStep,
CanActivateNextStep,
CanDeactivatePreviousStep,
DeactivatePreviousStep
} from './step-activation';

export { CommitChangesStep } from './step-commit-changes';
export { BuildNavigationPlanStep } from './step-build-navigation-plan';
export { LoadRouteStep } from './step-load-route';

export {
ActivationStrategy,
activationStrategy
} from './activation-strategy';

export {
PipelineStatus
} from './pipeline-status';
Expand All @@ -52,6 +62,6 @@ export {

export { PipelineProvider } from './pipeline-provider';
export { Pipeline } from './pipeline';
export { RouteLoader, LoadRouteStep } from './route-loading';
export { RouteLoader } from './utilities-route-loading';
export { RouterConfiguration } from './router-configuration';
export { Router } from './router';
30 changes: 7 additions & 23 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Router } from './router';
import { NavModel } from './nav-model';
import { RouterConfiguration } from './router-configuration';
import { NavigationCommand } from './navigation-commands';
import { IObservable } from './activation';
import { IObservable } from './utilities-activation';
import { PipelineStatus } from './pipeline-status';
import { ActivationStrategyType } from './activation-strategy';

/**@internal */
declare module 'aurelia-dependency-injection' {
Expand Down Expand Up @@ -145,6 +146,11 @@ export interface RouteConfig {
*/
layoutModel?: any;

/**
* @internal
*/
hasChildRouter: boolean;

[x: string]: any;
}

Expand Down Expand Up @@ -220,28 +226,6 @@ export interface ConfiguresRouter {
configureRouter(config: RouterConfiguration, router: Router): Promise<void> | PromiseLike<void> | void;
}

/**
* An optional interface describing the available activation strategies.
*/
export 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';
}

/**
* Enum like type for activation strategy built-in values
*/
export type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];

/**
* A step to be run during processing of the pipeline.
Expand Down
20 changes: 3 additions & 17 deletions src/navigation-instruction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ActivationStrategyType } from './interfaces';
import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments } from './interfaces';
import { Router } from './router';
import { activationStrategy } from './navigation-plan';
import { activationStrategy, ActivationStrategyType } from './activation-strategy';

/**
* Initialization options for a navigation instruction
Expand All @@ -18,20 +18,6 @@ export interface NavigationInstructionInit {
plan?: Record<string, /*ViewPortInstruction*/any>;
}

/**
* A pipeline step for instructing a piepline to commit changes on a navigation instruction
*/
export class CommitChangesStep {
run(navigationInstruction: NavigationInstruction, next: Function): Promise<any> {
return navigationInstruction
._commitChanges(/*wait to swap?*/true)
.then(() => {
navigationInstruction._updateTitle();
return next();
});
}
}

/**
* Class used to represent an instruction during a navigation.
*/
Expand Down Expand Up @@ -149,7 +135,7 @@ export class NavigationInstruction {
addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any {
const lifecycleArgs = this.lifecycleArgs;
const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: name });
const viewportInstruction = this.viewPortInstructions[name] = {
const viewportInstruction: ViewPortInstruction = this.viewPortInstructions[name] = {
name: name,
strategy: strategy,
moduleId: moduleId,
Expand Down
Loading

0 comments on commit a801ea2

Please sign in to comment.