You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to make use of a "one-off" event with the braintree dropin.
The expectation is that this will work:
dropIn.on('changeActiveView',()=>{console.log('usual changeActiveView handler');});//... later in the codeconstemitOneOff=()=>{console.log('foo');dropIn.off('changeActiveView',emitOneOff);}dropIn.on('changeActiveView',emitOneOff);
Problem is, the event array gets mutated in the when dropIn.off gets called during an emit phase, which shrinks the array, such that the usual event handler is ignored (dropped effectively) when the event is emitted.
This problem is usually dealt with (by many event-emitter libraries) by making a copy of the array during the emit phase, and iterating over an immutable version of that array to ensure all events are called.
Once implemented, a handy one or once function to handle the removal of the event after it being called is a nice to have, not required though.
The text was updated successfully, but these errors were encountered:
Trying to make use of a "one-off" event with the braintree dropin.
The expectation is that this will work:
Problem is, the event array gets mutated in the when
dropIn.off
gets called during anemit
phase, which shrinks the array, such that theusual
event handler is ignored (dropped effectively) when the event is emitted.This problem is usually dealt with (by many event-emitter libraries) by making a copy of the array during the emit phase, and iterating over an immutable version of that array to ensure all events are called.
Once implemented, a handy
one
oronce
function to handle the removal of the event after it being called is anice to have
, not required though.The text was updated successfully, but these errors were encountered: