Skip to content

Commit

Permalink
docs: update serialization boundaries code snippet (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntadpear committed Nov 13, 2022
1 parent 25988bd commit 0a6a7e1
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 0a6a7e1

Please sign in to comment.