Refactor clean up new promise setup.

This commit is contained in:
kor 2018-11-06 22:28:12 +13:00
parent 36e2dca38c
commit 19125d1bc4
3 changed files with 29 additions and 35 deletions

View File

@ -21,7 +21,7 @@ function Main()
{ {
this.util = new Util(); this.util = new Util();
this.database = new Wrap(); this.database = new Wrap();
// this.database.install(DATABASE); this.database.install(DATABASE);
this.grid = new Grid(); this.grid = new Grid();
this.grid.install( this.grid.install(
document.querySelector('main'), document.querySelector('main'),
@ -50,28 +50,36 @@ function Main()
this.timeStore = this.curTime; this.timeStore = this.curTime;
} }
this.start = function() this.resetPage = function()
{ {
this.timediff('load all js files');
this.database.start(new Indental(DATABASE).parse())
.then((db) => {
this.timediff('process db');
let target = window.document.location.hash;
lightbox.close(); lightbox.close();
document.activeElement.blur(); document.activeElement.blur();
}
this.updateQuery = function()
{
let target = window.document.location.hash;
if (this.queryCur !== 'add') if (this.queryCur !== 'add')
{ {
this.queryPrev = this.queryCur; this.queryPrev = this.queryCur;
} }
target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target; target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
this.queryCur = target.trim(); this.queryCur = target.trim();
if (window.location.hash != this.queryCur) if (window.location.hash != this.queryCur)
{ {
window.location.hash = this.queryCur; window.location.hash = this.queryCur;
} }
}
this.start = function()
{
this.timediff('load all js files');
this.database.start()
.then((db) => {
this.timediff('process db');
this.resetPage();
this.updateQuery();
this.timediff('prep query \'' + this.queryCur + '\''); this.timediff('prep query \'' + this.queryCur + '\'');
return this.database.filter(db, this.queryCur); return this.database.filter(db, this.queryCur);

View File

@ -9,8 +9,9 @@ function Wrap()
this.keys = Object.keys(this.database); this.keys = Object.keys(this.database);
} }
this.start = function(data) this.start = function()
{ {
let data = this.database;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
let commaSplit = function(data) let commaSplit = function(data)
@ -188,7 +189,6 @@ function Wrap()
} }
} }
} }
return tempDatabase; return tempDatabase;
} }
@ -289,18 +289,4 @@ function Wrap()
return stats; return stats;
} }
this.commaSplit = function(data)
{
if (data !== undefined)
{
var result = data.split(",");
for (var t = 0; t < result.length; t++)
{
result[t] = result[t].trim().toLowerCase();
}
return result;
}
return data;
}
} }