From d07e88192b359c060dacb39a3dd6b4f9013b87b4 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Tue, 28 Nov 2017 22:30:37 +0100 Subject: [PATCH] Lint infodisplay code too --- .eslintrc.json | 3 +- infodisplay/infodisplay.js | 78 +++++++++++++++++++------------------- package.json | 2 +- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c4f879a..256e439 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,7 +10,8 @@ "customElements": false, "document": false, "fetch": false, - "Plotly": false + "Plotly": false, + "window": false }, "settings": { "import/parser": "babel-eslint" diff --git a/infodisplay/infodisplay.js b/infodisplay/infodisplay.js index 5798241..e2ab664 100644 --- a/infodisplay/infodisplay.js +++ b/infodisplay/infodisplay.js @@ -1,57 +1,59 @@ -var msgflo = window.infodisplay.msgflo; -var timeout = null; +const { msgflo } = window.infodisplay; +let timeout = null; -var getRotationUrl = function (urls, current) { - var newUrl = urls[Math.floor(Math.random() * urls.length)]; +function getRotationUrl(urls, current) { + const newUrl = urls[Math.floor(Math.random() * urls.length)]; if (newUrl === current && urls.length > 1) { // Flip the coin again return getRotationUrl(urls, current); } return newUrl; -}; +} -var DisplayParticipant = function (broker, role, defaultUrls, timer) { - var urls = defaultUrls; - var def = { +function DisplayParticipant(broker, role, defaultUrls, timer) { + let urls = defaultUrls; + let participant; + const def = { component: 'msgflo-browser/infodisplay', label: 'Browser-based information display', icon: 'television', inports: [ { id: 'open', - type: 'string' - }, - { - id: 'urls', - type: 'array' - } - ], - outports: [ - { - id: 'opened', - type: 'string' + type: 'string', }, { id: 'urls', type: 'array', - hidden: true - } - ] + }, + ], + outports: [ + { + id: 'opened', + type: 'string', + }, + { + id: 'urls', + type: 'array', + hidden: true, + }, + ], }; - var process = function (inport, indata, callback) { - var current = document.getElementById('current'); - var next = document.getElementById('next'); + const process = (inport, indata, callback) => { + const current = document.getElementById('current'); + const next = document.getElementById('next'); if (inport === 'urls') { // Update URL listing urls = indata; - return callback('urls', null, urls); + callback('urls', null, urls); } - next.onerror = function (err) { + next.onerror = (err) => { next.onload = null; next.onerror = null; participant.send('open', getRotationUrl(urls, indata)); - } - next.onload = function () { + callback('open', err); + }; + next.onload = () => { next.onload = null; next.onerror = null; // Cross-fade @@ -60,31 +62,31 @@ var DisplayParticipant = function (broker, role, defaultUrls, timer) { if (timeout) { clearTimeout(timeout); } - timeout = setTimeout(function () { + timeout = setTimeout(() => { participant.send('open', getRotationUrl(urls, indata)); }, timer); - return callback('opened', null, next.getAttribute('src')); + callback('opened', null, next.getAttribute('src')); }; next.setAttribute('src', indata); // Rotate internal URLs list }; - var client = new msgflo.mqtt.Client(broker, {}); - var participant = new msgflo.participant.Participant(client, def, process, role); + const client = new msgflo.mqtt.Client(broker, {}); + participant = new msgflo.participant.Participant(client, def, process, role); return participant; } -window.addEventListener('load', function () { - var params = msgflo.options({ +window.addEventListener('load', () => { + const params = msgflo.options({ broker: 'mqtt://c-beam.cbrp3.c-base.org:1882', role: 'infodisplay', urls: [ 'http://c-beam.cbrp3.c-base.org/he1display', - 'https://c-base.org' + 'https://c-base.org', ], timer: 120000, }); - var p = DisplayParticipant(params.broker, params.role, params.urls, params.timer); - p.start(function (err) { + const p = DisplayParticipant(params.broker, params.role, params.urls, params.timer); + p.start((err) => { if (err) { console.error(err); return; diff --git a/package.json b/package.json index 66210ae..28cfdcd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "build": "webpack", - "pretest": "eslint lib/*.js elements/*.js index.js", + "pretest": "eslint lib/*.js elements/*.js infodisplay/*.js index.js", "start": "http-server . -p 3000 -s", "test": "npm run pretest" },