Skip to content

Commit 151fff9

Browse files
committed
update to new API
1 parent 8048cb0 commit 151fff9

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def sendMsg():
66
window.webxdc.sendUpdate(
77
{
88
"payload": {
9-
"sender": window.webxdc.selfName(),
9+
"sender": window.webxdc.selfName,
1010
"text": text,
1111
}
1212
},
@@ -35,7 +35,7 @@ def _onload():
3535
)
3636

3737
window.webxdc.setUpdateListener(receiveUpdate) # process incoming messages
38-
window.webxdc.getAllUpdates().forEach(receiveUpdate) # restore app state
38+
window.webxdc.getAllUpdates().then(lambda updates: updates.forEach(receiveUpdate)) # restore app state
3939

4040

4141
window.onload = _onload

webxdc.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// debug friend: document.writeln(JSON.stringify(value));
2+
//@ts-check
3+
/** @type {import('./webxdc').Webxdc<any>} */
24
window.webxdc = (() => {
3-
var updateListener = () => {};
5+
var updateListener = (_) => {};
46
var updatesKey = "__xdcUpdatesKey__";
57
window.addEventListener('storage', (event) => {
68
if (event.key == null) {
@@ -13,19 +15,14 @@ window.webxdc = (() => {
1315
}
1416
});
1517

18+
var params = new URLSearchParams(window.location.hash.substr(1));
1619
return {
17-
selfAddr: () => {
18-
var params = new URLSearchParams(window.location.hash.substr(1));
19-
return params.get("addr") || "device0@local.host";
20-
},
21-
selfName: () => {
22-
var params = new URLSearchParams(window.location.hash.substr(1));
23-
return params.get("name") || "device0";
24-
},
20+
selfAddr: params.get("addr") || "device0@local.host",
21+
selfName: params.get("name") || "device0",
2522
setUpdateListener: (cb) => (updateListener = cb),
2623
getAllUpdates: () => {
2724
var updatesJSON = window.localStorage.getItem(updatesKey);
28-
return updatesJSON ? JSON.parse(updatesJSON) : [];
25+
return Promise.resolve(updatesJSON ? JSON.parse(updatesJSON) : []);
2926
},
3027
sendUpdate: (update, description) => {
3128
// alert(description+"\n\n"+JSON.stringify(payload));
@@ -52,7 +49,7 @@ window.addXdcPeer = () => {
5249
window.open(url);
5350

5451
// update next peer ID
55-
params.set("next_peer", peerId + 1);
52+
params.set("next_peer", String(peerId + 1));
5653
window.location.hash = "#" + params.toString();
5754
}
5855

@@ -70,9 +67,9 @@ window.alterXdcApp = () => {
7067
title = document.createElement('title');
7168
document.getElementsByTagName('head')[0].append(title);
7269
}
73-
title.innerText = window.webxdc.selfAddr();
70+
title.innerText = window.webxdc.selfAddr;
7471

75-
if (window.webxdc.selfName() === "device0") {
72+
if (window.webxdc.selfName === "device0") {
7673
var div = document.createElement('div');
7774
div.innerHTML =
7875
'<div style="' + styleControlPanel + '">' +

0 commit comments

Comments
 (0)