mirror of
https://github.com/TangentFoxy/memex.git
synced 2024-11-22 04:54:23 +00:00
Add promises to article building.
This commit is contained in:
parent
82a728f8ca
commit
eea38f4cc1
@ -4554,4 +4554,16 @@ JS MAP IS DICTIONARY?
|
||||
- It's optimized for adding items to and removing items from the map.
|
||||
- The keys can by any type, not just strings.
|
||||
- You can't pollute it with custom methods.
|
||||
|
||||
JS REDUCE
|
||||
NOTE
|
||||
> "Whenever you need to transform a list into a single object, consider using reduce"
|
||||
|
||||
CSS LINK IN BODY
|
||||
LINK
|
||||
> https://stackoverflow.com/questions/6236097/is-link-not-rel-stylesheet-allowed-to-be-used-in-body
|
||||
> https://github.com/whatwg/html/commit/179983e9eb99efe417349a40ebb664bd11668ddd
|
||||
> http://w3c.github.io/html/document-metadata.html#the-link-element
|
||||
TAGS : code, web
|
||||
PROJ : Memex
|
||||
`
|
@ -11,6 +11,9 @@ function Main()
|
||||
this.queryPrev = '';
|
||||
this.queryPrevAdd = '';
|
||||
|
||||
this.timeStore = Date.now();
|
||||
this.curTime = null;
|
||||
|
||||
var parent = this;
|
||||
|
||||
this.install = function()
|
||||
@ -39,35 +42,25 @@ function Main()
|
||||
}
|
||||
}
|
||||
|
||||
this.start = function()
|
||||
this.timediff = function(label)
|
||||
{
|
||||
console.log(Date.now() + ' - start');
|
||||
let dbPromise = this.database.start(new Indental(DATABASE).parse());
|
||||
dbPromise.then((db) => {
|
||||
console.log(Date.now() + ' - db ready');
|
||||
// console.log(db);
|
||||
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
let dbKeys = Object.keys(db);
|
||||
let i = 0;
|
||||
|
||||
console.log(Date.now() + ' - start render');
|
||||
|
||||
while (i < 200)//dbKeys.length)
|
||||
{
|
||||
document.querySelector('main').innerHTML += this.grid.buildArticle(db[dbKeys[i]], dbKeys[i]);
|
||||
console.log(Date.now() + ' - did one! LAAAAAAG while reflowing');
|
||||
i++;
|
||||
this.curTime = Date.now();
|
||||
console.log((this.curTime - this.timeStore) + ' ms to ' + label);
|
||||
this.timeStore = this.curTime;
|
||||
}
|
||||
|
||||
console.log('COMPLETED ALL ARTICLES - lag stops')
|
||||
return 'done';
|
||||
}, 2000);
|
||||
|
||||
|
||||
|
||||
this.start = function()
|
||||
{
|
||||
this.timediff('call start');
|
||||
this.database.start(new Indental(DATABASE).parse())
|
||||
.then((db) => {
|
||||
this.timediff('process db');
|
||||
return this.grid.buildAllArticles(db);
|
||||
})
|
||||
.then((html) => {
|
||||
this.timediff('build html');
|
||||
document.querySelector('main').innerHTML = html;
|
||||
this.timediff('render html');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('ERROR:', error);
|
||||
|
@ -75,6 +75,10 @@ function Grid()
|
||||
}
|
||||
}
|
||||
|
||||
this.buildAllArticles = function(db)
|
||||
{
|
||||
return new Promise(function(resolve, reject)
|
||||
{
|
||||
this.buildArticle = function(value, key)
|
||||
{
|
||||
// let value = db[key];
|
||||
@ -421,4 +425,16 @@ function Grid()
|
||||
lightbox.load(`content/media/${file}`);
|
||||
}
|
||||
}
|
||||
|
||||
let dbKeys = Object.keys(db);
|
||||
let i = 0;
|
||||
let html = '';
|
||||
while (i < dbKeys.length)
|
||||
{
|
||||
html += buildArticle(db[dbKeys[i]], dbKeys[i]);
|
||||
i++;
|
||||
}
|
||||
resolve(html);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user