question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unbinding or .off() ?

See original GitHub issue

Sorry if this is a silly question or the wrong place to ask it but I was curious, is there a method for unbinding postRobot listeners?

For example: Previously in my react components I was doing something like…

componentWillMount() {
     window.addEventListener('message', this.onMessage);
}

componentWillUnmount() {
    window.removeEventListener('message', this.onMessage);
}

Now with postRobot I have something like…

componentWillMount() {
    postRobot.on('ON_MESSAGE', { window: window.parent }, (event) => {
      this.onMessage(event);
    });
}

So i was wondering do I need to unbind? I was imagining something like…

componentWillUnmount() {
    postRobot.off('ON_MESSAGE');
}

Or is this automatically handled since each request is hashed as a new postMessage?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bluepnumecommented, Mar 8, 2017

Definitely makes sense. Let me re-open this issue while I mull it over.

0reactions
TylerBarnescommented, Oct 14, 2018

hmm, nevermind! It looks like those “global” variables are still scoped to my component. Not very clean but I don’t really care since it seems to work well! Thanks for this library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between jQuery off() and unbind()
Using off is the modern way, unbind is the old way. Use off .
Read more >
jQuery unbind() Method - W3Schools
The unbind() method was deprecated in version 3.0. Use the off() method instead. The unbind() method removes event handlers from selected elements. This...
Read more >
.unbind() | jQuery API Documentation
A string containing one or more DOM event types, such as "click" or "submit," or custom event names. Unbinds the corresponding 'return false'...
Read more >
What's the relationship between jQuery bind/unbind and on/off?
(Delegated events are bound to a parent element rather than the element that we want to handle the event for.
Read more >
Binding and unbinding of event handlers - plainJS
Binding and unbinding of event handlers. How to attach or detach a handler function to an event, such as click, focus, or submit....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found