Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

add 'removeListener' method to have a way to remove the NFC listener #12

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

clickclickonsal
Copy link

Fix for Issue #8

@henrikra
Copy link

henrikra commented Aug 7, 2017

This is not ready yet since you should be able to specify which listeners you want to remove. For example:

class Example extends Component {
  componentDidMount() {
    NFC.addListener(this.logPayload);
  }

  componentWillUnmount() {
    NFC.removeListener(this.logPayload);
  }

  logPayload(payload) {
    console.log(payload);
  }
}

This way I can specify which listener I can remove :)

index.js Outdated
DeviceEventEmitter.removeListener(NFC_DISCOVERED);
_listeners.splice(0, _listeners.length);
_registeredToEvents = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What _registeredToEvents variable means in general?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_registeredToEvents keeps track if the DeviceEventEmitter.addListener is still attached.
This only needs to be set to false if DeviceEventEmitter is removed.
I created a removeAllListeners method because this truly removes the eventListener.
Perhaps I should call removeAllListeners destroy instead?

@clickclickonsal
Copy link
Author

The more & more I look at this code, I think it should look something like this instead.

NFC.initialize()
NFC.addListener(name, callback)
NFC.removeListener(name)
NFC.removeAllListeners()
NFC.destroy()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants