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

docs: update serialization boundaries code snippet #2122

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/docs/src/routes/docs/cheat/serialization/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ contributors:
- wuweiweiwu
- manucorporat
- adamdbradley
- voluntadpear
---

# `$` Boundaries
Expand All @@ -22,14 +23,24 @@ import { component$ } from '@builder.io/qwik';

export const topLevel = Promise.resolve('nonserializable data');

export class MyCustomClass {
val: string;

constructor(val: string) {
this.val = val;
}
}

export const Greeter = component$(() => {
// BEGIN component serialization boundary

// Referring to top level symbols that are exported is always allowed.
console.log(topLevel); // OK

const captureSerializable = 'serializable data';
const captureNonSerializable = Promise.resolve('nonserializable data');
const capturePromise = Promise.resolve('Qwik serializes promises');
// Instances of custom classes are not serializable.
const captureNonSerializable = new MyCustomClass('non serializable');

return (
<button
Expand All @@ -44,6 +55,7 @@ export const Greeter = component$(() => {
// - declared as `const`
// - is serializable (runtime error)
console.log(captureSerializable); // OK
console.log(capturePromise); // OK

// Referring to captureNonSerializable will pass static analysis but
// will fail at runtime because Qwik does not know how to serialize it.
Expand Down