Skip to content

Commit 76a499d

Browse files
committed
Refactor: move all sample code to a dedicated dir to clean up the root dir
1 parent 09faad7 commit 76a499d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+13
-12
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

sitegen/common.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { join } from "https://deno.land/[email protected]/path/mod.ts"
12
import van, { ChildDom as TypedChildDom } from "./mini-van.js"
23
import { HTMLDocument, Element, Text } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts"
34

@@ -91,7 +92,7 @@ export default (doc: HTMLDocument) => {
9192

9293
interface FileOptions {trim?: boolean}
9394
const File = (lang: string, file: string, {trim = false}: FileOptions, codeOptions: CodeOptions) => {
94-
let text = Deno.readTextFileSync(file)
95+
let text = Deno.readTextFileSync(join("sample-code", file))
9596
if (trim) {
9697
const lines = text.split("\n")
9798
const tagImportingLine = lines.findIndex(l => l.includes("= van.tags"))

sitegen/demo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ const TodoList = () => {
242242
p("You can also go fully reactive for the ", Symbol("TODO App"), ". That is, the entire state of the app is captured by a global ", Symbol("appState"), ". With the full reactivity it's easier to persist the ", Symbol("appState"), " into ", SymLink("localStorage", "https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage"), " so that the state is kept across page reloads."),
243243
p("Note that even if the app is fully reactive, we don't need to re-render the whole DOM tree for state updates, thanks to the optimization with ", Link("stateful binding", "/tutorial#stateful-binding"), "."),
244244
p(i("The code was implemented in TypeScript.")),
245-
TsFile("code/todo-app/src/main.ts", {trim: true}),
245+
TsFile("../code/todo-app/src/main.ts", {trim: true}),
246246
p(Demo()),
247247
p({id: "demo-todo-fully-reactive"}),
248248
p(Link("Try on CodeSandbox", "https://codesandbox.io/p/sandbox/github/vanjs-org/vanjs-org.github.io/tree/master/code/todo-app?file=/src/main.ts:1,1")),
@@ -282,7 +282,7 @@ const TodoList = () => {
282282
}),
283283
H2({id: "code-browser"}, "SPA w/ Client-Side Routing: Code Browser"),
284284
p("With ", VanJS(), ", you can built a single-page application with client-side routing support, thanks to ", VanJS(), "'s powerful builtin state management and state derivation:"),
285-
TsFile("code/code-browser/src/main.js", {trim: true}),
285+
TsFile("../code/code-browser/src/main.js", {trim: true}),
286286
p(Link("Try on CodeSandbox", "https://codesandbox.io/p/sandbox/github/vanjs-org/vanjs-org.github.io/tree/master/code/code-browser?file=/src/main.js:1,1")),
287287
H2("Stargazers"),
288288
p("The following code can show the number of stars for a Github repo, and a list of most recent stargazers:"),

sitegen/minivan.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ van.add(document.body, Hello())
6969
Shell("npm install mini-van-plate"),
7070
H3({id: "npm-van-plate"}, Symbol("van-plate"), " mode"),
7171
p("In ", Symbol("van-plate"), " mode, HTML content is generated purely through text templating. It can be easily integrated with your HTTP server to render dynamic web content. See the sample code below:"),
72-
JsFile("sitegen/node-examples/van-plate-server/van-plate-server.mjs"),
72+
JsFile("../sitegen/node-examples/van-plate-server/van-plate-server.mjs"),
7373
p("Preview via ", Link("CodeSandbox", "https://codesandbox.io/p/sandbox/github/vanjs-org/vanjs-org.github.io/tree/master/sitegen/node-examples/van-plate-server?file=%2Fvan-plate-server.mjs%3A1%2C1"), "."),
7474
p("As illustrated in the example, ", Symbol("render"), " method can be called on the object returned from the ", SymLink("tag function", "/tutorial#api-tags"), " to generate a ", Symbol("string"), " that can be used for serving."),
7575
p(Symbol("van.html"), " is a helper function defined in ", Symbol("van-plate.js"), " that is equivalent to:",
@@ -81,7 +81,7 @@ van.add(document.body, Hello())
8181
p("First, install ", Symbol("jsdom"), ":"),
8282
Shell("npm install jsdom"),
8383
p("Sample code:"),
84-
JsFile("sitegen/node-examples/mini-van-server/mini-van-server.mjs"),
84+
JsFile("../sitegen/node-examples/mini-van-server/mini-van-server.mjs"),
8585
p("Preview via ", Link("CodeSandbox", "https://codesandbox.io/p/sandbox/github/vanjs-org/vanjs-org.github.io/tree/master/sitegen/node-examples/mini-van-server?file=%2Fmini-van-server.mjs%3A1%2C1"), "."),
8686
p("Similar to ", Symbol("van-plate"), " mode, we have a helper function ", Symbol("html"), " defined in ", Symbol("mini-van.js"), " which is equivalent to:"),
8787
Js(`(...args) => "<!DOCTYPE html>" + tags.html(...args).outerHTML`),
@@ -90,12 +90,12 @@ van.add(document.body, Hello())
9090
H3({id: "deno-van-plate"}, Symbol("van-plate"), " mode"),
9191
p("Sample code:"),
9292
div({style: "font-size: 0.9em;"}, i("Requires Deno ", Symbol("1.35"), " or later.")),
93-
TsFile("sitegen/deno-examples/van-plate-server/van-plate-server.ts"),
93+
TsFile("../sitegen/deno-examples/van-plate-server/van-plate-server.ts"),
9494
p("Preview via ", Link("CodeSandbox", "https://codesandbox.io/p/sandbox/github/vanjs-org/vanjs-org.github.io/tree/master/sitegen/deno-examples/van-plate-server?file=%2Fvan-plate-server.ts%3A1%2C1"), "."),
9595
H3({id: "deno-mini-van"}, Symbol("mini-van"), " mode"),
9696
p("Likewise, ", MiniVan(), " mode needs a 3rd-party DOM library to provide the ", Symbol("Document"), " object. We will show an example with the integration of ", SymLink("deno-dom", "https://deno.com/[email protected]/advanced/jsx_dom/deno_dom"), "."),
9797
div({style: "font-size: 0.9em;"}, i("Requires Deno ", Symbol("1.35"), " or later.")),
98-
TsFile("sitegen/deno-examples/mini-van-server/mini-van-server.ts"),
98+
TsFile("../sitegen/deno-examples/mini-van-server/mini-van-server.ts"),
9999
p("Preview via ", Link("CodeSandbox", "https://codesandbox.io/p/sandbox/github/vanjs-org/vanjs-org.github.io/tree/master/sitegen/deno-examples/mini-van-server?file=%2Fmini-van-server.ts%3A1%2C1"), "."),
100100
H2("Client-Side: Getting Started"),
101101
p("To get started on the client side, add the line below to your script:"),

sitegen/ssr.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default (doc: HTMLDocument) => {
6868
p("Now, let's build some shared UI components that can run on both server-side and client-side."),
6969
H3("Static Component"),
7070
p("First, let's take a look at a static (non-reactive) component - ", Symbol("Hello"), ":"),
71-
TsFile("hydration-example/src/components/hello.ts"),
71+
TsFile("../hydration-example/src/components/hello.ts"),
7272
p("Compared to the ", SymLink("Hello", "/demo#hello-world"), " component in the \"VanJS by Example\" page, there are following notable differences:"),
7373
ul(
7474
li("The shared ", Symbol("Hello"), " component takes a ", Symbol("van"), " object as its input property. This is crucial to make ", Symbol("Hello"), " component cross-platform. Callers are responsible for providing the ", Symbol("van"), " object based on what's available in their specific environment so that the component can be agnostic to the execution environment. On the server-side, the ", Symbol("van"), " object from ", MiniVan(), " will be used (we can choose the ", Symbol("van"), " object from ", Symbol("van-plate"), " mode or from ", Symbol("mini-van"), " mode), whereas on the client-side, the ", Symbol("van"), " object from ", VanJS(), " will be used."),
@@ -78,7 +78,7 @@ export default (doc: HTMLDocument) => {
7878
p(b("Limitations: "), i("The typechecking for tag functions and ", Symbol("van.add"), " is quite limited. This is because it's hard to unify the type system across the common types between server-side and client-side.")),
7979
H3("Reactive Component"),
8080
p("Next, let's take a look at a reactive component - ", Symbol("Counter"), ":"),
81-
TsFile("hydration-example/src/components/counter.ts"),
81+
TsFile("../hydration-example/src/components/counter.ts"),
8282
p("Notable differences from the ", SymLink("Counter", "/demo#counter"), " component in the \"VanJS by Example\" page:"),
8383
ul(
8484
li("Similar to the ", Symbol("Hello"), " component, it takes a ", Symbol("van"), " object as its input property to make the component environment-agnostic."),
@@ -90,7 +90,7 @@ export default (doc: HTMLDocument) => {
9090
),
9191
H2("Server-Side Script: HTML Template"),
9292
p("Now, let's build the server-side script that enables SSR:"),
93-
TsFile("hydration-example/src/server.ts"),
93+
TsFile("../hydration-example/src/server.ts"),
9494
p("The script implements a basic HTTP server with the built-in ", Symbol("node:http"), " module (no web framework needed). You will probably first notice this line:"),
9595
Ts('if (req.url?.endsWith(".js")) return serveFile(req, res, finalhandler(req, res))'),
9696
p("This is to tell the HTTP server to serve the file statically if any ", Symbol(".js"), " file is requested."),
@@ -131,7 +131,7 @@ styleSelectDom.oninput = e => buttonStyle.val = (<HTMLSelectElement>e.target).va
131131
`),
132132
p("Since ", Symbol("buttonStyle"), " is passed into the ", Symbol("Counter"), " component where its ", Symbol("val"), " property is referenced, the hydrated ", Symbol("Counter"), " component will be reactive to the change of ", Symbol("buttonStyle"), " state."),
133133
p("Note that, this is an illustrative example to show how to make the entire hydrated component reactive to external states. In practice, the implementation of ", Symbol("Counter"), " component can be optimized to only make the ", InlineHtml("<button>"), "s' child text nodes of the ", Symbol("Counter"), " component reactive to ", Symbol("buttonStyle"), " state. This can be achieved by binding more localized DOM nodes (i.e.: the child text nodes of ", InlineHtml("<button>"), "s) to the ", Symbol("buttonStyle"), " state. You can check out the implementation below for an optimized ", Symbol("Counter"), " component:"),
134-
TsFile("hydration-example/src/components/optimized-counter.ts"),
134+
TsFile("../hydration-example/src/components/optimized-counter.ts"),
135135
H3({id: "api-hydrate"}, "API reference: ", Symbol("van.hydrate")),
136136
ApiTable({
137137
signature: "van.hydrate(dom, f) => undefined",

sitegen/x.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ async function* serverStateUpdates() {
424424
}
425425
`,
426426
"data-suffix": "van.add(document.body, ChatApp())",
427-
"data-css-file": "chat-app.code.css",
427+
"data-css-file": "sample-code/chat-app.code.css",
428428
}),
429429
p("Note that in the jsfiddle preview link above, we're simulating the server-side state updates. In real-world applications, state updates can be sent from server via ", Link(Symbol("WebSocket"), " messages", "https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event"), ", or ", Link("HTTP polling", "https://medium.com/cache-me-out/http-polling-and-long-polling-bd3f662a14f"), "."),
430430
H3({id: "serialization-and-compact"}, "Serialization app state and ", Symbol("vanX.compact")),

0 commit comments

Comments
 (0)