Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 10, 2024
1 parent d6542fa commit ed77433
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 64 deletions.
26 changes: 20 additions & 6 deletions packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/component/component.public.ts",
"mdFile": "qwik.componentqrl.md"
},
{
"name": "ComputedFn",
"id": "computedfn",
"hierarchy": [
{
"name": "ComputedFn",
"id": "computedfn"
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type ComputedFn<T> = () => T;\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"mdFile": "qwik.computedfn.md"
},
{
"name": "ComputedSignal2",
"id": "computedsignal2",
Expand Down Expand Up @@ -572,7 +586,7 @@
}
],
"kind": "Function",
"content": "```typescript\ncreateComputed2$: <T>(first: () => T) => ComputedSignal2<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nfirst\n\n\n</td><td>\n\n() =&gt; T\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[ComputedSignal2](#computedsignal2)<!-- -->&lt;T&gt;",
"content": "```typescript\ncreateComputed2$: <T>(qrl: () => T) => ComputedSignal2<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\n() =&gt; T\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[ComputedSignal2](#computedsignal2)<!-- -->&lt;T&gt;",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/v2/signal/v2-signal.public.ts",
"mdFile": "qwik.createcomputed2_.md"
},
Expand Down Expand Up @@ -819,7 +833,7 @@
}
],
"kind": "Function",
"content": "```typescript\nevent$: <T>(first: T) => import(\"./qrl.public\").QRL<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nfirst\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nimport(\"./qrl.public\").[QRL](#qrl)<!-- -->&lt;T&gt;",
"content": "```typescript\nevent$: <T>(qrl: T) => import(\"./qrl.public\").QRL<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nimport(\"./qrl.public\").[QRL](#qrl)<!-- -->&lt;T&gt;",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/qrl/qrl.public.dollar.ts",
"mdFile": "qwik.event_.md"
},
Expand Down Expand Up @@ -3233,7 +3247,7 @@
}
],
"kind": "Variable",
"content": "Hook that creates a signal that is retained for the lifetime of the component.\n\n\n```typescript\nuseSignal: UseSignal\n```",
"content": "```typescript\nuseSignal: UseSignal\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-signal.ts",
"mdFile": "qwik.usesignal.md"
},
Expand All @@ -3247,7 +3261,7 @@
}
],
"kind": "Interface",
"content": "Hook that creates a signal that is retained for the lifetime of the component.\n\n\n```typescript\nuseSignal: UseSignal\n```",
"content": "```typescript\nuseSignal: UseSignal\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-signal.ts",
"mdFile": "qwik.usesignal.md"
},
Expand Down Expand Up @@ -3359,7 +3373,7 @@
}
],
"kind": "Function",
"content": "Reruns the `taskFn` when the observed inputs change.\n\nUse `useTask` to observe changes on a set of inputs, and then re-execute the `taskFn` when those inputs change.\n\nThe `taskFn` only executes if the observed inputs change. To observe the inputs, use the `obs` function to wrap property reads. This creates subscriptions that will trigger the `taskFn` to rerun.\n\n\n```typescript\nuseTask$: (first: import(\"./use-task\").TaskFn, opts?: import(\"./use-task\").UseTaskOptions | undefined) => void\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nfirst\n\n\n</td><td>\n\nimport(\"./use-task\").[TaskFn](#taskfn)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\nimport(\"./use-task\").[UseTaskOptions](#usetaskoptions) \\| undefined\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nvoid",
"content": "Reruns the `taskFn` when the observed inputs change.\n\nUse `useTask` to observe changes on a set of inputs, and then re-execute the `taskFn` when those inputs change.\n\nThe `taskFn` only executes if the observed inputs change. To observe the inputs, use the `obs` function to wrap property reads. This creates subscriptions that will trigger the `taskFn` to rerun.\n\n\n```typescript\nuseTask$: (qrl: import(\"./use-task\").TaskFn, opts?: import(\"./use-task\").UseTaskOptions | undefined) => void\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nimport(\"./use-task\").[TaskFn](#taskfn)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\nimport(\"./use-task\").[UseTaskOptions](#usetaskoptions) \\| undefined\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nvoid",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task-dollar.ts",
"mdFile": "qwik.usetask_.md"
},
Expand Down Expand Up @@ -3401,7 +3415,7 @@
}
],
"kind": "Function",
"content": "```tsx\nconst Timer = component$(() => {\n const store = useStore({\n count: 0,\n });\n\n useVisibleTask$(() => {\n // Only runs in the client\n const timer = setInterval(() => {\n store.count++;\n }, 500);\n return () => {\n clearInterval(timer);\n };\n });\n\n return <div>{store.count}</div>;\n});\n```\n\n\n```typescript\nuseVisibleTask$: (first: import(\"./use-task\").TaskFn, opts?: import(\"./use-task\").OnVisibleTaskOptions | undefined) => void\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nfirst\n\n\n</td><td>\n\nimport(\"./use-task\").[TaskFn](#taskfn)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\nimport(\"./use-task\").[OnVisibleTaskOptions](#onvisibletaskoptions) \\| undefined\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nvoid",
"content": "```tsx\nconst Timer = component$(() => {\n const store = useStore({\n count: 0,\n });\n\n useVisibleTask$(() => {\n // Only runs in the client\n const timer = setInterval(() => {\n store.count++;\n }, 500);\n return () => {\n clearInterval(timer);\n };\n });\n\n return <div>{store.count}</div>;\n});\n```\n\n\n```typescript\nuseVisibleTask$: (qrl: import(\"./use-task\").TaskFn, opts?: import(\"./use-task\").OnVisibleTaskOptions | undefined) => void\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nimport(\"./use-task\").[TaskFn](#taskfn)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\nimport(\"./use-task\").[OnVisibleTaskOptions](#onvisibletaskoptions) \\| undefined\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nvoid",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task-dollar.ts",
"mdFile": "qwik.usevisibletask_.md"
},
Expand Down
22 changes: 13 additions & 9 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,14 @@ componentQrl
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/component/component.public.ts)
## ComputedFn
```typescript
export type ComputedFn<T> = () => T;
```
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
## ComputedSignal2
```typescript
Expand Down Expand Up @@ -1721,7 +1729,7 @@ Description
## createComputed2$
```typescript
createComputed2$: <T>(first: () => T) => ComputedSignal2<T>;
createComputed2$: <T>(qrl: () => T) => ComputedSignal2<T>;
```
<table><thead><tr><th>
Expand All @@ -1739,7 +1747,7 @@ Description
</th></tr></thead>
<tbody><tr><td>
first
qrl
</td><td>
Expand Down Expand Up @@ -2176,7 +2184,7 @@ any \| undefined
## event$
```typescript
event$: <T>(first: T) => import("./qrl.public").QRL<T>;
event$: <T>(qrl: T) => import("./qrl.public").QRL<T>;
```
<table><thead><tr><th>
Expand Down Expand Up @@ -10847,8 +10855,6 @@ T \| undefined
## useSignal
Hook that creates a signal that is retained for the lifetime of the component.
```typescript
useSignal: UseSignal;
```
Expand All @@ -10857,8 +10863,6 @@ useSignal: UseSignal;
## UseSignal
Hook that creates a signal that is retained for the lifetime of the component.
```typescript
useSignal: UseSignal;
```
Expand Down Expand Up @@ -11283,7 +11287,7 @@ Use `useTask` to observe changes on a set of inputs, and then re-execute the `ta
The `taskFn` only executes if the observed inputs change. To observe the inputs, use the `obs` function to wrap property reads. This creates subscriptions that will trigger the `taskFn` to rerun.
```typescript
useTask$: (first: import("./use-task").TaskFn, opts?: import("./use-task").UseTaskOptions | undefined) => void
useTask$: (qrl: import("./use-task").TaskFn, opts?: import("./use-task").UseTaskOptions | undefined) => void
```
<table><thead><tr><th>
Expand Down Expand Up @@ -11451,7 +11455,7 @@ const Timer = component$(() => {
```
```typescript
useVisibleTask$: (first: import("./use-task").TaskFn, opts?: import("./use-task").OnVisibleTaskOptions | undefined) => void
useVisibleTask$: (qrl: import("./use-task").TaskFn, opts?: import("./use-task").OnVisibleTaskOptions | undefined) => void
```
<table><thead><tr><th>
Expand Down
7 changes: 5 additions & 2 deletions packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export interface ComponentBaseProps {
// @public
export const componentQrl: <PROPS extends Record<any, any>>(componentQrl: QRL<OnRenderFn<PROPS>>) => Component<PROPS>;

// @public (undocumented)
export type ComputedFn<T> = () => T;

// @public (undocumented)
export interface ComputedSignal2<T> extends ReadonlySignal2<T> {
force(): void;
Expand Down Expand Up @@ -203,7 +206,7 @@ export interface CorrectedToggleEvent extends Event {
}

// @public (undocumented)
export const createComputed2$: <T>(first: () => T) => ComputedSignal2<T>;
export const createComputed2$: <T>(qrl: () => T) => ComputedSignal2<T>;

// @public (undocumented)
export const createComputed2Qrl: <T>(qrl: QRL<() => T>) => ComputedSignal2<T>;
Expand Down Expand Up @@ -1941,7 +1944,7 @@ export interface UseSignal {
<T>(value: T | (() => T)): Signal2<T>;
}

// @public
// @public (undocumented)
export const useSignal: UseSignal;

// @public
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/core/container/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
cleanupTask,
isResourceTask,
type ResourceReturnInternal,
type Task,
} from '../use/use-task';
import { isNotNullable, isPromise } from '../util/promises';
import { isArray, isObject, isSerializableObject } from '../util/types';
Expand Down Expand Up @@ -244,7 +245,7 @@ Task Symbol: ${task.$qrl$.$symbol$}
if (isResourceTask(task)) {
collector.$resources$.push(task.$state$!);
}
cleanupTask(task);
cleanupTask(task as Task);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export { useContext, useContextProvider, createContextId } from './use/use-conte
export { useServerData } from './use/use-env-data';
export { useStylesQrl, useStyles$, useStylesScopedQrl, useStylesScoped$ } from './use/use-styles';
export { useOn, useOnDocument, useOnWindow } from './use/use-on';
export { useSignal, useConstant, createSignal } from './use/use-signal';
export { useSignal, useConstant } from './use/use-signal';
export { withLocale, getLocale } from './use/use-locale';

export type { UseStylesScoped } from './use/use-styles';
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/state/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const createContext = (element: Element | VirtualElement): QContext => {
export const cleanupContext = (elCtx: QContext, subsManager: SubscriptionManager) => {
elCtx.$tasks$?.forEach((task) => {
subsManager.$clearSub$(task);
cleanupTask(task);
cleanupTask(task as any);
});
elCtx.$componentQrl$ = null;
elCtx.$seq$ = null;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/use/use-lexical-scope.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useLexicalScope = <VARS extends any[]>(): VARS => {
if (!qrl) {
const el = context.$element$;
assertDefined(el, 'invoke: element must be defined inside useLexicalScope()', context);
const containerElement = getWrappingContainer(el) as HTMLElement;
const containerElement = _getQContainerElement(el) as HTMLElement;
assertDefined(containerElement, `invoke: cant find parent q:container of`, el);
if (containerElement.getAttribute('q:runtime') == '2') {
const container = getDomContainer(containerElement);
Expand Down
18 changes: 18 additions & 0 deletions packages/qwik/src/core/use/use-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,21 @@ export const useSignal: UseSignal = <STATE>(initialState?: STATE): Signal2<STATE
const signal = createSignal2<STATE>(value);
return set(signal);
};

/**
* Stores a value which is retained for the lifetime of the component.
*
* If the value is a function, the function is invoked to calculate the actual value.
*
* @deprecated This is a technology preview
* @public
*/
export const useConstant = <T>(value: (() => T) | T): T => {
const { val, set } = useSequentialScope<T>();
if (val != null) {
return val;
}
// Note: We are not using `invoke` here because we don't want to clear the context
value = isFunction(value) && !isQwikComponent(value) ? value() : value;
return set(value as T);
};
1 change: 0 additions & 1 deletion packages/qwik/src/core/v2/client/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ import {
vnode_getElementNamespaceFlags,
} from './vnode-namespace';
import { escapeHTML } from '../shared/character-escaping';
import { SignalImpl } from '../../state/signal';

//////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
12 changes: 7 additions & 5 deletions packages/qwik/src/core/v2/tests/use-store.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Fragment as Component, Fragment, Fragment as Signal, useTask$ } from '@builder.io/qwik';
import { describe, expect, it, vi } from 'vitest';
import { advanceToNextTimerAndFlush } from '../../../testing/element-fixture';
import { domRender, ssrRenderToDom, trigger } from '@builder.io/qwik/testing';
import {
Fragment as Component,
Fragment,
Fragment as Signal,
useTask$,
component$,
type Signal as SignalType,
untrack,
useSignal,
useStore,
useTask$,
} from '@builder.io/qwik';
import { describe, expect, it, vi } from 'vitest';
import { advanceToNextTimerAndFlush } from '../../../testing/element-fixture';
import { domRender, ssrRenderToDom, trigger } from '@builder.io/qwik/testing';

const debug = false; //true;
Error.stackTraceLimit = 100;
Expand Down
72 changes: 35 additions & 37 deletions starters/apps/e2e/src/components/signals/signals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {
component$,
type Signal,
useSignal,
createSignal,
useConstant,
useStore,
useVisibleTask$,
useTask$,
Expand Down Expand Up @@ -137,7 +135,7 @@ export const SignalsChildren = component$(() => {
<Issue4228 />
<Issue4368 />
<Issue4868 />
<ManySignals />
{/* <ManySignals /> */}
</div>
);
});
Expand Down Expand Up @@ -1243,37 +1241,37 @@ export const Issue4868Card = component$((props: { src: string }) => {
);
});

export const ManySignals = component$(() => {
const signals = useConstant(() => {
const arr: (Signal<number> | string)[] = [];
for (let i = 0; i < 10; i++) {
arr.push(createSignal(0));
arr.push(", ");
}
return arr;
});
// const doubles = useConstant(() =>
// signals.map((s: Signal<number> | string) =>
// typeof s === "string" ? s : createComputed$(() => s.value * 2),
// ),
// );

return (
<>
<button
id="many-signals-button"
onClick$={() => {
for (const s of signals) {
if (typeof s !== "string") {
s.value++;
}
}
}}
>
Increment
</button>
<div id="many-signals-result">{signals}</div>
{/* <div id="many-doubles-result">{doubles}</div> */}
</>
);
});
// export const ManySignals = component$(() => {
// const signals = useConstant(() => {
// const arr: (Signal<number> | string)[] = [];
// for (let i = 0; i < 10; i++) {
// arr.push(createSignal(0));
// arr.push(", ");
// }
// return arr;
// });
// // const doubles = useConstant(() =>
// // signals.map((s: Signal<number> | string) =>
// // typeof s === "string" ? s : createComputed$(() => s.value * 2),
// // ),
// // );

// return (
// <>
// <button
// id="many-signals-button"
// onClick$={() => {
// for (const s of signals) {
// if (typeof s !== "string") {
// s.value++;
// }
// }
// }}
// >
// Increment
// </button>
// <div id="many-signals-result">{signals}</div>
// {/* <div id="many-doubles-result">{doubles}</div> */}
// </>
// );
// });

0 comments on commit ed77433

Please sign in to comment.