13
0

WebSockets: avoid duplicated node+addr hash function in JS code

This commit is contained in:
Luciano Iam 2020-04-12 12:07:10 +02:00 committed by Robin Gareus
parent 22199e8845
commit feeda2c19d
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 10 additions and 4 deletions

View File

@ -43,8 +43,8 @@ import { Switch, DiscreteSlider, ContinuousSlider, LogarithmicSlider,
} else if (msg.node == 'strip_plugin_param_desc') { } else if (msg.node == 'strip_plugin_param_desc') {
createStripPluginParam (msg.addr, ...msg.val); createStripPluginParam (msg.addr, ...msg.val);
} else if (FEEDBACK_NODES.includes(msg.node)) { } else if (FEEDBACK_NODES.includes(msg.node)) {
if (widgets[[msg.node, msg.addr]]) { if (widgets[msg.hash]) {
widgets[[msg.node, msg.addr]].value = msg.val[0]; widgets[msg.hash].value = msg.val[0];
} }
} }
}; };

View File

@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
import { nodeAddressHash } from '/shared/channel.js';
export class Widget { export class Widget {
constructor (node, addr, html) { constructor (node, addr, html) {
@ -39,7 +41,7 @@ export class Widget {
} }
get hash () { get hash () {
return [this.node].concat(this.addr).join('_'); return nodeAddressHash(this.node, this.addr);
} }
} }

View File

@ -18,6 +18,10 @@
const JSON_INF = 1.0e+128; const JSON_INF = 1.0e+128;
export function nodeAddressHash(node, addr) {
return [node].concat(addr).join('_');
}
export class MessageChannel { export class MessageChannel {
constructor (host) { constructor (host) {
@ -95,7 +99,7 @@ export class Message {
} }
get hash () { get hash () {
return [this.node].concat(this.addr).join('_'); return nodeAddressHash(this.node, this.addr);
} }
toString () { toString () {