Skip to content

Commit 2439462

Browse files
committed
switch to @ivi/htm
1 parent 4a17457 commit 2439462

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

frameworks/keyed/ivi/package-lock.json

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

frameworks/keyed/ivi/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
"build-prod": "rollup -c rollup.config.mjs"
1919
},
2020
"dependencies": {
21-
"@ivi/tpl": "3.0.1",
21+
"@ivi/htm": "^3.0.2",
2222
"ivi": "3.0.3"
2323
},
2424
"devDependencies": {
25-
"tslib": "2.8.1",
26-
"typescript": "5.7.2",
27-
"rollup": "4.27.4",
25+
"@ivi/rollup-plugin": "3.0.4",
2826
"@rollup/plugin-node-resolve": "15.3.0",
2927
"@rollup/plugin-terser": "0.4.4",
3028
"@rollup/plugin-typescript": "12.1.1",
31-
"@ivi/rollup-plugin": "3.0.4"
29+
"rollup": "4.27.4",
30+
"tslib": "2.8.1",
31+
"typescript": "5.7.2"
3232
}
33-
}
33+
}

frameworks/keyed/ivi/src/main.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineRoot, dirtyCheck, update, component, List, eventDispatcher, getProps, useReducer } from "ivi";
2-
import { htm } from "@ivi/tpl";
2+
import { htm as html } from "@ivi/htm";
33
import { Entry, State, Action, ActionType } from "./types.js";
44

55
const random = (max: number) => Math.round(Math.random() * 1000) % max;
@@ -66,21 +66,26 @@ interface RowProps {
6666
const Row = component<RowProps>((c) => {
6767
const onSelect = () => { dispatch(c, { type: ActionType.Select, entry: getProps(c).entry }); };
6868
const onRemove = () => { dispatch(c, { type: ActionType.Remove, entry: getProps(c).entry }); };
69-
return ({ entry, selected }) => htm`
70-
tr${selected === true ? "danger" : ""}
71-
td.col-md-1 =${entry.id}
72-
td.col-md-4
73-
a @click=${onSelect} =${entry.label}
74-
td.col-md-1
75-
a @click=${onRemove} span.glyphicon.glyphicon-remove :aria-hidden='true'
76-
td.col-md-6
77-
`;
69+
return ({ entry, selected }) => html`
70+
<tr class=${selected === true ? "danger" : ""}>
71+
<td class="col-md-1" .textContent=${entry.id}/>
72+
<td class="col-md-4">
73+
<a @click=${onSelect} .textContent=${entry.label}/>
74+
</td>
75+
<td class="col-md-1">
76+
<a @click=${onRemove}>
77+
<span class="glyphicon glyphicon-remove" aria-hidden="true"/>
78+
</a>
79+
</td>
80+
<td class="col-md-6"/>
81+
</tr>
82+
`;
7883
});
7984

80-
const Button = (text: string, id: string, onClick: () => void) => /* preventClone */ htm`
81-
div.col-sm-6.smallpad
82-
button.btn.btn-primary.btn-block :type='button' :id=${id} @click=${onClick}
83-
=${text}
85+
const Button = (text: string, id: string, onClick: () => void) => /* preventClone */ html`
86+
<div class="col-sm-6 smallpad">
87+
<button class="btn btn-primary btn-block" type="button" id=${id} @click=${onClick} .textContent=${text}/>
88+
</div>
8489
`;
8590

8691
const App = component((c) => {
@@ -98,18 +103,28 @@ const App = component((c) => {
98103

99104
return () => {
100105
const { data, selected } = _state();
101-
return /* preventClone */ htm`
102-
div.container
103-
div.jumbotron
104-
div.row
105-
div.col-md-6 h1 'ivi'
106-
div.col-md-6 div.row ${buttons}
107-
table.table.table-hover.table-striped.test-data
108-
@dispatch=${onDispatch}
109-
${data.length
110-
? htm`tbody ${List(data, getEntryId, (entry) => Row({ entry, selected: selected === entry.id }))}`
111-
: htm`tbody`}
112-
span.preloadicon.glyphicon.glyphicon-remove :aria-hidden='true'
106+
return /* preventClone */ html`
107+
<div class="container">
108+
<div class="jumbotron">
109+
<div class="row">
110+
<div class="col-md-6">
111+
<h1>ivi</h1>
112+
</div>
113+
<div class="col-md-6">
114+
<div class="row">
115+
${buttons}
116+
</div>
117+
</div>
118+
</div>
119+
</div>
120+
<table class="table table-hover table-striped test-data" @dispatch=${onDispatch}>
121+
${data.length
122+
? html`<tbody>${List(data, getEntryId, (entry) => Row({ entry, selected: selected === entry.id }))}</tbody>`
123+
: html`<tbody/>`
124+
}
125+
</table>
126+
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"/>
127+
</div>
113128
`;
114129
};
115130
});

0 commit comments

Comments
 (0)