-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
39 lines (28 loc) · 745 Bytes
/
main.js
File metadata and controls
39 lines (28 loc) · 745 Bytes
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
import { signal, effect, derived } from './signals.js'
const btn = document.querySelector('button')
btn.addEventListener('click', () => count.value++)
const count = signal(0)
const double = derived(() => count.value * 2)
effect(() => {
btn.innerText = count.value
})
effect(() => {
if (count.value > 10) {
console.log('dangerously high')
count.value = 0
}
})
effect(() => console.log(double.value))
/*
import { observable } from './observable.js'
const btn = document.querySelector('button')
btn.addEventListener('click', () => counter.increment())
const counter = observable(0)
counter.subscribe((count) => {
btn.innerText = count
})
const unsubscribe = counter.subscribe((count) => {
console.log(count)
})
unsubscribe()
*/