Skip to content

Commit

Permalink
feat(site): don't load if data is already available
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Wensink committed Oct 13, 2017
1 parent b6ffa6e commit 8a090b2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Site.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { polyfill } from 'es6-promise';
import { polyfill, Promise } from 'es6-promise';
import 'isomorphic-fetch';
import * as deepmerge from 'deepmerge';
import * as getNested from 'get-nested';
Expand Down Expand Up @@ -78,6 +78,13 @@ class Site {
}

public getPage(path, loadFromServer = false): Promise<void> {
if (!this.pagesLoading[ path ]) {
const dataMaybeAlreadyLoaded = getNested(() => this.data.data[this.data.paths[path]]);
if (getNested(() => dataMaybeAlreadyLoaded.__hn.view_modes.includes('default'))) {
this.pagesLoading[ path ] = Promise.resolve(this.data.paths[ path ]);
}
}

if (loadFromServer === true || !this.pagesLoading[ path ]) {

// Copy this.tokensToVerify for this single request.
Expand Down

0 comments on commit 8a090b2

Please sign in to comment.