From 771643d1c49bc26af58428fa3b3396da5e41c93a Mon Sep 17 00:00:00 2001
From: Luca Casonato
Date: Sat, 8 May 2021 18:47:54 +0200
Subject: [PATCH] update example
---
example/deps.ts | 2 +-
example/pages/index.tsx | 11 ++++++++---
example/server.ts | 2 +-
runtime.ts | 1 +
src/cli/init.ts | 11 ++++++++---
src/runtime/utils.ts | 1 +
6 files changed, 20 insertions(+), 8 deletions(-)
create mode 100644 src/runtime/utils.ts
diff --git a/example/deps.ts b/example/deps.ts
index a8d76d71..94d40074 100644
--- a/example/deps.ts
+++ b/example/deps.ts
@@ -1 +1 @@
-export * from "../runtime.ts";
+export * from "file:///mnt/starship/Projects/github.com/lucacasonato/fresh/runtime.ts";
diff --git a/example/pages/index.tsx b/example/pages/index.tsx
index c765d64c..72d5cd86 100644
--- a/example/pages/index.tsx
+++ b/example/pages/index.tsx
@@ -1,4 +1,4 @@
-import { h, useState } from "../deps.ts";
+import { h, IS_BROWSER, useState } from "../deps.ts";
export default function Home() {
return (
@@ -8,6 +8,7 @@ export default function Home() {
file, and refresh.
+ {IS_BROWSER ? "Viewing JIT render." : "Viewing browser render."}
);
}
@@ -16,7 +17,11 @@ function Counter() {
const [count, setCount] = useState(0);
return
{count}
-
-
+
+
;
}
diff --git a/example/server.ts b/example/server.ts
index 2b41ef2d..0c0b8ffd 100644
--- a/example/server.ts
+++ b/example/server.ts
@@ -2,7 +2,7 @@
// This file SHOULD be checked into source version control.
// To update this file, run `fresh routes`.
-import { setup } from "../server.ts";
+import { setup } from "file:///mnt/starship/Projects/github.com/lucacasonato/fresh/server.ts";
import * as $0 from "./pages/[name].tsx";
import * as $1 from "./pages/index.tsx";
diff --git a/runtime.ts b/runtime.ts
index bd1eaee7..f3ad234a 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -1,2 +1,3 @@
export * from "./src/runtime/deps.ts";
export * from "./src/runtime/types.ts";
+export * from "./src/runtime/utils.ts";
diff --git a/src/cli/init.ts b/src/cli/init.ts
index 5625da24..03f1b0ab 100644
--- a/src/cli/init.ts
+++ b/src/cli/init.ts
@@ -60,7 +60,7 @@ async function init(directory: string) {
import.meta.url,
)}";\n`;
await Deno.writeTextFile(join(directory, "deps.ts"), DEPS_TS);
- const PAGES_INDEX_TSX = `import { h, useState } from "../deps.ts";
+ const PAGES_INDEX_TSX = `import { h, IS_BROWSER, useState } from "../deps.ts";
export default function Home() {
return (
@@ -70,6 +70,7 @@ export default function Home() {
file, and refresh.
+ {IS_BROWSER ? "Viewing JIT render." : "Viewing browser render."}
);
}
@@ -78,8 +79,12 @@ function Counter() {
const [count, setCount] = useState(0);
return
{count}
-
-
+
+
;
}
`;
diff --git a/src/runtime/utils.ts b/src/runtime/utils.ts
new file mode 100644
index 00000000..426b1a7f
--- /dev/null
+++ b/src/runtime/utils.ts
@@ -0,0 +1 @@
+export const IS_BROWSER = typeof document !== "undefined";