Skip to content

Commit bd087f0

Browse files
committed
Merge PR #1922: update native-document framework
2 parents 7770b74 + cf46518 commit bd087f0

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

frameworks/keyed/native-document/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link href="/css/currentStyle.css" rel="stylesheet" />
66
</head>
77
<body>
8-
<div id="main"></div>
8+
<div id="root"></div>
99
<script src="dist/main.js"></script>
1010
</body>
1111
</html>

frameworks/keyed/native-document/package-lock.json

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

frameworks/keyed/native-document/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dev": "vite"
1212
},
1313
"dependencies": {
14-
"native-document": "1.0.26",
14+
"native-document": "1.0.34",
1515
"vite": "^7.0.4"
1616
}
1717
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Link, Span } from "native-document/elements";
2-
import AppService from "../service";
32

4-
export default function RemoveIcon(itemId){
5-
return Link(
6-
Span({ class: 'glyphicon glyphicon-remove', 'aria-hidden': true })
7-
).nd.onClick(() => AppService.remove(itemId));
8-
};
3+
4+
export default (function RemoveIcon(attributes) {
5+
return Link(Span(attributes));
6+
}).cached({ class: 'glyphicon glyphicon-remove', 'aria-hidden': true });
Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
import { Tr, Td, ForEachArray, Link, Span, Div, Table, TBody } from "native-document/elements";
2-
import { Observable } from "native-document";
2+
import { useCache } from 'native-document';
33

44
import Jumbotron from "./components/Jumbotron";
55
import RemoveIcon from "./components/RemoveIcon";
66

77
import AppService from "./service";
88

9-
const App = () => {
10-
11-
return Div({ class: 'container' }, [
12-
Jumbotron(),
13-
Table({ class: 'table table-hover table-striped test-data' }, [
14-
TBody(
15-
ForEachArray(AppService.data, (item) => {
16-
return Tr( { class: { 'danger': AppService.selected.when(item.id) } }, [
17-
Td({ class: 'col-md-1' }, item.id),
18-
Td({ class: 'col-md-4' },
19-
Link(item.label)
20-
).nd.onClick(() => AppService.select(item.id)),
21-
Td({ class: 'col-md-1' }, RemoveIcon(item.id)),
22-
Td({ class: 'col-md-6'})
23-
]);
24-
},
25-
'id')
26-
),
27-
Span({ class: 'preloadicon glyphicon glyphicon-remove', 'aria-hidden': true })
28-
])
9+
10+
const Attributes = {
11+
table: { class: 'table table-hover table-striped test-data' },
12+
};
13+
14+
const TableRowBuilder = useCache(($binder) => {
15+
16+
const isSelected = $binder.class((item) => AppService.selected.when(item.id));
17+
const id = $binder.value((item) => item.id);
18+
const label = $binder.value((item) => item.label);
19+
20+
const rowClick = $binder.attach((_, item) => AppService.select(item.id));
21+
const removeClick = $binder.attach((_, item) => AppService.remove(item.id));
22+
23+
return Tr( { class: { 'danger': isSelected } }, [
24+
Td({ class: 'col-md-1' }, id),
25+
Td({ class: 'col-md-4' }, Link(label)).nd.attach('onClick', rowClick),
26+
Td({ class: 'col-md-1' },
27+
RemoveIcon().nd.attach('onClick', removeClick)
28+
),
29+
Td({ class: 'col-md-6'})
2930
]);
30-
}
31+
});
32+
33+
const App = Div({ class: 'container' }, [
34+
Jumbotron(),
35+
Table(Attributes.table,
36+
TBody(ForEachArray(AppService.data, TableRowBuilder, 'id', { isParentUniqueChild: true}))
37+
),
38+
Span({ class: 'preloadicon glyphicon glyphicon-remove', 'aria-hidden': true })
39+
]);
3140

32-
document.querySelector('#main').append(App());
41+
document.getElementById('root').appendChild(App);

frameworks/keyed/native-document/src/service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const selected = Observable(0);
88
const AppService = {
99
data,
1010
selected,
11+
clean: Observable(false),
1112
resetSelected() {
1213
selected.disconnectAll();
1314
selected.set(0);

0 commit comments

Comments
 (0)