Skip to content

Commit 1aadea2

Browse files
authored
feat: context api (#15)
1 parent 6a2fb87 commit 1aadea2

19 files changed

Lines changed: 1995 additions & 219 deletions

docs/guide/context.md

Lines changed: 401 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"license": "MIT",
2020
"packageManager": "pnpm@10.12.4",
2121
"devDependencies": {
22+
"jsdom": "^27.0.1",
2223
"prettier": "^3.6.2",
2324
"typescript": "~5.9.3",
2425
"vitepress": "^1.6.4"

packages/compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kaori-compiler",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "JSX to lit-html compiler for kaori",
55
"type": "module",
66
"exports": {

packages/compiler/src/__tests__/__snapshots__/children-reactive.spec.ts.snap

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,115 +3,115 @@
33
exports[`Children prop reactivity > should NOT make arrow function children reactive (functions are static) 1`] = `
44
"import { component, html } from "kaori.js";
55
function Parent() {
6-
return component(For, {
6+
return html\`\${component(For, {
77
get items() {
88
return getItems();
99
},
1010
children: item => html\`<div>\${item.name}</div>\`
11-
});
11+
})}\`;
1212
}"
1313
`;
1414
1515
exports[`Children prop reactivity > should NOT make children reactive when containing only static content 1`] = `
1616
"import { component, html } from "kaori.js";
1717
function Parent() {
18-
return component(Container, {
18+
return html\`\${component(Container, {
1919
children: html\`<p>Static text</p>\`
20-
});
20+
})}\`;
2121
}"
2222
`;
2323
2424
exports[`Children prop reactivity > should handle nested reactive children correctly 1`] = `
25-
"import { component } from "kaori.js";
25+
"import { component, html } from "kaori.js";
2626
function Parent() {
27-
return component(Outer, {
27+
return html\`\${component(Outer, {
2828
get children() {
29-
return component(Middle, {
29+
return html\`\${component(Middle, {
3030
get children() {
31-
return component(Inner, {
31+
return html\`\${component(Inner, {
3232
get prop() {
3333
return getValue();
3434
}
35-
});
35+
})}\`;
3636
}
37-
});
37+
})}\`;
3838
}
39-
});
39+
})}\`;
4040
}"
4141
`;
4242
4343
exports[`Children prop reactivity > should make children reactive even with static component props (component call is dynamic) 1`] = `
44-
"import { component } from "kaori.js";
44+
"import { component, html } from "kaori.js";
4545
function Parent() {
46-
return component(Container, {
46+
return html\`\${component(Container, {
4747
get children() {
48-
return component(Child, {
48+
return html\`\${component(Child, {
4949
title: "static"
50-
});
50+
})}\`;
5151
}
52-
});
52+
})}\`;
5353
}"
5454
`;
5555
5656
exports[`Children prop reactivity > should make children reactive when containing component with function call props 1`] = `
57-
"import { component } from "kaori.js";
57+
"import { component, html } from "kaori.js";
5858
function Parent() {
59-
return component(Container, {
59+
return html\`\${component(Container, {
6060
get children() {
61-
return component(Child, {
61+
return html\`\${component(Child, {
6262
get title() {
6363
return getTitle();
6464
}
65-
});
65+
})}\`;
6666
}
67-
});
67+
})}\`;
6868
}"
6969
`;
7070
7171
exports[`Children prop reactivity > should make children reactive when containing function calls 1`] = `
72-
"import { component } from "kaori.js";
72+
"import { component, html } from "kaori.js";
7373
function Parent() {
74-
return component(Container, {
74+
return html\`\${component(Container, {
7575
get children() {
7676
return getMessage();
7777
}
78-
});
78+
})}\`;
7979
}"
8080
`;
8181
8282
exports[`Children prop reactivity > should make children reactive when containing html template with member access 1`] = `
8383
"import { component, html } from "kaori.js";
8484
function Parent() {
85-
return component(Container, {
85+
return html\`\${component(Container, {
8686
get children() {
8787
return html\`<p>\${user.name}</p>\`;
8888
}
89-
});
89+
})}\`;
9090
}"
9191
`;
9292
9393
exports[`Children prop reactivity > should make children reactive when containing member access 1`] = `
94-
"import { component } from "kaori.js";
94+
"import { component, html } from "kaori.js";
9595
function Parent() {
96-
return component(Container, {
96+
return html\`\${component(Container, {
9797
get children() {
9898
return user.name;
9999
}
100-
});
100+
})}\`;
101101
}"
102102
`;
103103
104104
exports[`Children prop reactivity > should make children reactive with mixed static and dynamic content 1`] = `
105105
"import { component, html } from "kaori.js";
106106
function Parent() {
107-
return component(Container, {
107+
return html\`\${component(Container, {
108108
get children() {
109-
return [html\`<p>Static</p>\`, getDynamic(), component(Child, {
109+
return [html\`<p>Static</p>\`, getDynamic(), html\`\${component(Child, {
110110
get prop() {
111111
return getValue();
112112
}
113-
})];
113+
})}\`];
114114
}
115-
});
115+
})}\`;
116116
}"
117117
`;

packages/compiler/src/__tests__/__snapshots__/ref-directive.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ exports[`Ref directive transformation > should transform ref on component 1`] =
4646
import { createRef } from "kaori.js";
4747
function App() {
4848
const myRef = createRef();
49-
return [component(MyComponent, {
49+
return [html\`\${component(MyComponent, {
5050
ref: myRef
51-
}), html\`<div \${ref(myRef)}>HTML element</div>\`];
51+
})}\`, html\`<div \${ref(myRef)}>HTML element</div>\`];
5252
}"
5353
`;
5454

0 commit comments

Comments
 (0)