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(linking-tool): add support for links tree #39

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

Conversation

wjanaszek
Copy link
Contributor

No description provided.

@wjanaszek wjanaszek force-pushed the feature/linking-tool branch 2 times, most recently from 4a437d6 to 51c3123 Compare January 15, 2020 14:08
@wjanaszek wjanaszek force-pushed the feature/linking-tool branch 13 times, most recently from 934c1e2 to f7d50d8 Compare January 17, 2020 15:08
@wjanaszek
Copy link
Contributor Author

Work in progress

@wjanaszek wjanaszek force-pushed the feature/linking-tool branch 7 times, most recently from 7d18f6e to a74b733 Compare January 30, 2020 15:02
private findNodeWithPath(linkPath: Link[]): LinksTree {
let linksTree = { ...this.linksTree };
linkPath.forEach(link => {
linksTree = linksTree[link.type] as LinksTree;

Choose a reason for hiding this comment

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

I would check if property is really LinksTree to avoid unhandled errors if wrong path is provided.

embedded?: { id: string };
queryParams?: Params;
skipLocationChange?: boolean;
[key: string]: any;

Choose a reason for hiding this comment

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

Is there any reason why is interpolatable parameters map not nested under dedicated property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure, it's an old code from another project. I think we can remove this for now, if some property will be missing, the change has to be done in this library.

Choose a reason for hiding this comment

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

I'm not sure we can simply remove this. I believe it is used to interpolate url params (like "somePath/:id/update") e.g. search for utils.interpolate(url, params). What I mean is to move this params under some prop, e.g.
skipLocationChange?: boolean; params?: { [key: string]: any; }
and then pass only obj.params instead of obj to the interpolation function. Is it more clear now?

export function convertParamsToQueryParamsString(params: Params): string {
let result = '?';
Object.keys(params).forEach((key: string) => {
result += `${key}=${params[key]}&`;

Choose a reason for hiding this comment

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

If particular param value is an array of strings (common case), with this implementation it will be rendered like: "?param1=val1,val2&param2=...". This kind of multi-value query param is not correctly parsed by Angular then into Params object again (you will get {param1: "val1,val2", ...}). It's better to convert it to the following form instead: "?param1=val1&param1=val2&param2=...". This kind of url could be correctly parsed by the Angular then (you will get {param1: ["val1", "val2"], ... }) and is also widely supported by many web frameworks.

.concat('-routing.module.ts');
}

private static resolveLoadChildrenForIvy(loadChildrenAssignment: PropertyAssignment): string {

Choose a reason for hiding this comment

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

I think this is not the best name. You could not use Ivy and use dynamic imports for routing at the same time and still this function will be used. I would name this function like "resolveLoadChildrenFromDynamicImport" (and the other function "resolveLoadChildrenFromStringImport") or something similiar.

The other thing is if you should use "resolveLoadChildren" or "resolveChildModule(Path? Name?)" instead, in my opinion it is more descriptive.

loadChildrenAssignment.getInitializer() as ArrowFunction
)
.split(/([A-Z]?[^A-Z]*)/g)
.filter(word => !!word && word !== 'Module' && word !== 'Feature');

Choose a reason for hiding this comment

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

I'm not sure why do you filter out 'Module' and 'Feature' words here. Many modules have 'Feature' word in their name, so it could break filename of routing module. I can imagine some apps could also have "Module" word somewhere in their module names (not only in the suffix). These are not preserved words netiher in JS, nor in Angular, so I don't think we can simply filter them like that.

- create some enum with link types, like the following:
```
export enum LinkType {
Admin = 'admin',

Choose a reason for hiding this comment

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

I'm not sure it will work with current implementation. It seems like enum item name and its value must match exactly 1:1, because I think you use item name instead of value when saving items to map/tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I will fix it.

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.

3 participants