Phedg1
Phedg1

Reputation: 1978

Firebase Database Remove Listener That Didn't Exist ValueChanged -=?

I'm integrating Firebase Database into my Unity project. I need one of my functions to add and remove the ValueChanged listener from different database references based on input. When the function to remove the listener is called it is not guaranteed that a listener will be in place. I would like to know what this results in.

FirebaseDatabase.DefaultInstance.GetReference("exampleChild").Child(currentUserID).ValueChanged -= HandleValueChanged;

Do the negatives stack, so that if I would call this later, nothing would happen? Are the negatives ignored if there is no value to remove?

FirebaseDatabase.DefaultInstance.GetReference("exampleChild").Child(currentUserID).ValueChanged -= HandleValueChanged;
FirebaseDatabase.DefaultInstance.GetReference("exampleChild").Child(currentUserID).ValueChanged += HandleValueChanged;

Upvotes: 0

Views: 711

Answers (1)

Galandil
Galandil

Reputation: 4249

No, they don't stack.

Basically, if you try to unregister twice (or more), from the 2nd time on nothing happens (with no exceptions).

So, the last two lines of your code will result in the HandValueChanged registered to ValueChanged, regardless if it was registered or not before.

Upvotes: 1

Related Questions