Skip to content

Commit

Permalink
refactor(qwikloader): more import types
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed May 13, 2024
1 parent 384fc80 commit fc3f6d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
14 changes: 14 additions & 0 deletions packages/qwik/src/core/container/container.ts
Expand Up @@ -191,3 +191,17 @@ export interface QContainerElement extends Element {
qFuncs?: Function[];
_qwikjson_?: any;
}

export interface QElement extends Element {
_qc_?: QContext | undefined;
}

export interface QDocument extends Document {
__q_context__?: [Element, Event, URL] | 0;
}

export interface QWindow extends Window {
qwikevents: {
push: (...e: string[]) => void;
};
}
24 changes: 5 additions & 19 deletions packages/qwik/src/qwikloader.ts
@@ -1,6 +1,5 @@
import type { QwikSymbolEvent, QwikVisibleEvent } from './core/render/jsx/types/jsx-qwik-events';
import type { QContainerElement } from './core/container/container';
import type { QContext } from './core/state/context';
import type { QContainerElement, QDocument, QElement, QWindow } from './core/container/container';

/**
* Set up event listening for browser.
Expand All @@ -11,17 +10,9 @@ import type { QContext } from './core/state/context';
* @param doc - Document to use for setting up global listeners, and to determine all the browser
* supported events.
*/
export const qwikLoader = (
doc: Document & { __q_context__?: [Element, Event, URL] | 0 },
hasInitialized?: number
) => {
export const qwikLoader = (doc: QDocument, hasInitialized?: number) => {
const Q_CONTEXT = '__q_context__';
type qWindow = Window & {
qwikevents: {
push: (...e: string[]) => void;
};
};
const win = window as unknown as qWindow;
const win = window as unknown as QWindow;
const events = new Set();

// Some shortenings for minification
Expand Down Expand Up @@ -65,12 +56,7 @@ export const qwikLoader = (
detail,
}) as T;

const dispatch = async (
element: Element & { _qc_?: QContext | undefined },
onPrefix: string,
ev: Event,
eventName = ev.type
) => {
const dispatch = async (element: QElement, onPrefix: string, ev: Event, eventName = ev.type) => {
const attrName = 'on' + onPrefix + ':' + eventName;
if (element.hasAttribute('preventdefault:' + eventName)) {
ev.preventDefault();
Expand Down Expand Up @@ -202,7 +188,7 @@ export const qwikLoader = (
};

const addEventListener = (
el: Document | Window,
el: QDocument | QWindow,
eventName: string,
handler: (ev: Event) => void,
capture = false
Expand Down

0 comments on commit fc3f6d8

Please sign in to comment.