erikringsmuth / app-router

Router for Web Components
https://erikringsmuth.github.io/app-router/
MIT License
610 stars 83 forks source link

Fire 'template-not-found' event on route and router when template is null #102

Closed nomego closed 5 months ago

nomego commented 9 years ago

If the HTML import succeeds but the expected template can't be found (no template tag or wrong template ID), app router currently errors out with: Uncaught TypeError: Cannot use 'in' operator to search for 'createInstance' in null

This commit prevents that error and instead fires a template-not-found event.

erikringsmuth commented 9 years ago

For something like this or the other import-error PR, would you ever be handling the event in production code or would this be more for debugging? If it's more for debugging I think we should throw an error with a custom message telling the developer what went wrong. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

nomego commented 9 years ago

We currently use this in production code.

In our use case, in addition to any pre-registered routes, we register a route for whatever URL is being accessed dynamically in the state-change event, which causes app-router to try to fetch that view / template (ad-hoc routing). In any case we want something to react on, throwing an error can't be caught by the outer application in this case. It could be done in addition to the event, but it's nothing we would need. The import-error would be our client side 404 equivalent and we'd want to show a "this page doesn't exist". The template-not-found (some 4xx/5xx equivalent) event would not have any differentiating significance from import-error to the end user but we'd want the ability to register an automatic error report "behind the scenes". The events could however share the same event name and contain the specifics in the event information, if that fits the project better.

jmalonzo commented 7 years ago

@nomego Thanks for this.

The events could however share the same event name and contain the specifics in the event information, if that fits the project better.

I probably prefer this and re-use import-error. Would that cover your use-case?