From 5cbbde6d8355b36dc9d53aa8396e31216d26a8a5 Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Wed, 2 Feb 2022 13:45:16 -0800 Subject: [PATCH 1/4] Fix more types --- lib/router/index.ts | 9 ++++++++- lib/router/router.ts | 5 +++-- lib/router/transition-intent/named-transition-intent.ts | 7 ++----- lib/router/utils.ts | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/router/index.ts b/lib/router/index.ts index ef8ed09..4218e18 100644 --- a/lib/router/index.ts +++ b/lib/router/index.ts @@ -8,4 +8,11 @@ export { QUERY_PARAMS_SYMBOL, } from './transition'; export { default as TransitionState, TransitionError } from './transition-state'; -export { default as InternalRouteInfo, IModel, ModelFor, RouteInfo, Route } from './route-info'; +export { + default as InternalRouteInfo, + IModel, + ModelFor, + Route, + RouteInfo, + RouteInfoWithAttributes, +} from './route-info'; diff --git a/lib/router/router.ts b/lib/router/router.ts index a67ce4e..5f966cb 100644 --- a/lib/router/router.ts +++ b/lib/router/router.ts @@ -28,6 +28,7 @@ import { getChangelist, log, merge, + ModelsAndQueryParams, promiseLabel, QueryParamsContainer, } from './utils'; @@ -945,7 +946,7 @@ export default abstract class Router> { @return {String} a URL */ - generate(routeName: string, ...args: ModelFor[]) { + generate(routeName: string, ...args: ModelsAndQueryParams>) { let partitionedArgs = extractQueryParams(args), suppliedParams = partitionedArgs[0], queryParams = partitionedArgs[1]; @@ -1032,7 +1033,7 @@ export default abstract class Router> { return routesEqual && !getChangelist(activeQPsOnNewHandler, queryParams); } - isActive(routeName: string, ...args: ModelFor[] | [...ModelFor[], QueryParamsContainer]) { + isActive(routeName: string, ...args: ModelsAndQueryParams>) { let [contexts, queryParams] = extractQueryParams(args); return this.isActiveIntent(routeName, contexts, queryParams); } diff --git a/lib/router/transition-intent/named-transition-intent.ts b/lib/router/transition-intent/named-transition-intent.ts index ab38e14..c73e129 100644 --- a/lib/router/transition-intent/named-transition-intent.ts +++ b/lib/router/transition-intent/named-transition-intent.ts @@ -9,7 +9,7 @@ import InternalRouteInfo, { import Router, { ParsedHandler } from '../router'; import { TransitionIntent } from '../transition-intent'; import TransitionState from '../transition-state'; -import { extractQueryParams, isParam, merge } from '../utils'; +import { isParam, merge } from '../utils'; export default class NamedTransitionIntent> extends TransitionIntent { name: string; @@ -34,10 +34,7 @@ export default class NamedTransitionIntent> extends Transiti } applyToState(oldState: TransitionState, isIntermediate: boolean): TransitionState { - // TODO: WTF fix me - let partitionedArgs = extractQueryParams([this.name].concat(this.contexts as any)), - pureArgs = partitionedArgs[0], - handlers: ParsedHandler[] = this.router.recognizer.handlersFor(pureArgs[0]); + let handlers: ParsedHandler[] = this.router.recognizer.handlersFor(this.name); let targetRouteName = handlers[handlers.length - 1].handler; diff --git a/lib/router/utils.ts b/lib/router/utils.ts index 0e754ef..dd1ac3e 100644 --- a/lib/router/utils.ts +++ b/lib/router/utils.ts @@ -21,14 +21,14 @@ export function merge(hash: Dict, other?: Dict) { } } +export type ModelsAndQueryParams = T[] | [...T[], QueryParamsContainer]; + /** @private Extracts query params from the end of an array **/ -export function extractQueryParams( - array: T[] | [...T[], QueryParamsContainer] -): [T[], QueryParams | null] { +export function extractQueryParams(array: ModelsAndQueryParams): [T[], QueryParams | null] { let len = array && array.length, head, queryParams; From 6b3d9c9fee05a43fa781a6c2ae076f550be6ceee Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Wed, 2 Feb 2022 13:56:26 -0800 Subject: [PATCH 2/4] Add rsvp to peer dependencies --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 314db70..06460c6 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,8 @@ "typescript": "~4.5.5" }, "peerDependencies": { - "route-recognizer": "^0.3.4" + "route-recognizer": "^0.3.4", + "rsvp": "^4.8.5" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" From 634c06f40955da6abb3284fbfc9451662ec3b6ea Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Thu, 3 Feb 2022 12:02:09 -0800 Subject: [PATCH 3/4] Add RSVP types --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index 06460c6..0c48604 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@babel/plugin-transform-modules-commonjs": "^7.12.1", "@types/node": "^14.14.6", "@types/qunit": "^2.9.6", + "@types/rsvp": "^4.0.4", "@typescript-eslint/eslint-plugin": "^5.10.2", "@typescript-eslint/parser": "^5.10.2", "babel-plugin-debug-macros": "^0.3.3", diff --git a/yarn.lock b/yarn.lock index 79de9ac..f4ea259 100644 --- a/yarn.lock +++ b/yarn.lock @@ -540,6 +540,11 @@ "@types/glob" "*" "@types/node" "*" +"@types/rsvp@^4.0.4": + version "4.0.4" + resolved "https://registry.yarnpkg.com/@types/rsvp/-/rsvp-4.0.4.tgz#55e93e7054027f1ad4b4ebc1e60e59eb091e2d32" + integrity sha512-J3Ol++HCC7/hwZhanDvggFYU/GtxHxE/e7cGRWxR04BF7Tt3TqJZ84BkzQgDxmX0uu8IagiyfmfoUlBACh2Ilg== + "@types/serve-static@*": version "1.13.4" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.4.tgz#6662a93583e5a6cabca1b23592eb91e12fa80e7c" From 41e1150064a0d59ceef54e86f1fb9a1ffdf0d0f4 Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Thu, 3 Feb 2022 12:04:39 -0800 Subject: [PATCH 4/4] fixup! Fix more types --- lib/router/router.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/router/router.ts b/lib/router/router.ts index 5f966cb..437ff84 100644 --- a/lib/router/router.ts +++ b/lib/router/router.ts @@ -30,7 +30,6 @@ import { merge, ModelsAndQueryParams, promiseLabel, - QueryParamsContainer, } from './utils'; export interface SerializerFunc {