Skip to content

Commit 39a2a05

Browse files
author
Anthony Du Pont
committed
🐛 Fix Event Binding
1 parent 36c096e commit 39a2a05

File tree

25 files changed

+40
-20
lines changed

25 files changed

+40
-20
lines changed

dist/highway.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ class core_Core extends tiny_emitter_default.a {
479479
this.From = new (helpers_Helpers.getRenderer(this.props.slug, this.renderers))(this.props);
480480
this.From.init();
481481

482+
// Events
483+
this._click = this.click.bind(this);
484+
482485
// Listen the `popstate` on the window to run the router each time an
483486
// history entry changes. Basically everytime the backward/forward arrows
484487
// are triggered by the user.
@@ -534,7 +537,7 @@ class core_Core extends tiny_emitter_default.a {
534537

535538
// We then loop over each one of them to bind the `click` event.
536539
for (const link of this.links) {
537-
link.addEventListener('click', this.click.bind(this));
540+
link.addEventListener('click', this._click);
538541
}
539542
}
540543

@@ -544,7 +547,7 @@ class core_Core extends tiny_emitter_default.a {
544547
unbind() {
545548
// We then loop over each one of them to unbind the `click` event.
546549
for (const link of this.links) {
547-
link.removeEventListener('click', this.click.bind(this));
550+
link.removeEventListener('click', this._click);
548551
}
549552
}
550553

@@ -702,12 +705,12 @@ class core_Core extends tiny_emitter_default.a {
702705
// We trigger an event when the new content is added to the DOM.
703706
this.emit('NAVIGATE_IN', this.To, this.state);
704707

705-
// Bind events
706-
this.bind();
707-
708708
// Now we show our content!
709709
await this.To.show();
710710

711+
// Bind events
712+
this.bind();
713+
711714
// We reset our status variables.
712715
this.navigating = false;
713716

dist/highway.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/highway.min.js.gz

10 Bytes
Binary file not shown.

examples/basic-anchor/dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<article router-view="home">
1818
<h1>Home</h1>
1919
<p>Welcome on your website!</p>
20+
<p><a href="./page.html">Go to page</a></p>
2021
</article>
2122
</main>
2223
<script type="application/javascript" src="./index.js"></script>

0 commit comments

Comments
 (0)