Skip to content

Commit b6875c1

Browse files
committed
Upgrade Mini-Van to 0.6.0
1 parent 2f698f2 commit b6875c1

File tree

10 files changed

+83
-84
lines changed

10 files changed

+83
-84
lines changed

bun-examples/hydration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is a [Bun 1.0](https://bun.sh/blog/bun-v1.0)-based variation of the fullsta
77

88
```json
99
"dependencies": {
10-
"mini-van-plate": "^0.5.7",
10+
"mini-van-plate": "^0.6.0",
1111
"vanjs-core": "^1.5.0"
1212
},
1313
"devDependencies": {

bun-examples/hydration/package-lock.json

Lines changed: 47 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bun-examples/hydration/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"build": "bun build --minify src/client.ts --outdir dist && echo Run the following command to start the server: bun src/server.ts [port]"
99
},
1010
"dependencies": {
11-
"mini-van-plate": "^0.5.7",
11+
"mini-van-plate": "^0.6.0",
1212
"vanjs-core": "^1.5.0"
1313
},
1414
"devDependencies": {
15-
"bun": "^1.0.0",
16-
"bun-types": "^1.0.1"
15+
"@types/bun": "^1.1.6",
16+
"bun": "^1.0.0"
1717
}
1818
}

bun-examples/hydration/src/client.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import van from "vanjs-core"
2+
import { registerEnv } from "mini-van-plate/shared"
23
import Hello from "./components/hello.js"
34
import Counter from "./components/counter.js"
45

6+
registerEnv({van})
7+
58
const {button, p} = van.tags
69

7-
van.add(document.getElementById("hello-container")!, Hello({van}))
10+
van.add(document.getElementById("hello-container")!, Hello())
811

912
const hydrate = () => {
1013
van.hydrate(document.getElementById("basic-counter")!, dom => Counter({
11-
van,
1214
id: dom.id,
1315
init: Number(dom.getAttribute("data-counter")),
1416
}))
@@ -17,7 +19,6 @@ const hydrate = () => {
1719
const buttonStyle = van.state(styleSelectDom.value)
1820
styleSelectDom.oninput = e => buttonStyle.val = (<HTMLSelectElement>e.target).value
1921
van.hydrate(document.getElementById("styled-counter")!, dom => Counter({
20-
van,
2122
id: dom.id,
2223
init: Number(dom.getAttribute("data-counter")),
2324
buttonStyle,

bun-examples/hydration/src/components/counter.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
import { VanObj, State } from "mini-van-plate/shared"
1+
import { env, State } from "mini-van-plate/shared"
22

33
interface Props {
4-
van: VanObj
5-
id?: string
6-
init?: number
7-
buttonStyle?: string | State<string>
4+
readonly id?: string
5+
readonly init?: number
6+
readonly buttonStyle?: string | State<string>
87
}
98

10-
export default ({
11-
van, id, init = 0, buttonStyle = "👍👎",
12-
}: Props) => {
13-
const {button, div} = van.tags
9+
export default ({id, init = 0, buttonStyle = "👍👎"}: Props) => {
10+
const {button, div} = env.van.tags
1411

15-
const stateProto = Object.getPrototypeOf(van.state())
12+
const stateProto = Object.getPrototypeOf(env.van.state())
1613

1714
const val = <T>(v: T | State<T>) =>
1815
Object.getPrototypeOf(v ?? 0) === stateProto ? (<State<T>>v).val : <T>v
1916

2017
const [up, down] = [...val(buttonStyle)]
21-
const counter = van.state(init)
18+
const counter = env.van.state(init)
2219
return div({...(id ? {id} : {}), "data-counter": counter},
2320
"❤️ ", counter, " ",
2421
button({onclick: () => ++counter.val}, up),

bun-examples/hydration/src/components/hello.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { VanObj } from "mini-van-plate/shared"
1+
import { env } from "mini-van-plate/shared"
22

3-
interface Props {
4-
van: VanObj
5-
}
6-
7-
export default ({van} : Props) => {
8-
const {a, div, li, p, ul} = van.tags
3+
export default () => {
4+
const {a, div, li, p, ul} = env.van.tags
95

106
const fromServer = typeof window === "undefined"
117
return div(

bun-examples/hydration/src/components/optimized-counter.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
import { VanObj, State } from "mini-van-plate/shared"
1+
import { env, State } from "mini-van-plate/shared"
22

33
interface Props {
4-
van: VanObj
5-
id?: string
6-
init?: number
7-
buttonStyle?: string | State<string>
4+
readonly id?: string
5+
readonly init?: number
6+
readonly buttonStyle?: string | State<string>
87
}
98

10-
export default ({
11-
van, id, init = 0, buttonStyle = "👍👎",
12-
}: Props) => {
13-
const {button, div} = van.tags
9+
export default ({id, init = 0, buttonStyle = "👍👎"}: Props) => {
10+
const {button, div} = env.van.tags
1411

15-
const stateProto = Object.getPrototypeOf(van.state())
12+
const stateProto = Object.getPrototypeOf(env.van.state())
1613

1714
const val = <T>(v: T | State<T>) =>
1815
Object.getPrototypeOf(v ?? 0) === stateProto ? (<State<T>>v).val : <T>v
1916

20-
const counter = van.state(init)
17+
const counter = env.van.state(init)
2118
return div({...(id ? {id} : {}), "data-counter": counter},
2219
"❤️ ", counter, " ",
2320
button({onclick: () => ++counter.val}, () => [...val(buttonStyle)][0]),

bun-examples/hydration/src/server.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import van from "mini-van-plate/van-plate"
2+
import { registerEnv } from "mini-van-plate/shared"
23
import Hello from "./components/hello.js"
34
import Counter from "./components/counter.js"
45

56
const {body, div, h1, h2, head, link, meta, option, p, script, select, title} = van.tags
67

8+
registerEnv({van})
9+
710
const server = Bun.serve({
811
port: Bun.argv[2] ?? 8080,
912
fetch(req) {
@@ -19,13 +22,11 @@ const server = Bun.serve({
1922
body(
2023
script({type: "text/javascript", src: `dist/client.js`, defer: true}),
2124
h1("Hello Components"),
22-
div({id: "hello-container"},
23-
Hello({van}),
24-
),
25+
div({id: "hello-container"}, Hello()),
2526
h1("Counter Components"),
2627
div({id: "counter-container"},
2728
h2("Basic Counter"),
28-
Counter({van, id: "basic-counter", init: counterInit}),
29+
Counter({id: "basic-counter", init: counterInit}),
2930
h2("Styled Counter"),
3031
p("Select the button style: ",
3132
select({id: "button-style", value: "👆👇"},
@@ -36,7 +37,7 @@ const server = Bun.serve({
3637
option("📈📉"),
3738
),
3839
),
39-
Counter({van, id: "styled-counter", init: counterInit, buttonStyle: "👆👇"}),
40+
Counter({id: "styled-counter", init: counterInit, buttonStyle: "👆👇"}),
4041
),
4142
)
4243
), {headers: {"Content-Type": "text/html; charset=UTF-8"}})

bun-examples/hydration/src/tsconfig.json

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"lib": ["ESNext"],
3+
"lib": ["ESNext", "DOM"],
44
"module": "ESNext",
55
"target": "ESNext",
66
"moduleResolution": "bundler",
@@ -14,13 +14,7 @@
1414
"jsx": "preserve",
1515
"allowSyntheticDefaultImports": true,
1616
"forceConsistentCasingInFileNames": true,
17-
"allowJs": true,
18-
"types": [
19-
"bun-types" // add Bun global
20-
]
17+
"allowJs": true
2118
},
22-
"include": [
23-
"src/components/*.ts",
24-
"src/server.ts"
25-
]
19+
"include": ["src"]
2620
}

0 commit comments

Comments
 (0)