Pre-bind methods
This commit is contained in:
26
js/trweb.js
26
js/trweb.js
@@ -8,7 +8,7 @@ class trweb {
|
||||
#loadcb = function(key) {return localStorage.getItem(`trweb.${key}`)};
|
||||
#savecb = function(key, value) {localStorage.setItem(`trweb.${key}`, value)};
|
||||
#logger = function(msg) {};
|
||||
#logcb = function(module, loglevel, msg) {this.#logger(`${module}: ${msg}`)};
|
||||
#logcb = function(module, loglevel, msg) {this.#logger(`${module}: ${msg}`)}.bind(this);
|
||||
|
||||
#timer;
|
||||
|
||||
@@ -30,7 +30,7 @@ class trweb {
|
||||
this.#logger = logger;
|
||||
}
|
||||
|
||||
this.#dom_servermanager = new trdom_servermanager(this.#loadcb, this.#savecb, this.#logcb.bind(this), this.#registerServer.bind(this))
|
||||
this.#dom_servermanager = new trdom_servermanager(this.#loadcb, this.#savecb, this.#logcb, this.#registerServer)
|
||||
|
||||
this.#guiFooter = document.createElement('div');
|
||||
this.#guiFooter.classList.add('trweb_footer');
|
||||
@@ -41,11 +41,11 @@ class trweb {
|
||||
}
|
||||
else {
|
||||
this.#logger('Waiting for document to load');
|
||||
document.addEventListener('DOMContentLoaded', this.#handler.bind(this));
|
||||
document.addEventListener('DOMContentLoaded', this.#handler);
|
||||
}
|
||||
}
|
||||
|
||||
#registerServer(name, initdata) {
|
||||
#registerServer = function(name, initdata) {
|
||||
let torrentCallback = function(hash, torrentInfo) {
|
||||
let mergedTorrentInfo = this.#knownTorrents[hash];
|
||||
if (mergedTorrentInfo == null) {
|
||||
@@ -55,11 +55,11 @@ class trweb {
|
||||
mergedTorrentInfo.name = torrentInfo.name;
|
||||
|
||||
this.#updateTorrentDisplay(mergedTorrentInfo);
|
||||
};
|
||||
let newserver = new trserver(initdata, function(msg) {this.#logger(`[Server: ${name}]: ${msg}`);}.bind(this), torrentCallback.bind(this));
|
||||
}.bind(this);
|
||||
let newserver = new trserver(initdata, function(msg) {this.#logger(`[Server: ${name}]: ${msg}`);}.bind(this), torrentCallback);
|
||||
this.#dom_servermanager.getServers()[name] = newserver;
|
||||
newserver.refreshTorrentList();
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
#createTorrentEntry(hash) {
|
||||
let torrent = new trtorrent(hash);
|
||||
@@ -79,7 +79,7 @@ class trweb {
|
||||
|
||||
#createServerEntryForTorrent(hash, srv) {
|
||||
this.#needsSort = true;
|
||||
let control = new trdom_torrentcontrol(hash, this.#dom_servermanager.getServers()[srv], this.#logcb.bind(this), function() {return this.#knownTorrents}.bind(this));
|
||||
let control = new trdom_torrentcontrol(hash, this.#dom_servermanager.getServers()[srv], this.#logcb, function() {return this.#knownTorrents}.bind(this));
|
||||
|
||||
let torrent = this.#knownTorrents[hash];
|
||||
|
||||
@@ -162,7 +162,7 @@ class trweb {
|
||||
}
|
||||
}
|
||||
|
||||
#handler(e) {
|
||||
#handler = function(e) {
|
||||
switch (e.type) {
|
||||
case 'DOMContentLoaded':
|
||||
this.#logger('Activating TRWEB instance');
|
||||
@@ -178,7 +178,7 @@ class trweb {
|
||||
this.setTimer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
refresh() {
|
||||
for (const [key, value] of Object.entries(this.#dom_servermanager.getServers())) {
|
||||
@@ -197,16 +197,16 @@ class trweb {
|
||||
return list;
|
||||
}
|
||||
|
||||
#timercb() {
|
||||
#timercb = function() {
|
||||
if (this.#needsSort) {
|
||||
this.#needsSort = false;
|
||||
this.sort();
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
setTimer() {
|
||||
this.#timer = window.setInterval(this.#timercb.bind(this), 2000);
|
||||
this.#timer = window.setInterval(this.#timercb, 2000);
|
||||
}
|
||||
|
||||
haltTimer() {
|
||||
|
||||
Reference in New Issue
Block a user