Skip to content

Commit

Permalink
chore(all): clean up, add more comments, ensure compat
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Mar 30, 2019
1 parent a7f2184 commit e40b0a5
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 69 deletions.
40 changes: 5 additions & 35 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ module.exports = function(config) {
frameworks: ["jasmine"],
files: ["test/**/*.spec.ts"],
preprocessors: {
"test/**/*.spec.ts": ["webpack"]
"test/**/*.spec.ts": ["webpack", 'sourcemap']
},
webpack: {
mode: "development",
entry: 'test/setup.ts',
resolve: {
extensions: [".ts", ".js"],
modules: ["src", "node_modules"],
alias: {
src: path.resolve(__dirname, "src")
src: path.resolve(__dirname, 'src'),
test: path.resolve(__dirname, 'test')
}
},
devtool: browsers.includes('ChromeDebugging') ? 'eval-source-map' : 'inline-source-map',
Expand All @@ -35,21 +37,14 @@ module.exports = function(config) {
},
reporters: ["mocha"],
webpackServer: { noInfo: config.noInfo },
browsers: Array.isArray(browsers) && browsers.length > 0 ? browsers : ['ChromeHeadlessOpt'],
browsers: Array.isArray(browsers) && browsers.length > 0 ? browsers : ['ChromeHeadless'],
customLaunchers: {
ChromeDebugging: {
base: 'Chrome',
flags: [
...commonChromeFlags,
'--remote-debugging-port=9333'
],
debug: true
},
ChromeHeadlessOpt: {
base: 'ChromeHeadless',
flags: [
...commonChromeFlags
]
}
},
mochaReporter: {
Expand All @@ -58,28 +53,3 @@ module.exports = function(config) {
singleRun: false
});
};

const commonChromeFlags = [
'--no-default-browser-check',
'--no-first-run',
'--no-managed-user-acknowledgment-check',
'--no-pings',
'--no-sandbox',
'--no-wifi',
'--no-zygote',
'--disable-background-networking',
'--disable-background-timer-throttling',
'--disable-backing-store-limit',
'--disable-boot-animation',
'--disable-breakpad',
'--disable-cache',
'--disable-clear-browsing-data-counters',
'--disable-cloud-import',
'--disable-component-extensions-with-background-pages',
'--disable-contextual-search',
'--disable-default-apps',
'--disable-extensions',
'--disable-infobars',
'--disable-translate',
'--disable-sync'
];
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/navigation-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface NavigationInstructionInit {
previousInstruction?: NavigationInstruction;
router: Router;
options?: Object;
plan?: Record<string, ViewPortInstruction>;
plan?: Record<string, /*ViewPortInstruction*/any>;
}

/**
Expand Down Expand Up @@ -73,7 +73,7 @@ export class NavigationInstruction {
/**
* viewPort instructions to used activation.
*/
viewPortInstructions: Record<string, any>;
viewPortInstructions: Record<string, /*ViewPortInstruction*/any>;

/**
* The router instance.
Expand All @@ -83,7 +83,7 @@ export class NavigationInstruction {
/**
* Current built viewport plan of this nav instruction
*/
plan: Record<string, any> = null;
plan: Record<string, /*ViewPortPlan*/any> = null;

options: Record<string, any> = {};

Expand Down Expand Up @@ -141,9 +141,9 @@ export class NavigationInstruction {
}

/**
* Adds a viewPort instruction.
* Adds a viewPort instruction. Returns the newly created instruction based on parameters
*/
addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): ViewPortInstruction {
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] = {
Expand Down
19 changes: 11 additions & 8 deletions src/route-loading.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Next, RouteConfig, ViewPortComponent, ViewPortPlan } from './interfaces';
import { Next, RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';
import { Redirect } from './navigation-commands';
import { NavigationInstruction } from './navigation-instruction';
import { activationStrategy, _buildNavigationPlan } from './navigation-plan';
Expand Down Expand Up @@ -77,23 +77,25 @@ export const determineWhatToLoad = (

for (let viewPortName in plan) {
let viewPortPlan = plan[viewPortName];
let child_nav_instruction = viewPortPlan.childNavigationInstruction;

if (viewPortPlan.strategy === activationStrategy.replace) {
toLoad.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);

if (viewPortPlan.childNavigationInstruction) {
determineWhatToLoad(viewPortPlan.childNavigationInstruction, toLoad);
if (child_nav_instruction) {
determineWhatToLoad(child_nav_instruction, toLoad);
}
} else {
let viewPortInstruction = navigationInstruction.addViewPortInstruction(
viewPortName,
viewPortPlan.strategy,
viewPortPlan.prevModuleId,
viewPortPlan.prevComponent);
viewPortPlan.prevComponent
) as ViewPortInstruction;

if (viewPortPlan.childNavigationInstruction) {
viewPortInstruction.childNavigationInstruction = viewPortPlan.childNavigationInstruction;
determineWhatToLoad(viewPortPlan.childNavigationInstruction, toLoad);
if (child_nav_instruction) {
viewPortInstruction.childNavigationInstruction = child_nav_instruction;
determineWhatToLoad(child_nav_instruction, toLoad);
}
}
}
Expand All @@ -117,7 +119,8 @@ export const loadRoute = (
viewPortPlan.name,
viewPortPlan.strategy,
moduleId,
component);
component
) as ViewPortInstruction;

let childRouter = component.childRouter;
if (childRouter) {
Expand Down
11 changes: 10 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ type RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfigur
* @constructor
*/
export class Router {

container: Container;

history: History;

viewPorts: Record<string, ViewPort>;
/**
* A registry of registered viewport. Will be used to handle process navigation instruction route loading
* and dom swapping
*/
viewPorts: Record<string, any>;

/**
* List of route configs registered with this router
*/
routes: RouteConfig[];

/**
Expand Down
10 changes: 7 additions & 3 deletions test/activation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import {
activationStrategy,
ActivationStrategy,
NavigationInstruction,
ViewPortInstruction,
RouteConfig,
CanDeactivatePreviousStep,
CanActivateNextStep,
ActivateNextStep,
NavigationInstructionInit,
ViewPortPlan
NavigationInstructionInit
} from '../src/aurelia-router';
import {
ViewPortComponent,
ViewPortInstruction,
ViewPort,
ViewPortPlan
} from '../src/interfaces';
import { ValueOf, createPipelineState, MockPipelineState, MockInstruction } from './shared';

describe('activation', () => {
Expand Down
8 changes: 5 additions & 3 deletions test/app-router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
RouteLoader,
Pipeline,
NavigationInstruction,
ViewPortComponent,
NavigationCommand,
Next,
RouterConfiguration,
ViewPortInstruction,
ViewPort,
PipelineStep
} from '../src/aurelia-router';
import { MockHistory, MockInstruction } from './shared';
import { EventAggregator } from 'aurelia-event-aggregator';
import { History } from 'aurelia-history';
import {
ViewPortComponent,
ViewPortInstruction,
ViewPort
} from '../src/interfaces';

declare module 'aurelia-history' {
interface History {
Expand Down
5 changes: 4 additions & 1 deletion test/navigation-instruction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { MockHistory } from './shared';
import {
AppRouter,
Router,
ViewPortInstruction,
RouterConfiguration,
PipelineProvider
} from '../src/aurelia-router';

import {
ViewPortInstruction
} from '../src/interfaces';

const absoluteRoot = 'http://aurelia.io/docs/';

describe('NavigationInstruction', () => {
Expand Down
12 changes: 9 additions & 3 deletions test/route-loading/load-component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import '../setup';
import { Container } from 'aurelia-dependency-injection';
import { NavigationInstruction, RouteConfig, Router, RouterConfiguration, ViewPortComponent } from '../../src/aurelia-router';
import { NavigationInstruction, RouteConfig, Router, RouterConfiguration } from '../../src/aurelia-router';
import { loadComponent, RouteLoader } from '../../src/route-loading';
import {
ViewPortComponent,
ViewPortInstruction,
ViewPort,
ViewPortPlan
} from '../../src/interfaces';

describe('RouteLoading -- loadComponent()', function loadComponent__Tests() {
describe('RouteLoading -- loadComponent()', function() {
let container: Container;
let router: Router;
let routeLoader: RouteLoader;
let navInstruction: NavigationInstruction;
let config: RouteConfig;
let vpComponent: ViewPortComponent;

beforeEach(function __setup__() {
beforeEach(function() {
routeLoader = {
loadRoute(router: Router, config: RouteConfig, nav: NavigationInstruction): Promise<ViewPortComponent> {
return Promise.resolve(vpComponent);
Expand Down
2 changes: 1 addition & 1 deletion test/route-loading/load-route-step.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NavigationInstruction, Next, PipelineResult, activationStrategy, RouteC
import { createNextFn } from '../../src/next';
import { PipelineStatus } from '../../src/pipeline-status';

describe('RouteLoading -- LoadRouteStep', function _2_LoadRouteStep__Tests() {
describe('RouteLoading -- LoadRouteStep', function() {
let container: Container;
let navInstruction: NavigationInstruction;
let loadRouteStep: LoadRouteStep;
Expand Down
2 changes: 1 addition & 1 deletion test/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ describe('the router', () => {
})
.then(() => router._createNavigationInstruction('foo/123?bar=456'))
.then(() => fail('should have rejected'))
.catch(done);
.catch(() => done());
});
});
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"listFiles": true,
"declaration": false,
"removeComments": false,
"sourceMap": true,
"lib": [
"es2015",
"dom",
Expand Down
5 changes: 5 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"linterOptions": {
"exclude": [
"dist/aurelia-router.d.ts"
]
},
"rules": {
"class-name": true,
"comment-format": [
Expand Down

0 comments on commit e40b0a5

Please sign in to comment.