Skip to content

Commit

Permalink
feat(events): add checks in DEBUG mode when removing event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
localvoid committed May 27, 2018
1 parent c25e3eb commit a28cde2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/ivi/src/events/native_event_dispatcher.ts
Expand Up @@ -108,20 +108,26 @@ export function removeBeforeNativeEvent<E extends Event>(
source: NativeEventDispatcher<E>,
cb: (e: SyntheticNativeEvent<E>) => void,
): void {
if (source.before !== null) {
unorderedArrayDelete(source.before, source.before.indexOf(cb));
decDependencies(source);
if (DEBUG) {
if (source.before === null || source.before.indexOf(cb) === -1) {
throw new Error("removeBeforeNativeEvent() failed, unable to find registered callback");
}
}
unorderedArrayDelete(source.before!, source.before!.indexOf(cb));
decDependencies(source);
}

export function removeAfterNativeEvent<E extends Event>(
source: NativeEventDispatcher<E>,
cb: (e: SyntheticNativeEvent<E>) => void,
): void {
if (source.after !== null) {
unorderedArrayDelete(source.after, source.after.indexOf(cb));
decDependencies(source);
if (DEBUG) {
if (source.after === null || source.after.indexOf(cb) === -1) {
throw new Error("removeAfterNativeEvent() failed, unable to find registered callback");
}
}
unorderedArrayDelete(source.after!, source.after!.indexOf(cb));
decDependencies(source);
}

function incDependencies<E extends Event>(source: NativeEventDispatcher<E>): void {
Expand Down

0 comments on commit a28cde2

Please sign in to comment.