Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jwc-runtime): <Fragment /> support #4

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/jwc-runtime/dom/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import { updateDOM } from "./dom";
* @param node the vnode
*/
export function createElement(node: VNode): Node {

// create a dom node according to the tag name of the vnode
const el = document.createElement(node.tagName);
const el = node.tagName === "Fragment" ? document.createDocumentFragment() : document.createElement(node.tagName);

// set the attributes of the dom node
for (const key in node.attributes) {
const attributes = node.attributes;
for (const key in attributes) {
if (key.startsWith("on")) {
el.addEventListener(key.slice(2).toLowerCase(), node.attributes[key]);
const eventName = key.slice(2).toLowerCase()
el.addEventListener(eventName, attributes[key])
} else {
el.setAttribute(key, node.attributes[key]);
// @ts-ignore
node.tagName === "Fragment" ? null : el.setAttribute(camelToDash(key), attributes[key]);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/jwc-runtime/v-dom/fragment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Fragment = "Fragment";
2 changes: 1 addition & 1 deletion packages/jwc-runtime/v-dom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './diff';
export * from './h';
// export * from './fragment';
export * from './fragment';
export * from './vnode';
export * from './patch';
6 changes: 3 additions & 3 deletions packages/jwc-starter-vite-ts/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JwcComponent, Component, Prop, h } from "jwcjs";
import { JwcComponent, Component, Prop, h, Fragment } from "jwcjs";
import styles from './App.css?inline';

@Component({
Expand Down Expand Up @@ -41,7 +41,7 @@ export class App extends JwcComponent {

public override render() {
return (
<div>
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
Expand All @@ -58,7 +58,7 @@ export class App extends JwcComponent {
<p class="read-the-docs">
Click on the Vite and Jwc logos to learn more
</p>
</div>
</>
)
}
}