Skip to content

Commit 89d88bf

Browse files
committed
changed props check order
1 parent 4b962df commit 89d88bf

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

cjs/json.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const ids = umap(new WeakMap);
77
let id = 0;
88

99
const tag = type => (template, ...values) => ({
10+
id: ids.get(template) ||
11+
ids.set(template, id++),
1012
type,
11-
template,
1213
values,
13-
id: ids.get(template) ||
14-
ids.set(template, id++)
14+
template
1515
});
1616

1717
html.json = tag('html');
@@ -35,10 +35,10 @@ const asJSON = value => isJSON(value) ? unroll(value) : value;
3535
const isJSON = thing => (
3636
typeof thing === 'object' &&
3737
thing !== null &&
38+
'id' in thing &&
3839
'type' in thing &&
39-
'template' in thing &&
4040
'values' in thing &&
41-
'id' in thing
41+
'template' in thing
4242
);
4343

4444
const render = (where, what) => $render(

esm/json.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const ids = umap(new WeakMap);
66
let id = 0;
77

88
const tag = type => (template, ...values) => ({
9+
id: ids.get(template) ||
10+
ids.set(template, id++),
911
type,
10-
template,
1112
values,
12-
id: ids.get(template) ||
13-
ids.set(template, id++)
13+
template
1414
});
1515

1616
html.json = tag('html');
@@ -34,10 +34,10 @@ const asJSON = value => isJSON(value) ? unroll(value) : value;
3434
const isJSON = thing => (
3535
typeof thing === 'object' &&
3636
thing !== null &&
37+
'id' in thing &&
3738
'type' in thing &&
38-
'template' in thing &&
3939
'values' in thing &&
40-
'id' in thing
40+
'template' in thing
4141
);
4242

4343
const render = (where, what) => $render(

test/json.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<script type="module">
99
import {render, html} from '../esm/json.js';
1010
const strong = name => html.json`<strong>${name}</strong>`;
11-
const greetings = name => html.json`
11+
const greetings = name => JSON.parse(JSON.stringify(html.json`
1212
<div>Hello ${strong(name)} 👋</div>
13-
`;
13+
`));
1414

1515
console.log(greetings('console'));
1616
render(document.body, greetings('World'));

0 commit comments

Comments
 (0)