-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
116 lines (96 loc) · 2.33 KB
/
index.html
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PV Example</title>
<style>
body > div {
margin:20px;
padding:20px;
background-color:lightblue;
}
h2 {
margin-top:0;
}
p {
margin-bottom:.5rem;
}
pre {
font-size:1.4rem;
}
</style>
</head>
<body>
<h1>Petite Vue Global Store</h1>
<div v-scope="sender(globalStore)">
<h2>This is an island (v-scope)</h2>
<input type="text" @input="setMessage( $event.target.value )" placeholder="message">
<button @click="toggle">toggle checkbox</button>
</div>
<div v-scope="reader(globalStore)">
<h2>This is another island (different v-scope)</h2>
<p>{{store.message}}</p>
<p>{{bigMessage}}</p>
<input type="checkbox" v-model="store.toggle">
</div>
<div v-scope="counter(globalStore)"></div>
<div v-scope="counter(globalStore)"></div>
<div v-scope="{ globalStore }">
<h2>And yet another with just global store:</h2>
<pre>{{globalStore}}</pre>
</div>
<script type="module">
import PV from './lib/main.js';
const sender = (store) => {
return {
toggle() {
store.toggle = !store.toggle;
},
setMessage(msg) {
store.message = msg;
},
}
}
const reader = (store) => {
return {
store,
get bigMessage() {
return store.message.toUpperCase()
},
}
}
const counter = (store) => {
store.count = store.count ?? 0;
return {
localCount:0,
get count() {
return store.count
},
inc() {
this.localCount++;
store.count++;
},
$template: `
<div>
<h2>Counter:</h2>
<p>Local Count: {{localCount}}</p>
<p>Global Count: {{count}}</p>
<button @click="inc">increment</button>
</div>`
}
}
PV.registerScope( "sender", sender );
PV.registerScope( "reader", reader );
PV.registerScope( "counter", counter );
//you can initialize the global store if you like
//but you don't have to, you can also add props as needed from scopes
PV.initializeStore( {
toggle:false,
message:"initial message"
});
const app = PV.mount();
</script>
</body>
</html>