Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/current router #1819

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Feat/current router #1819

wants to merge 5 commits into from

Conversation

brandonseydel
Copy link
Member

Pull Request

πŸ“– Description

🎫 Issues

πŸ‘©β€πŸ’» Reviewer Notes

πŸ“‘ Test Plan

⏭ Next Steps

@bigopon
Copy link
Member

bigopon commented Dec 6, 2023

@jwx @Sayan751 can you help with reviewing the respective part in this PR? If you feel like to, tests are also needed πŸ˜‰

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: 33 lines in your changes are missing coverage. Please review.

Comparison is base (703d275) 88.53% compared to head (c555aed) 88.41%.
Report is 3 commits behind head on master.

Files Patch % Lines
packages/router-lite/src/route-callback.ts 14.28% 18 Missing ⚠️
packages/router/src/route-callback.ts 11.76% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1819      +/-   ##
==========================================
- Coverage   88.53%   88.41%   -0.13%     
==========================================
  Files         248      250       +2     
  Lines       22290    22326      +36     
  Branches     5182     5181       -1     
==========================================
+ Hits        19735    19740       +5     
- Misses       2555     2586      +31     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

Copy link
Member

@bigopon bigopon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, though we need some, at least preliminary, tests

snapshot: Partial<Navigation>;
};

export const IRoute = DI.createInterface<IRoute>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to decorate this with /*@__PURE__*/ comment for tree shaking

Suggested change
export const IRoute = DI.createInterface<IRoute>();
export const IRoute = /*@__PURE__*/ DI.createInterface<IRoute>();


export const IRoute = DI.createInterface<IRoute>();

export const RouteCallback = Registration.cachedCallback(IRoute, (container) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely to be the same

Suggested change
export const RouteCallback = Registration.cachedCallback(IRoute, (container) => {
export const RouteCallback = /*@__PURE__*/ Registration.cachedCallback(IRoute, (container) => {

}, returnVal) ;
};

export const RouteCallback = Registration.cachedCallback(IRoute, (container) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree shaking related comment

Suggested change
export const RouteCallback = Registration.cachedCallback(IRoute, (container) => {
export const RouteCallback = /*@__PURE__*/ Registration.cachedCallback(IRoute, (container) => {

queryParams: TQueryParams;
snapshot: Partial<NavigationEndEvent>;
};
export const IRoute = DI.createInterface<IRoute>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const IRoute = DI.createInterface<IRoute>();
export const IRoute = /*@__PURE__*/ DI.createInterface<IRoute>();

Copy link
Contributor

@Sayan751 Sayan751 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandonseydel Thank you for this. Reviewed the router-lite part. Seems logical; however, as there are no tests, it is hard to verify that it works for different routing scenarios. Please consider writing tests.

route.path = finalInstructions.toPath();
route.url = finalInstructions.toUrl(true, router.options._urlParser);
route.title = localWindow.document.title;
route.queryParams = Array.from(queryParams).reduce<Record<string, string>>((acc, [key, value]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed when queryParams is of type URLSearchParams.

acc[key] = value;
return acc;
}, {});
route.params = flattenParams(children);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why flatten parameter? This results in loss of information.

import { IRouter } from './router';
import { Params, ViewportInstructionTree } from './instructions';

export type IRoute<TParams = Record<string, string | undefined>, TQueryParams = Record<string, string | undefined>> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a class.

path: string;
url: string;
params: TParams;
queryParams: TQueryParams;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be of type URLSearchParams.

url: string;
params: TParams;
queryParams: TQueryParams;
snapshot: Partial<NavigationEndEvent>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the name snapshot to be very ambiguous. I would remove it completely, because semantically, the event cannot be a part of the current route. Furthermore, I would like to know the use-cases where this would be beneficial.

If kept, I would suggest removing the Partial, as why would the information provided by the framework be partial?

title: string;
path: string;
url: string;
params: TParams;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra TParams is not needed, as there is already a Params type should for this very purpose.

Moreover, considering multi-level routing, this should be a map (for example, Map<component,Params>) of some sort.

};

export const RouteCallback = Registration.cachedCallback(IRoute, (container) => {
const route: IRoute = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instantiate the class instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants