Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose unwrapStore as a low level API #6960

Merged
merged 10 commits into from
Oct 29, 2024
5 changes: 5 additions & 0 deletions .changeset/short-cycles-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
shairez marked this conversation as resolved.
Show resolved Hide resolved
---

Expose unwrapProxy as a low level API
14 changes: 14 additions & 0 deletions packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3010,6 +3010,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-core.ts",
"mdFile": "qwik.untrack.md"
},
{
"name": "unwrapProxy",
"id": "unwrapproxy",
"hierarchy": [
{
"name": "unwrapProxy",
"id": "unwrapproxy"
}
],
"kind": "Function",
"content": "Get the target value of the Proxy. Useful if you want to clone a store (structureClone, IndexedDB,...)\n\n\n```typescript\nunwrapProxy: <T>(proxy: T) => 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\nproxy\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nT",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/state/common.ts",
"mdFile": "qwik.unwrapproxy.md"
},
{
"name": "useComputed$",
"id": "usecomputed_",
Expand Down
39 changes: 39 additions & 0 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10119,6 +10119,45 @@ T

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-core.ts)

## unwrapProxy

Get the target value of the Proxy. Useful if you want to clone a store (structureClone, IndexedDB,...)

```typescript
unwrapProxy: <T>(proxy: T) => T;
```

<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead>
<tbody><tr><td>

proxy

</td><td>

T

</td><td>

</td></tr>
</tbody></table>
**Returns:**

T

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/state/common.ts)

## useComputed$

Hook that returns a read-only signal that updates when signals used in the `ComputedFn` change.
Expand Down
3 changes: 3 additions & 0 deletions packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,9 @@ export interface TrackHTMLAttributes<T extends Element> extends Attrs<'track', T
// @public
export const untrack: <T>(fn: () => T) => T;

// @public
export const unwrapProxy: <T>(proxy: T) => T;

// @public
export const useComputed$: <T>(qrl: ComputedFn<T>) => Signal<Awaited<T>>;

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 @@ -124,7 +124,7 @@ export type { ErrorBoundaryStore } from './render/error-handling';
export type { ValueOrPromise } from './util/types';
export type { Signal, ReadonlySignal } from './state/signal';
export type { NoSerialize } from './state/common';
export { noSerialize } from './state/common';
export { noSerialize, unwrapProxy } from './state/common';
export { isSignal } from './state/signal';
export { version } from './version';

Expand Down
7 changes: 6 additions & 1 deletion packages/qwik/src/core/state/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ export const isConnected = (sub: SubscriberEffect | SubscriberHost): boolean =>
}
};

/** @public */
/**
* Get the target value of the Proxy. Useful if you want to clone a store (structureClone,
* IndexedDB,...)
*
* @public
*/
export const unwrapProxy = <T>(proxy: T): T => {
return isObject(proxy) ? (getProxyTarget<any>(proxy) ?? proxy) : proxy;
};
Expand Down