Skip to content

Commit

Permalink
refact: Loading sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitz committed Dec 15, 2017
1 parent 0a65ad0 commit c93f351
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const init = (url = window.location.origin) => state => async actions => {
if (state.isBeaker) {
await medium.init(url)
await medium.loadStyle()
const articles = await medium.preloadArticles()
const { title, ...info } = await medium.loadInfo()
const articles = await medium.preloadArticles()
actions.update({ articles, info, title })
}
actions.update({ isLoading: false })
Expand Down
4 changes: 1 addition & 3 deletions app/lib/medium.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ class Medium {
}

async preloadArticles () {
debug('Pre-loading articles...')
const files = await this.dat.readdir('/articles', { recursive: true, stat: true })
const articles = await Promise.all(files.filter(isMarkdown).map(file => this.loadArticle(file)))
return articles.sort(byDate)
}

async loadInfo () {
debug('Loading info...')
const info = await this.dat.getInfo()
const blog = await this.dat.readFile('/blog.json')
.then(
config => JSON.parse(config),
() => { console.error('/blog.json not found') }
)
blog.author = renderInline(blog.author)
blog.author = blog.author && renderInline(blog.author)
info.description = renderInline(info.description)
debug('Info loaded:', { ...info, ...blog })
return { ...info, ...blog }
Expand Down

0 comments on commit c93f351

Please sign in to comment.