Refactor router, fixes #2505 and #2778#3027
Conversation
…ixes MithrilJS#2778 Code that sets `fireAsync` to null and uses `hashchange` when `pushState` is not supported was removed in v2.2.0. However, some of that code and comments remained.
…rilJS#2505 This ensures that the reset logic is executed even when there is an internal redirect to the default route in case of failure.
dead-claudia
left a comment
There was a problem hiding this comment.
While we're at it, could you just make route.set the actual definition and just have everything call route.set instead of setPath?
That not only will save some more gzip size, it'll also make it so people can hack into route change and transparently wrap it for more advanced use cases like capturing previous paths for more detailed analytics.
|
@dead-claudia Thank you for your review comment. |
The `state` is represented as a three-valued integer, but due to the `sentinel === currentResolver` condition, a boolean state appears to be sufficient in practice. This improves code readability and further reduces the bundle size.
|
@dead-claudia |
Since the `state` update process has been removed, `onbeforeupdate` is no longer needed. This further reduces the bundle size.
In the `update()` function, even if the `comp` parameter is undefined, it falls back to "div". This commit slightly reduces the bundle size and optimizes the component fallback process.
|
I added some simple refactoring and reduced the bundle size. |
Description
This PR refactors the router code to fix two issues (#2505 and #2778).
This will make the router code a little easier to read and reduce the bundle size (8.97kB(gzipped)).
Motivation and Context
I wanted to close two router-related issues (#2505 and #2778) that had been left unresolved for a long time.
Although these issues do not seem to cause any big problems even if they are not fixed, the fixed bundle size seemed to be smaller than I had expected.
How Has This Been Tested?
npm run testTypes of changes
Checklist