Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 23, 2024
1 parent a14e08b commit ea46d47
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/qwik/src/core/qrl/qrl-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,24 @@ export const createQRL = <TYPE>(
return fn;
}
return function (this: unknown, ...args: QrlArgs<TYPE>) {
let context = tryGetInvokeContext();
if (context) {
const prevQrl = context.$qrl$;
context.$qrl$ = qrl;
const prevEvent = context.$event$;
if (context.$event$ === undefined) {
context.$event$ = this as Event;
}
// const result = invoke.call(this, context, f, ...(args as Parameters<typeof f>));
try {
return fn.apply(this, args);
} finally {
context.$qrl$ = prevQrl;
context.$event$ = prevEvent;
}
const currentCtx = tryGetInvokeContext();
const prevQrl = currentCtx?.$qrl$;
const prevEvent = currentCtx?.$event$;

const baseContext = createOrReuseInvocationContext(currentCtx);
const context: InvokeContext = {
...baseContext,
$qrl$: qrl as QRLInternal,
};
if (context.$event$ === undefined) {
context.$event$ = this as Event;
}
try {
return fn.apply(this, args);
} finally {
context.$qrl$ = prevQrl;
context.$event$ = prevEvent;
}
context = newInvokeContext();
context.$qrl$ = qrl;
context.$event$ = this as Event;
return invoke.call(this, context, fn as any, ...args);
} as TYPE;
};

Expand Down Expand Up @@ -176,7 +174,15 @@ export const createQRL = <TYPE>(
if (beforeFn && beforeFn() === false) {
return;
}
const context = createOrReuseInvocationContext(currentCtx);

const baseContext = createOrReuseInvocationContext(currentCtx);
const context: InvokeContext = {
...baseContext,
$qrl$: qrl as QRLInternal,
};
if (context.$event$ === undefined) {
context.$event$ = this as Event;
}
return invoke.call(this, context, f, ...(args as Parameters<typeof f>));
});
}
Expand Down

0 comments on commit ea46d47

Please sign in to comment.