-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix #30 by using a for loop instead of .forEach #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM, but we decided for the same commit message rules as in openui5, so please prefix your commit message with e.g. [FIX]
Just making sure as mdn notes:
The order of routes is and will not be relevant here? |
Yes, order of routes is currently not of any interest for the dependency analysis. |
I would prefer a more explicit handling of both types as it might be hard to understand for others. At least I was at first thinking that only objects are supported now. But if I'm the only one, I don't mind 😄 |
@codeworrior oh sure. I'll edit the commit message and force push. @matz3 I could do something like if (Array.isArray(routing.routes)) {
routing.routes.forEach(this.visitRoute.bind(this, info))
} else {
for ( let key in routing.routes) {
this.visitRoute(info, routing.routes[key])
}
} and move the loop body to a method ( That way the handling of arrays would not change fromt he current version and objects would be handled like in this pr. Another way would be to use |
Looks good to me 👍 |
While this is pretty cool once understood, I think for the casual reader it involves too much magic (I had to look this up tbh) 😄 What about a good old arrow function? if (Array.isArray(routing.routes)) {
routing.routes.forEach((route) => this.visitRoute(info, route));
} else {
for ( let key in routing.routes) {
this.visitRoute(info, routing.routes[key]);
}
} |
Oh sure, 👍 for the arrow function :D Should I restructure the PR to implement it that way? |
Yes please. I think @codeworrior will also be fine with that 🙂 |
Routes may be defined as an array or object in the manifest. If it its an object we use `for .. in` to iterate over it, for arrays we stay with forEach. Fixes #30
As the rework got a a little big to do without a safety net I added two test cases. While writing this I noticed some other thing the current code might not handle correctly:
The current implementation ignores both cases. I could add a commit to this PR to fix those cases (+test) or do this in another PR (or forget I ever thought about it, if you want me to ;)) |
I had fixed those two issues in a branch of our internal predecessor repo already, but that branch didn't make it into the public repos. That's how I fixed the second: // merge target config with default config
let config = Object.assign({}, routing.config, target);
let module = ModuleName.fromUI5LegacyName(
(config.viewPath ? config.viewPath + "." : "") +
config.viewName, ".view." + config.viewType.toLowerCase() ); If you don't mind, I can push the two fixes on top of your change. It might take some time until I can migrate the old branch to the |
I figured I might as well create a PR for this issue. afaik this should be the "cleanest" solution for this problem the inner body does not care about the routes name anyway.
It hurts me a little bit to remove functional syntax and the fat arrow, but I guess its for the greater good ;)
An alternative would be to use
Object.values(routing.routes).forEach
but that would give no access to the route name at all. With the for loop theres still thekey
if one needs the name.Additionally I guess this is faster than Object.values.