Skip to content

Commit

Permalink
Merge pull request #19259 from xg-wang/router-type
Browse files Browse the repository at this point in the history
Improve internal router type
  • Loading branch information
rwjblue committed Nov 11, 2020
2 parents f2104f2 + eff0aef commit b35106e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
23 changes: 14 additions & 9 deletions packages/@ember/-internals/routing/lib/system/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let uuid = 0;
export interface RouteOptions {
path?: string;
resetNamespace?: boolean;
serialize?: any;
serialize?: (model: {}, params: string[]) => { [key: string]: unknown | undefined };
overrideNameAssertion?: boolean;
}

Expand Down Expand Up @@ -43,16 +43,14 @@ function isOptions(value?: RouteOptions | DSLCallback): value is RouteOptions {
}
export interface DSLImplOptions {
enableLoadingSubstates: boolean;
overrideNameAssertion?: boolean;
engineInfo?: EngineInfo;
addRouteForEngine(name: string, routeOptions: EngineRouteInfo): void;
resolveRouteMap(name: string): Factory<any, any>;
path?: string;
}

export default class DSLImpl implements DSL {
parent: string | null;
matches: any[];
matches: Array<Object | undefined>;
enableLoadingSubstates: boolean;
explicitIndex = false;
options: DSLImplOptions;
Expand All @@ -69,7 +67,7 @@ export default class DSLImpl implements DSL {
route(name: string, callback: DSLCallback): void;
route(name: string, options: RouteOptions): void;
route(name: string, options: RouteOptions, callback: DSLCallback): void;
route(name: string, _options?: RouteOptions | DSLCallback, _callback?: DSLCallback) {
route(name: string, _options?: RouteOptions | DSLCallback, _callback?: DSLCallback): void {
let options: RouteOptions;
let callback: Option<DSLCallback> = null;

Expand Down Expand Up @@ -127,9 +125,13 @@ export default class DSLImpl implements DSL {
createRoute(this, name, options);
}
}
/* eslint-enable no-dupe-class-members */

push(url: string, name: string, callback?: MatchCallback, serialize?: any) {
push(
url: string,
name: string,
callback?: MatchCallback,
serialize?: (model: {}, params: string[]) => { [key: string]: unknown | undefined }
): void {
let parts = name.split('.');

if (this.options.engineInfo) {
Expand Down Expand Up @@ -163,12 +165,15 @@ export default class DSLImpl implements DSL {

return (match) => {
for (let i = 0; i < dslMatches.length; i += 3) {
match(dslMatches[i]).to(dslMatches[i + 1], dslMatches[i + 2]);
match(dslMatches[i] as string).to(
dslMatches[i + 1] as string,
dslMatches[i + 2] as MatchCallback
);
}
};
}

mount(_name: string, options: MountOptions = {}) {
mount(_name: string, options: MountOptions = {}): void {
let engineRouteMap = this.options.resolveRouteMap(_name);
let name = _name;

Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/-internals/routing/lib/system/engines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export interface EngineInfo {

export interface EngineRouteInfo extends EngineInfo {
localFullName: string;
serializeMethod?: any;
serializeMethod?: (model: {}, params: string[]) => { [key: string]: unknown | undefined };
}
7 changes: 5 additions & 2 deletions packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ import EmberRouter, { QueryParam } from './router';

export const ROUTE_CONNECTIONS = new WeakMap();

export function defaultSerialize(model: {}, params: string[]) {
export function defaultSerialize(
model: {},
params: string[]
): { [key: string]: unknown } | undefined {
if (params.length < 1 || !model) {
return;
}
Expand All @@ -67,7 +70,7 @@ export function defaultSerialize(model: {}, params: string[]) {
return object;
}

export function hasDefaultSerialize(route: Route) {
export function hasDefaultSerialize(route: Route): boolean {
return route.serialize === defaultSerialize;
}

Expand Down

0 comments on commit b35106e

Please sign in to comment.