stop using Gun.chain.map; monitor game list changes manually

This commit is contained in:
Jesse D. McDonald 2020-03-29 01:14:26 -05:00
parent f184df6447
commit 8e639a68eb
1 changed files with 66 additions and 48 deletions

View File

@ -796,8 +796,7 @@ $(function (){
}
window.setTimeout(function(){
gun.get(PacoSakoUUID).get('meta').map().on(function(d,key){
if (key.match(/^[0-9a-f]{16}$/)) {
function updateSelectMeta(d, key) {
d = d || {};
debug('got meta for key ' + key, d);
const lightName = shortenName(String(d.lightName || 'Light'));
@ -849,7 +848,26 @@ $(function (){
$('#cb_select_game')[0].selectedIndex = -1;
}
}
let cancellers = {};
let cancelAll = gun.get(PacoSakoUUID).get('meta').onWithCancel(function(meta) {
for (const gameId in meta) { /* use of 'in' here is deliberate */
/* 'gameId' may include extra GUN fields like '_' */
if (gameId.match(/^[0-9a-f]{16}$/)) {
if (!Gun.obj.is(meta[gameId])) {
updateSelectMeta(null, gameId);
if (gameId in cancellers) {
cancellers[gameId]();
delete cancellers[gameId];
}
} else if (!(gameId in cancellers)) {
cancellers[gameId] = gun.get(meta[gameId]).onWithCancel(function(d) {
updateSelectMeta(d, gameId);
});
}
}
}
}, { change: true });
}, 1);
window.setInterval(function(){