Skip to content

Commit

Permalink
Merge pull request #331 from tildeio/more-type-fixes
Browse files Browse the repository at this point in the history
More type fixes
  • Loading branch information
wagenet authored Feb 3, 2022
2 parents ffbdf57 + 41e1150 commit edcbb7f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
9 changes: 8 additions & 1 deletion lib/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
6 changes: 3 additions & 3 deletions lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
getChangelist,
log,
merge,
ModelsAndQueryParams,
promiseLabel,
QueryParamsContainer,
} from './utils';

export interface SerializerFunc<T extends IModel> {
Expand Down Expand Up @@ -945,7 +945,7 @@ export default abstract class Router<R extends Route<{}>> {
@return {String} a URL
*/
generate(routeName: string, ...args: ModelFor<R>[]) {
generate(routeName: string, ...args: ModelsAndQueryParams<ModelFor<R>>) {
let partitionedArgs = extractQueryParams(args),
suppliedParams = partitionedArgs[0],
queryParams = partitionedArgs[1];
Expand Down Expand Up @@ -1032,7 +1032,7 @@ export default abstract class Router<R extends Route<{}>> {
return routesEqual && !getChangelist(activeQPsOnNewHandler, queryParams);
}

isActive(routeName: string, ...args: ModelFor<R>[] | [...ModelFor<R>[], QueryParamsContainer]) {
isActive(routeName: string, ...args: ModelsAndQueryParams<ModelFor<R>>) {
let [contexts, queryParams] = extractQueryParams(args);
return this.isActiveIntent(routeName, contexts, queryParams);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/router/transition-intent/named-transition-intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<R extends Route<{}>> extends TransitionIntent<R> {
name: string;
Expand All @@ -34,10 +34,7 @@ export default class NamedTransitionIntent<R extends Route<{}>> extends Transiti
}

applyToState(oldState: TransitionState<R>, isIntermediate: boolean): TransitionState<R> {
// 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;

Expand Down
6 changes: 3 additions & 3 deletions lib/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export function merge(hash: Dict<unknown>, other?: Dict<unknown>) {
}
}

export type ModelsAndQueryParams<T> = T[] | [...T[], QueryParamsContainer];

/**
@private
Extracts query params from the end of an array
**/
export function extractQueryParams<T>(
array: T[] | [...T[], QueryParamsContainer]
): [T[], QueryParams | null] {
export function extractQueryParams<T>(array: ModelsAndQueryParams<T>): [T[], QueryParams | null] {
let len = array && array.length,
head,
queryParams;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -66,7 +67,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"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit edcbb7f

Please sign in to comment.