With the following addListener and removeListener, the listener remains active (i.e. doesn't get removed):
Realm.addListener('change', this.realmChanged.bind(this));
Realm.removeListener('change', this.realmChanged.bind(this));
// A change to Realm will still trigger a call to realmChanged().
Am I using this correctly?
Thanks!
Josh
Okay, I figured the .bind(this) was causing issues so I was able to get the following to work just fine:
this.realmChanged = this.realmChanged.bind(this);
Realm.addListener('change', this.realmChanged);
Realm.removeListener('change', this.realmChanged);
I'm not a JS expert so was that an obvious solution?
Also, it would be useful to put an example of removeListener in your non-API docs so others don't accidentally fall into a similar trap.
Thanks!
Great suggestion @joshuapinter. We'll do that! We're going to be redoing the docs for that very soon because we are expanding on where you can listen for events.
Most helpful comment
Great suggestion @joshuapinter. We'll do that! We're going to be redoing the docs for that very soon because we are expanding on where you can listen for events.