diff --git a/src/_h5ai/public/js/lib/core/event.js b/src/_h5ai/public/js/lib/core/event.js index 655e385a..16f16e1f 100644 --- a/src/_h5ai/public/js/lib/core/event.js +++ b/src/_h5ai/public/js/lib/core/event.js @@ -1,33 +1,27 @@ -const {lo} = require('../globals'); +const isStr = x => typeof x === 'string'; +const isFn = x => typeof x === 'function'; const subscriptions = {}; -function sub(topic, listener) { - if (lo.isString(topic) && lo.isFunction(listener)) { +const sub = (topic, listener) => { + if (isStr(topic) && isFn(listener)) { if (!subscriptions[topic]) { subscriptions[topic] = []; } subscriptions[topic].push(listener); } -} +}; -function unsub(topic, listener) { - if (lo.isString(topic) && lo.isFunction(listener) && subscriptions[topic]) { - subscriptions[topic] = lo.without(subscriptions[topic], listener); - } -} - -function pub(topic, ...args) { +const pub = (topic, ...args) => { // console.log(topic, args); - if (lo.isString(topic) && subscriptions[topic]) { - lo.each(subscriptions[topic], listener => { + if (isStr(topic) && subscriptions[topic]) { + subscriptions[topic].forEach(listener => { listener.apply(topic, args); }); } -} +}; module.exports = { sub, - unsub, pub }; diff --git a/src/_h5ai/public/js/lib/server.js b/src/_h5ai/public/js/lib/server.js index 2ac4e285..29e87eb0 100644 --- a/src/_h5ai/public/js/lib/server.js +++ b/src/_h5ai/public/js/lib/server.js @@ -1,6 +1,6 @@ const {jq, lo} = require('./globals'); -function request(data) { +const request = data => { return new Promise(resolve => { jq.ajax({ url: '?', @@ -11,9 +11,9 @@ function request(data) { .done(json => resolve(json)) .fail(() => resolve()); }); -} +}; -function formRequest(data) { +const formRequest = data => { const $form = jq('
'); lo.each(data, (val, key) => { @@ -24,7 +24,7 @@ function formRequest(data) { }); $form.appendTo('body').submit().remove(); -} +}; module.exports = { request, diff --git a/src/_h5ai/public/js/pre.js b/src/_h5ai/public/js/pre.js index 64970ccd..99a1e1d5 100644 --- a/src/_h5ai/public/js/pre.js +++ b/src/_h5ai/public/js/pre.js @@ -1,6 +1,6 @@ /* eslint-disable func-names,no-var */ (function (win) { - if (typeof win !== 'object' || win.window !== win || !win.document) { + if (!win || win.window !== win || !win.document) { throw new Error('no-window'); } @@ -15,26 +15,13 @@ } } - assert('console', win.console && typeof win.console.log === 'function'); - assert('assign', win.Object && typeof win.Object.assign === 'function'); - assert('promise', win.Promise && typeof win.Promise === 'function'); - assert('history', win.history && typeof win.history.pushState === 'function'); + function isFn(x) { + return typeof x === 'function'; + } - assert('canvas', (function () { - var elem = win.document.createElement('canvas'); - return elem.getContext && elem.getContext('2d'); - }())); - - assert('storage', (function () { - var key = '#test#'; - try { - win.localStorage.setItem(key, key); - win.localStorage.removeItem(key); - return true; - } catch (e) { - return false; - } - }())); + assert('console', win.console && isFn(win.console.log)); + assert('assign', win.Object && isFn(win.Object.assign)); + assert('promise', isFn(win.Promise)); }(this)); /* eslint-enable */