Skip to content

Commit b511222

Browse files
committed
Update the example for OptimizedCounter
1 parent 1fe32ec commit b511222

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

test/van.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,11 @@ const runTests = async (van, msgDom, { debug }) => {
10171017
const counter = van.state(init);
10181018
return div(Object.assign(Object.assign({}, (id ? { id } : {})), { "data-counter": counter }), "❤️ ", counter, " ", button({ onclick: () => ++counter.val }, up), button({ onclick: () => --counter.val }, down));
10191019
};
1020-
const OptimizedCounter = ({ van: { state, derive, val, tags: { button, div } }, id, init = 0, buttonStyle = "👍👎", }) => div((dom) => {
1021-
if (dom)
1022-
return dom;
1023-
const counter = state(init);
1024-
const up = state(undefined), down = state(undefined);
1025-
derive(() => [up.val, down.val] = [...val(buttonStyle)]);
1026-
return div(Object.assign(Object.assign({}, (id ? { id } : {})), { "data-counter": counter }), "❤️ ", counter, " ", button({ onclick: () => ++counter.val }, up), button({ onclick: () => --counter.val }, down));
1027-
}).firstChild;
1020+
const OptimizedCounter = ({ van, id, init = 0, buttonStyle = "👍👎", }) => {
1021+
const { button, div } = van.tags;
1022+
const counter = van.state(init);
1023+
return div(Object.assign(Object.assign({}, (id ? { id } : {})), { "data-counter": counter }), "❤️ ", counter, " ", button({ onclick: () => ++counter.val }, () => [...van.val(buttonStyle)][0]), button({ onclick: () => --counter.val }, () => [...van.val(buttonStyle)][1]));
1024+
};
10281025
const hydrateExample = (Counter) => withHiddenDom(async (hiddenDom) => {
10291026
const counterInit = 5;
10301027
const selectDom = select({ value: "👆👇" }, option("👆👇"), option("👍👎"), option("🔼🔽"), option("⏫⏬"), option("📈📉"));

test/van.test.nomodule.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -951,14 +951,11 @@
951951
const counter = van3.state(init);
952952
return div3(Object.assign(Object.assign({}, id ? { id } : {}), { "data-counter": counter }), "\u2764\uFE0F ", counter, " ", button2({ onclick: () => ++counter.val }, up), button2({ onclick: () => --counter.val }, down));
953953
};
954-
const OptimizedCounter = ({ van: { state, derive, val, tags: { button: button2, div: div3 } }, id, init = 0, buttonStyle = "\u{1F44D}\u{1F44E}" }) => div3((dom) => {
955-
if (dom)
956-
return dom;
957-
const counter = state(init);
958-
const up = state(void 0), down = state(void 0);
959-
derive(() => [up.val, down.val] = [...val(buttonStyle)]);
960-
return div3(Object.assign(Object.assign({}, id ? { id } : {}), { "data-counter": counter }), "\u2764\uFE0F ", counter, " ", button2({ onclick: () => ++counter.val }, up), button2({ onclick: () => --counter.val }, down));
961-
}).firstChild;
954+
const OptimizedCounter = ({ van: van3, id, init = 0, buttonStyle = "\u{1F44D}\u{1F44E}" }) => {
955+
const { button: button2, div: div3 } = van3.tags;
956+
const counter = van3.state(init);
957+
return div3(Object.assign(Object.assign({}, id ? { id } : {}), { "data-counter": counter }), "\u2764\uFE0F ", counter, " ", button2({ onclick: () => ++counter.val }, () => [...van3.val(buttonStyle)][0]), button2({ onclick: () => --counter.val }, () => [...van3.val(buttonStyle)][1]));
958+
};
962959
const hydrateExample = (Counter2) => withHiddenDom(async (hiddenDom) => {
963960
const counterInit = 5;
964961
const selectDom = select({ value: "\u{1F446}\u{1F447}" }, option("\u{1F446}\u{1F447}"), option("\u{1F44D}\u{1F44E}"), option("\u{1F53C}\u{1F53D}"), option("\u23EB\u23EC"), option("\u{1F4C8}\u{1F4C9}"));

test/van.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,21 +1333,17 @@ const runTests = async (van: VanForTesting, msgDom: Element, {debug}: BundleOpti
13331333
}
13341334

13351335
const OptimizedCounter = ({
1336-
van: {state, derive, val, tags: {button, div}},
1337-
id, init = 0, buttonStyle = "👍👎",
1338-
}: CounterProps) => <HTMLDivElement>div((dom: Node | undefined) => {
1339-
if (dom) return dom
1340-
1341-
const counter = state(init)
1342-
const up = state(<string | undefined>undefined), down = state(<string | undefined>undefined)
1343-
derive(() => [up.val, down.val] = [...val(buttonStyle)])
1336+
van, id, init = 0, buttonStyle = "👍👎",
1337+
}: CounterProps) => {
1338+
const {button, div} = van.tags
13441339

1340+
const counter = van.state(init)
13451341
return div({...(id ? {id} : {}), "data-counter": counter},
13461342
"❤️ ", counter, " ",
1347-
button({onclick: () => ++counter.val}, up),
1348-
button({onclick: () => --counter.val}, down),
1343+
button({onclick: () => ++counter.val}, () => [...van.val(buttonStyle)][0]),
1344+
button({onclick: () => --counter.val}, () => [...van.val(buttonStyle)][1]),
13491345
)
1350-
}).firstChild
1346+
}
13511347

13521348
const hydrateExample = (
13531349
Counter: (props: CounterProps) => HTMLDivElement,

0 commit comments

Comments
 (0)