WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 8486acc

Browse files
committed
for demo
1 parent c7f708a commit 8486acc

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`npm run build`してから、`index.html`を live-server 等でブラウザで開くと動作確認できます。
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<script type="module" src="dist/App.js"></script>
5+
</body>
6+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare namespace JSX {
2+
interface IntrinsicElements {
3+
[key: string]: any;
4+
}
5+
}

05/jsx_react__eventHandler_build/package-lock.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scripts": {
3+
"build": "node_modules/.bin/tsc"
4+
},
5+
"devDependencies": {
6+
"typescript": "^5.5.4"
7+
}
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { h } from './h.js';
2+
3+
const App = () => {
4+
let count = 0;
5+
return (
6+
<button
7+
onClick={(event: Event) => {
8+
count++;
9+
(event.target! as HTMLButtonElement).textContent = count.toString();
10+
}}
11+
>
12+
{count}
13+
</button>
14+
);
15+
};
16+
17+
const dom = App();
18+
document.body.append(dom);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const h = (element: any, attributes: any, ...children: any) => {
2+
const el = document.createElement(element);
3+
for (const attrName in attributes) {
4+
const attrValue = attributes[attrName];
5+
if (/^on[A-Z][a-z]/.test(attrName) && typeof attrValue === 'function') {
6+
const eventName = attrName.slice(2).toLowerCase();
7+
el.addEventListener(eventName, attrValue);
8+
} else {
9+
el.setAttribute(attrName, attrValue);
10+
}
11+
}
12+
el.append(...children);
13+
return el;
14+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2021",
4+
"moduleResolution": "Bundler",
5+
"strict": true,
6+
"esModuleInterop": true,
7+
"skipLibCheck": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"jsx": "react",
10+
"jsxFactory": "h",
11+
"outDir": "dist"
12+
}
13+
}

0 commit comments

Comments
 (0)