reduce overhead in hash set/get

This commit is contained in:
Andrew Dolgov 2021-03-06 22:41:46 +03:00
parent 7b0b5b55c7
commit 1d9fa2a42e
3 changed files with 21 additions and 21 deletions

View File

@ -18,6 +18,15 @@ const App = {
is_prefs: false, is_prefs: false,
LABEL_BASE_INDEX: -1024, LABEL_BASE_INDEX: -1024,
_translations: {}, _translations: {},
Hash: {
get: function() {
return dojo.queryToObject(window.location.hash.substring(1));
},
set: function(params) {
const obj = dojo.queryToObject(window.location.hash.substring(1));
window.location.hash = dojo.objectToQuery({...obj, ...params});
}
},
l10n: { l10n: {
ngettext: function(msg1, msg2, n) { ngettext: function(msg1, msg2, n) {
return self.__((parseInt(n) > 1) ? msg2 : msg1); return self.__((parseInt(n) > 1) ? msg2 : msg1);
@ -1269,6 +1278,6 @@ const App = {
default: default:
console.log("quickMenuGo: unknown action: " + opid); console.log("quickMenuGo: unknown action: " + opid);
} }
} },
} }

View File

@ -236,12 +236,12 @@ const Feeds = {
//document.onkeypress = (event) => { return App.hotkeyHandler(event) }; //document.onkeypress = (event) => { return App.hotkeyHandler(event) };
window.onresize = () => { Headlines.scrollHandler(); } window.onresize = () => { Headlines.scrollHandler(); }
/* global hash_get */ const hash = App.Hash.get();
const hash_feed_id = hash_get('f');
const hash_feed_is_cat = hash_get('c') == "1";
if (hash_feed_id != undefined) { console.log('got hash', hash);
this.open({feed: hash_feed_id, is_cat: hash_feed_is_cat});
if (hash.f != undefined) {
this.open({feed: parseInt(hash.f), is_cat: parseInt(hash.c)});
} else { } else {
this.openDefaultFeed(); this.openDefaultFeed();
} }
@ -305,9 +305,12 @@ const Feeds = {
setActive: function(id, is_cat) { setActive: function(id, is_cat) {
console.log('setActive', id, is_cat); console.log('setActive', id, is_cat);
/* global hash_set */ if ('requestIdleCallback' in window)
hash_set('f', id); window.requestIdleCallback(() => {
hash_set('c', is_cat ? 1 : 0); App.Hash.set({f: id, c: is_cat ? 1 : 0});
});
else
App.Hash.set({f: id, c: is_cat ? 1 : 0});
this._active_feed_id = id; this._active_feed_id = id;
this._active_feed_is_cat = is_cat; this._active_feed_is_cat = is_cat;

View File

@ -69,15 +69,3 @@ require(["dojo/_base/kernel",
}); });
}); });
/* exported hash_get */
function hash_get(key) {
const obj = dojo.queryToObject(window.location.hash.substring(1));
return obj[key];
}
/* exported hash_set */
function hash_set(key, value) {
const obj = dojo.queryToObject(window.location.hash.substring(1));
obj[key] = value;
window.location.hash = dojo.objectToQuery(obj);
}