From 5f21fcc100098755b01c7f0d17e9c39f2cbeb7b0 Mon Sep 17 00:00:00 2001 From: djmaze Date: Fri, 13 Aug 2021 10:01:01 +0200 Subject: [PATCH] hasher.changed.* to hasher.* --- dev/Knoin/Knoin.js | 2 +- dev/bootstrap.js | 10 +++++----- vendors/routes/hasher.js | 16 ++++++---------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index a58566a57..e97250004 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -303,7 +303,7 @@ export function startScreens(screensClasses) { const cross = new Crossroads(); cross.addRoute(/^([a-zA-Z0-9-]*)\/?(.*)$/, screenOnRoute); - hasher.changed.add(cross.parse.bind(cross)); + hasher.add(cross.parse.bind(cross)); hasher.init(); setTimeout(() => $htmlCL.remove('rl-started-trigger'), 100); diff --git a/dev/bootstrap.js b/dev/bootstrap.js index 8f76009f9..46686092b 100644 --- a/dev/bootstrap.js +++ b/dev/bootstrap.js @@ -56,8 +56,8 @@ export default App => { rl.route.root(); setTimeout(() => (Settings.app('inIframe') ? parent : window).location.reload(), 100); }, - off: () => hasher.changed.active = false, - on: () => hasher.changed.active = true, + off: () => hasher.active = false, + on: () => hasher.active = true, /** * @param {string} sHash * @param {boolean=} silence = false @@ -70,11 +70,11 @@ export default App => { const cmd = replace ? 'replaceHash' : 'setHash'; if (silence) { - hasher.changed.active = false; + hasher.active = false; hasher[cmd](hash); - hasher.changed.active = true; + hasher.active = true; } else { - hasher.changed.active = true; + hasher.active = true; hasher[cmd](hash); hasher.setHash(hash); } diff --git a/vendors/routes/hasher.js b/vendors/routes/hasher.js index 4da3c7957..f74937ddf 100644 --- a/vendors/routes/hasher.js +++ b/vendors/routes/hasher.js @@ -28,7 +28,7 @@ if (_hash !== newHash) { var oldHash = _hash; _hash = newHash; //should come before event dispatch to make sure user can get proper value inside event handler - hasher.changed.dispatch(_trimHash(newHash), _trimHash(oldHash)); + hasher.dispatch(_trimHash(newHash), _trimHash(oldHash)); } }, _checkHistory = () => { @@ -64,13 +64,9 @@ * - pass current hash as 1st parameter to listeners and previous hash value as 2nd parameter. * @type signals.Signal */ - changed : { - active : true, - add : callback => _bindings.push(callback), - dispatch : function(...args) { - this.active && _bindings.forEach(callback => callback(...args)); - } - }, + active : true, + add : callback => _bindings.push(callback), + dispatch : (...args) => hasher.active && _bindings.forEach(callback => callback(...args)), /** * Start listening/dispatching changes in the hash/history. @@ -79,14 +75,14 @@ * */ init : () => { - hasher.init = ()=>{}; + hasher.init = ()=>0; _hash = _getWindowHash(); //thought about branching/overloading hasher.init() to avoid checking multiple times but //don't think worth doing it since it probably won't be called multiple times. addEventListener('hashchange', _checkHistory); - hasher.changed.dispatch(_trimHash(_hash)); + hasher.dispatch(_trimHash(_hash)); }, /**