abstract-state-router
abstract-state-router copied to clipboard
stateError and stateChangeError events should be combined
Yeah, it's really confusing what the difference between them is, and worse, I don't think the tests do a good job of asserting that they do the things specific to them (why is it a stateError and not a stateChangeError to navigate to a nonexistent state?).
A couple things:
- is there any real distinction to be found?
- Is it notable that some error events only happen between state changes starting and ending? I think that might be the current logic. Maybe this could be indicated by just a boolean between state changes.
- how significant is the difference between an error happening in a user-land function (like the provided
activatefunction, or event handlers) and some other error happening (not able to turn a state name into a route whengois called or not being able to find a matching state whenevaluateCurrentRouteis called)
- are any of these state routing issues serious enough to emit actual
errorevents?
current stateError events:
https://github.com/TehShrike/abstract-state-router/blob/f5983192fa5dc76f24a817140d8c3550ce15138f/index.js#L176 - I think this would only happen if a stateChangeAttempt listener threw an error. This should probably just be thrown in another tick instead of being emitted as a state-router error.
Same for https://github.com/TehShrike/abstract-state-router/blob/f5983192fa5dc76f24a817140d8c3550ce15138f/index.js#L288 which is just catching possible errors in event listener code.
For https://github.com/TehShrike/abstract-state-router/blob/f5983192fa5dc76f24a817140d8c3550ce15138f/index.js#L331 in evaluateCurrentRoute, the only place I see that could be causing that error would be if prototypalStateHolder.guaranteeAllStatesExist threw, which means that someone tried to navigate to a state that doesn't exist.
Maybe that should just throw straight out as well? It seems like a different kind of "not found" than the traditional one I'd imagine existing, which would be "there was no matching route for the url in the location bar".
I would expect to be directed to the hashBrownRouter.setDefault (404) state if the state doesn't exist.
If there wasn't a hash, I would expect to go to the fallbackState.
If I call state.go('this.route.does.not.exist'), I would expect to have an error thrown.