-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsignals.html
48 lines (45 loc) · 1.82 KB
/
signals.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
<head>
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" crossorigin="anonymous"></script>
<script type="importmap">
{
"imports": {
"@preact/signals-core": "https://ga.jspm.io/npm:@preact/[email protected]/dist/signals-core.module.js",
"phx-live-state": "https://ga.jspm.io/npm:[email protected]/build/src/index.js",
"solid-js": "https://ga.jspm.io/npm:[email protected]/dist/dev.js"
},
"scopes": {
"https://ga.jspm.io/": {
"json-joy/esm/json-patch": "https://ga.jspm.io/npm:[email protected]/esm/json-patch/index.js",
"phoenix": "https://ga.jspm.io/npm:[email protected]/priv/static/phoenix.mjs",
"process": "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/process.js",
"reflect-metadata": "https://ga.jspm.io/npm:[email protected]/Reflect.js",
"subscript": "https://ga.jspm.io/npm:[email protected]/subscript.js",
"wc-context": "https://ga.jspm.io/npm:[email protected]/core.js"
}
}
}
</script>
<script type="module">
import { createSignal } from 'solid-js';
import { signal, effect } from "@preact/signals-core";
import LiveState from 'phx-live-state';
function createLiveSignal(liveState, initialState) {
const stateSignal = signal({people: []});
liveState.addEventListener('state:change', ({ detail: {state} }) => {
stateSignal.value = state;
})
return stateSignal;
}
const liveState = new LiveState({ url: 'ws://localhost:4000/live_state', topic: 'people:all' });
liveState.connect();
const state = createLiveSignal(liveState, {});
effect(() => {
const {people} = state.value;
console.log(state.value);
console.log(`There are ${people?.length} people.`);
});
</script>
</head>
<body>
<h1>hi</h1>
</body>