From 55a9014be247a7c4f9f90a948bcef4b6cf17675f Mon Sep 17 00:00:00 2001 From: kor Date: Wed, 7 Nov 2018 00:45:52 +1300 Subject: [PATCH] Add load (links working again) with new promise setup. Improve seer (benchmark). --- docs/logic/main.js | 83 ++++++++++--------------------------------- docs/logic/seer.js | 16 ++++++++- docs/logic/wrap.js | 88 ++++++++++++++++++++++------------------------ 3 files changed, 76 insertions(+), 111 deletions(-) diff --git a/docs/logic/main.js b/docs/logic/main.js index 4746821..9215114 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -65,21 +65,23 @@ function Main() this.start = function() { - this.database.start() - .then((db) => { - seer.note('process db'); - - this.resetPage(); - this.updateQuery(); + this.database.start(); + seer.note('process db'); + this.load(); + } - seer.note('prep query'); - return this.database.filter(db, this.queryCur); - }) - .then((filtered) => { - seer.note('filter db'); - return this.grid.buildAllArticles(filtered); - }) - .then((html) => { + this.load = function() + { + this.resetPage(); + this.updateQuery(); + seer.note('prep query'); + + let filtered = this.database.filter(this.queryCur); + seer.note('filter db'); + + this.grid.buildAllArticles(filtered) + .then((html) => + { seer.note('build html'); let stats = this.database.stats(); @@ -89,57 +91,10 @@ function Main() seer.note('render stats'); this.grid.newDisplay(html); - // seer.note('render html'); - seer.report(); - - document.querySelector('.loading-wave').style.display = 'none'; - }) - .catch((error) => { - console.log('ERROR:', error); - }) - // this.load(window.document.location.hash); - // + }); + document.querySelector('.loading-wave').style.display = 'none'; } - - this.load = function() - { - - } - -// this.load = function(target) -// { -// lightbox.close(); -// document.activeElement.blur(); -// if (this.queryCur !== 'add') -// { -// this.queryPrev = this.queryCur; -// } - -// target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target; -// this.queryCur = target.trim(); - -// if (window.location.hash != this.queryCur) -// { -// window.location.hash = this.queryCur; -// } - -// if (this.queryCur === 'add') -// { -// if (window.showAdd != undefined && window.showAdd) -// { -// this.add.show(); -// } -// else -// { -// window.location.hash = this.queryPrev; -// } -// } -// else -// { -// this.grid.display(this.db.filter(this.queryCur)); -// } -// } } -// window.addEventListener("hashchange", function() { main.load(window.document.location.hash); }); \ No newline at end of file +window.addEventListener("hashchange", function() { main.load(); }); \ No newline at end of file diff --git a/docs/logic/seer.js b/docs/logic/seer.js index 82e0e3e..73b6c90 100644 --- a/docs/logic/seer.js +++ b/docs/logic/seer.js @@ -3,6 +3,7 @@ function Seer() { this.verbose = false this.quota = 0; + this.limbo = false; this.timeBegin = null; this.timeRef = null; @@ -12,13 +13,24 @@ function Seer() { this.verbose = verbose; this.quota = quota; - this.timeBegin = Date.now(); + this.rebirth(); + } + + this.rebirth = function() + { + this.timeBegin = Date.now(); this.timeRef = Date.now(); this.book = []; + this.limbo = false; } this.note = function(desc) { + if (this.limbo) + { + this.rebirth(); + } + var entry = [desc, (Date.now() - this.timeRef)]; this.book.push(entry); if (this.verbose) @@ -44,5 +56,7 @@ function Seer() console.log(percentage + ' % of time spent on: ' + this.book[i][0]); } } + console.log('_____________________________'); + this.limbo = true; } } \ No newline at end of file diff --git a/docs/logic/wrap.js b/docs/logic/wrap.js index e9f5264..ef434ec 100644 --- a/docs/logic/wrap.js +++ b/docs/logic/wrap.js @@ -11,59 +11,26 @@ function Wrap() this.start = function() { - let data = this.database; - return new Promise(function(resolve, reject) + let keys = Object.keys(this.database); + for (let i = 0; i < keys.length; i++) { - let commaSplit = function(data) - { - if (data !== undefined) - { - var result = data.split(","); - for (var c = 0; c < result.length; c++) - { - result[c] = result[c].trim().toLowerCase(); - } - return result; - } - return data; - } + let entry = this.database[keys[i]]; - let objectSplit = function(data) - { - if (typeof data == 'object') - { - for (let o = 0; o < data.length; o++) - { - if (data[o].substr(0,2) == '> ') - { - data[o] = data[o].substr(2,data[o].length-1); - } - } - } - return data; - } + entry.AUTH = commaSplit(entry.AUTH); + entry.TAGS = commaSplit(entry.TAGS); + entry.TYPE = commaSplit(entry.TYPE); + entry.PROJ = commaSplit(entry.PROJ); - let keys = Object.keys(data); - for (let i = 0; i < keys.length; i++) - { - let entry = data[keys[i]]; + entry.LINK = objectSplit(entry.LINK); + entry.FILE = objectSplit(entry.FILE); - entry.AUTH = commaSplit(entry.AUTH); - entry.TAGS = commaSplit(entry.TAGS); - entry.TYPE = commaSplit(entry.TYPE); - entry.PROJ = commaSplit(entry.PROJ); - - entry.LINK = objectSplit(entry.LINK); - entry.FILE = objectSplit(entry.FILE); - - data[keys[i]].DIID = i; - } - resolve(data); - }); + this.database[keys[i]].DIID = i; + } } - this.filter = function(db, target) + this.filter = function(target, data) { + let db = this.database;//data == undefined ? this.database : data; let tempDatabase = {}; if (target == '') { @@ -192,6 +159,35 @@ function Wrap() return tempDatabase; } + let commaSplit = function(data) + { + if (data !== undefined) + { + var result = data.split(","); + for (var c = 0; c < result.length; c++) + { + result[c] = result[c].trim().toLowerCase(); + } + return result; + } + return data; + } + + let objectSplit = function(data) + { + if (typeof data == 'object') + { + for (let o = 0; o < data.length; o++) + { + if (data[o].substr(0,2) == '> ') + { + data[o] = data[o].substr(2,data[o].length-1); + } + } + } + return data; + } + this.stats = function(db = this.database) { // CALCULATE