@graphql-yoga/typed-event-target
Advanced tools
Comparing version 0.1.1 to 1.0.0-alpha-20220920120038-f79bce94
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveGlobalConfig = void 0; | ||
const resolveGlobalConfig = (api = globalThis) => { | ||
if (!api.Event || !api.EventTarget) { | ||
throw new Error(` | ||
[@graphql-yoga/subscription] 'createPubSub' uses the Event and EventTarget APIs. | ||
In modern JavaScript environments those are part of the global scope. However, if you are using an older version of Node.js (< 16.x.x), those APIs must be polyfilled. | ||
You can provide polyfills to the 'createPubSub' function: | ||
\`\`\` | ||
// yarn install --exact event-target-polyfill@0.0.3 | ||
import 'event-target-polyfill' | ||
const pubSub = createPubSub() | ||
\`\`\` | ||
Alternatively, you can provide your own custom implementation. | ||
\`\`\` | ||
const pubSub = createPubSub({ | ||
event: { | ||
Event, | ||
EventTarget, | ||
} | ||
}) | ||
\`\`\` | ||
`); | ||
} | ||
return globalThis; | ||
}; | ||
exports.resolveGlobalConfig = resolveGlobalConfig; |
@@ -1,29 +0,1 @@ | ||
export const resolveGlobalConfig = (api = globalThis) => { | ||
if (!api.Event || !api.EventTarget) { | ||
throw new Error(` | ||
[@graphql-yoga/subscription] 'createPubSub' uses the Event and EventTarget APIs. | ||
In modern JavaScript environments those are part of the global scope. However, if you are using an older version of Node.js (< 16.x.x), those APIs must be polyfilled. | ||
You can provide polyfills to the 'createPubSub' function: | ||
\`\`\` | ||
// yarn install --exact event-target-polyfill@0.0.3 | ||
import 'event-target-polyfill' | ||
const pubSub = createPubSub() | ||
\`\`\` | ||
Alternatively, you can provide your own custom implementation. | ||
\`\`\` | ||
const pubSub = createPubSub({ | ||
event: { | ||
Event, | ||
EventTarget, | ||
} | ||
}) | ||
\`\`\` | ||
`); | ||
} | ||
return globalThis; | ||
}; | ||
export {}; |
{ | ||
"name": "@graphql-yoga/typed-event-target", | ||
"version": "0.1.1", | ||
"version": "1.0.0-alpha-20220920120038-f79bce94", | ||
"description": "", | ||
"sideEffects": false, | ||
"dependencies": { | ||
@@ -6,0 +7,0 @@ "@repeaterjs/repeater": "^3.0.4", |
@@ -1,20 +0,12 @@ | ||
export declare type TypedEvent = Event & { | ||
data?: unknown; | ||
}; | ||
export interface TypedEventListener<TEvent extends TypedEvent> extends EventListener { | ||
export interface TypedEventListener<TEvent extends CustomEvent> { | ||
(evt: TEvent): void; | ||
} | ||
export interface TypedEventListenerObject<TEvent extends TypedEvent> extends EventListener { | ||
export interface TypedEventListenerObject<TEvent extends CustomEvent> { | ||
handleEvent(object: TEvent): void; | ||
} | ||
export declare type TypedEventListenerOrEventListenerObject<TEvent extends TypedEvent> = TypedEventListener<TEvent> | TypedEventListenerObject<TEvent>; | ||
export interface TypedEventTarget<TEvent extends TypedEvent> extends EventTarget { | ||
addEventListener(type: string, callback: TypedEventListenerOrEventListenerObject<TEvent>, options?: AddEventListenerOptions | boolean): void; | ||
export declare type TypedEventListenerOrEventListenerObject<TEvent extends CustomEvent> = TypedEventListener<TEvent> | TypedEventListenerObject<TEvent>; | ||
export interface TypedEventTarget<TEvent extends CustomEvent> extends EventTarget { | ||
addEventListener(type: string, callback: TypedEventListenerOrEventListenerObject<TEvent> | null, options?: AddEventListenerOptions | boolean): void; | ||
dispatchEvent(event: TEvent): boolean; | ||
removeEventListener(type: string, callback: TypedEventListenerOrEventListenerObject<TEvent>, options?: EventListenerOptions | boolean): void; | ||
removeEventListener(type: string, callback: TypedEventListenerOrEventListenerObject<TEvent> | null, options?: EventListenerOptions | boolean): void; | ||
} | ||
export declare type EventAPI = { | ||
Event: typeof Event; | ||
EventTarget: typeof EventTarget; | ||
}; | ||
export declare const resolveGlobalConfig: (api?: EventAPI) => EventAPI; |
Sorry, the diff of this file is not supported yet
3064
15