Skip to content

Commit e65b65d

Browse files
authored
Merge pull request #75 from dojoengine/pgnd/events
feat(playground): add events.html
2 parents 21f6e76 + 4880ea9 commit e65b65d

File tree

2 files changed

+95
-10
lines changed

2 files changed

+95
-10
lines changed

playground/entities.html

+11-10
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@
4545

4646
updateManager.displayUpdate('fetch', entities);
4747

48-
const subscription = await client.onEntityUpdated([
49-
{
50-
Keys: {
51-
keys: [undefined],
52-
pattern_matching: "VariableLen",
53-
models: []
48+
const subscription = await client.onEntityUpdated(
49+
[
50+
{
51+
Keys: {
52+
keys: [undefined],
53+
pattern_matching: "VariableLen",
54+
models: []
55+
}
5456
}
55-
}
56-
], (updatedEntities) => {
57-
updateManager.displayUpdate('update', updatedEntities);
58-
});
57+
], (updatedEntities) => {
58+
updateManager.displayUpdate('update', updatedEntities);
59+
});
5960

6061
// Keeps the subscription alive.
6162
window.addEventListener('beforeunload', () => {

playground/events.html

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<html>
2+
3+
</html>
4+
5+
<head>
6+
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
7+
<link rel="stylesheet"
8+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css">
9+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
10+
</head>
11+
12+
<body>
13+
<script type="module">
14+
import init, { createClient, ClientConfig } from '../pkg/dojo_c.js';
15+
import { ThemeManager, UpdateManager } from './setup.js';
16+
17+
const themeManager = new ThemeManager();
18+
const updateManager = new UpdateManager();
19+
20+
async function run() {
21+
await init();
22+
23+
let config = {
24+
rpcUrl: 'http://localhost:5050',
25+
toriiUrl: 'http://localhost:8080',
26+
relayUrl: '',
27+
worldAddress: '0x064613f376f05242dfcc9fe360fa2ce1fdd6b00b1ce73dae2ea649ea118fd9be'
28+
}
29+
30+
let cconfig = new ClientConfig(config.rpcUrl, config.toriiUrl, config.relayUrl, config.worldAddress);
31+
const client = await createClient(cconfig);
32+
33+
let events = await client.getEventMessages({
34+
limit: 10,
35+
offset: 0,
36+
dont_include_hashed_keys: true,
37+
order_by: [],
38+
entity_models: [],
39+
clause: {
40+
Keys: {
41+
keys: [undefined],
42+
pattern_matching: "VariableLen",
43+
models: []
44+
}
45+
}
46+
});
47+
48+
updateManager.displayUpdate('fetch', events);
49+
50+
const is_historical = false;
51+
52+
const subscription = await client.onEventMessageUpdated(
53+
[
54+
{
55+
Keys: {
56+
keys: [undefined],
57+
pattern_matching: "VariableLen",
58+
models: []
59+
}
60+
}
61+
],
62+
is_historical,
63+
(updatedEvents) => {
64+
updateManager.displayUpdate('update', updatedEvents);
65+
});
66+
67+
// Keeps the subscription alive.
68+
window.addEventListener('beforeunload', () => {
69+
if (subscription) {
70+
subscription.cancel();
71+
}
72+
});
73+
}
74+
75+
run().catch(error => {
76+
console.error(error);
77+
updateManager.displayUpdate('error', error.toString());
78+
});
79+
80+
console.log("a");
81+
</script>
82+
</body>
83+
84+
</html>

0 commit comments

Comments
 (0)