diff --git a/internal/events/dispatch-hooks.ts b/internal/events/dispatch-hooks.ts new file mode 100644 index 000000000..e67f491ff --- /dev/null +++ b/internal/events/dispatch-hooks.ts @@ -0,0 +1,176 @@ +/** + * @license + * Copyright 2023 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * A symbol used to access dispatch hooks on an event. + */ +const dispatchHooks = Symbol('dispatchHooks'); + +/** + * An `Event` with additional symbols for dispatch hooks. + */ +interface EventWithDispatchHooks extends Event { + [dispatchHooks]: EventTarget; +} + +/** + * Add a hook for an event that is called after the event is dispatched and + * propagates to other event listeners. + * + * This is useful for behaviors that need to check if an event is canceled. + * + * The callback is invoked synchronously, which allows for better integration + * with synchronous platform APIs (like `
` or `