-
Notifications
You must be signed in to change notification settings - Fork 5
/
vdom-examples.js
78 lines (72 loc) · 2.31 KB
/
vdom-examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { h, unmount, patch } from './vue-vdom.js';
// VDOM 1 ---------------------------------
export const vdom1 = h(
'h1',
{ class: 'text-orange-500 text-3xl font-bold' },
'Vue.js Amsterdam 🧡'
);
// VDOM 2 ---------------------------------
export const vdom2 = h(
'button',
{
class: 'bg-gray-200 p-2 rounded',
onClick: () => alert('🤘'),
},
'Click here 🎉'
);
// VDOM 3 ---------------------------------
export const vdom3 = h(
'div',
{ class: 'bg-gray-800 rounded-full p-6' },
h('h1', { class: 'text-6xl' }, '🍕')
);
// VDOM 4 ---------------------------------
export const vdom4 = h('div', { class: 'bg-gray-800 rounded p-4' }, [
h('h1', { class: 'text-white text-2xl' }, 'Yummy foods'),
h('ol', { class: 'list-decimal text-white ml-4' }, [
h('li', null, '🍕'),
h('li', null, '🍔'),
h('li', null, '🌮'),
h('li', null, '🍟'),
]),
]);
// VDOM 5 ---------------------------------
const ducks = h('span', { class: 'text-3xl' }, '🦆🦆🦆');
const monkeys = h('span', { class: 'text-3xl' }, '🙈🙊🙉');
const goats = h('span', { class: 'text-3xl' }, '🐐🐐🐐');
export const vdom5 = h('div', { class: 'text-center rounded p-4' }, [
h(
'h1',
{ class: 'text-2xl font-bold' },
"I don't have no time for no monkey business"
),
h('div', null, [ducks, monkeys, goats]),
h(
'button',
{
class: 'text-3xl bg-gray-200 p-2 rounded mt-4',
onClick: () => unmount(monkeys),
},
'🚫🐒'
),
]);
// VDOM 7 ---------------------------------
export const vdom6 = h('div', { class: 'flex flex-col items-center' }, [
h('h1', { class: 'font-bold' }, "It's not a bug..."),
h('p', { class: 'text-5xl my-4' }, '🐛'),
h(
'button',
{
class: 'bg-black text-white p-2 rounded hover:bg-orange-500',
onClick: () => patch(vdom6, vdom6_patch),
},
'Patch 🩹'
),
]);
export const vdom6_patch = h('div', { class: 'flex flex-col items-center' }, [
h('h1', { class: 'font-bold' }, "... it's a feature!"),
h('div', { class: 'text-5xl' }, '✨'),
h('div', { class: 'text-5xl' }, '✨'),
h('div', { class: 'text-5xl' }, '✨'),
h('div', { class: 'text-5xl' }, '✨'),
]);