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: fix and update broken code examples #3874

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/docs/src/routes/docs/(qwikcity)/server$/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { server$ } from '@builder.io/qwik-city';

// By wrapping a function with `server$()` we mark it to always
// execute on the server. This is a form of RPC mechanism.
const serverGreeter = server$((firstName, lastName) => {
const serverGreeter = server$((firstName: string, lastName: string) => {
const greeting = `Hello ${firstName} ${lastName}`;
console.log('Prints in the server', greeting);
return greeting;
Expand All @@ -31,9 +31,9 @@ export default component$(() => {

return (
<section>
<label>First name: <input bind:value={name} /></label>
<label>Last name: <input bind:value={name} /></label>
<label>First name: <input bind:value={firstName} /></label>
<label>Last name: <input bind:value={lastName} /></label>

<button
onClick$={async () => {
const greeting = await serverGreeter(firstName.value, lastName.value);
Expand Down Expand Up @@ -82,10 +82,10 @@ const addUser = server$(async function(id: number, fullName: string, address: Ad
import { component$, useSignal } from '@builder.io/qwik';
import { server$ } from '@builder.io/qwik-city';

const stream = server$(async function() {
const stream = server$(async function* () {
for (let i = 0; i < 10; i++) {
yield i;
await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 1000));
}
});

Expand All @@ -95,7 +95,8 @@ export default component$(() => {
<div>
<button
onClick$={async () => {
for await (const i of stream()) {
const response = await stream();
for await (const i of response) {
message.value += ` ${i}`;
}
}}
Expand Down