Skip to content

Commit

Permalink
feat(): emit warning when emitting event while disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Aug 6, 2019
1 parent fa7d29f commit 053a7df
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/runtime/event-emitter.ts
Expand Up @@ -5,15 +5,20 @@ import { getElement, win } from '@platform';


export const createEvent = (ref: d.RuntimeRef, name: string, flags: number) => {
const elm = getElement(ref);
const elm = getElement(ref) as HTMLElement;
return {
emit: (detail: any) => elm.dispatchEvent(
new (BUILD.hydrateServerSide ? (win as any).CustomEvent : CustomEvent)(name, {
bubbles: !!(flags & EVENT_FLAGS.Bubbles),
composed: !!(flags & EVENT_FLAGS.Composed),
cancelable: !!(flags & EVENT_FLAGS.Cancellable),
detail
})
)
emit: (detail: any) => {
if (BUILD.isDev && !elm.isConnected) {
console.warn(`The "${name}" event was emitted, but the dispatcher node is not longer connected to the dom.`);
}
return elm.dispatchEvent(
new (BUILD.hydrateServerSide ? (win as any).CustomEvent : CustomEvent)(name, {
bubbles: !!(flags & EVENT_FLAGS.Bubbles),
composed: !!(flags & EVENT_FLAGS.Composed),
cancelable: !!(flags & EVENT_FLAGS.Cancellable),
detail
})
);
}
};
};

0 comments on commit 053a7df

Please sign in to comment.