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

How to ensure every route emits DOMContentLoaded? #664

Closed
NetOpWibby opened this issue Jun 8, 2018 · 2 comments
Closed

How to ensure every route emits DOMContentLoaded? #664

NetOpWibby opened this issue Jun 8, 2018 · 2 comments

Comments

@NetOpWibby
Copy link

NetOpWibby commented Jun 8, 2018

Expected behavior

emitter.on("DOMContentLoaded", function () {
  log("hi"); // returns "hi" in the console
});

Actual behavior

emitter.on("DOMContentLoaded", function () {
  log("hi"); // returns nothing in the console
});

Steps to reproduce behavior

Start writing a plugin like this:

// client.js
app.use(require("/path/to/my-plugin")());
// my-plugin.js
function myPlugin () {
  return function (state, emitter) {
    emitter.on("DOMContentLoaded", () => {
      log("hi");
    });
  };
}

module.exports = exports = myPlugin;
@goto-bus-stop
Copy link
Member

DOMContentLoaded is supposed to fire only once per page load, even if you navigate to other routes. There is a navigate event that is fired when you navigate to other routes: https://github.com/choojs/choo#navigatestateeventsnavigate

@NetOpWibby
Copy link
Author

I managed to get something working but in the end, hooking into Fastify worked for my purposes. I'm super delayed in saying this but, thanks for the assistance.

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

No branches or pull requests

3 participants