Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update branch to reflect master
  • Loading branch information
addyosmani committed May 18, 2016
commit d7f6c5205e7fdfc78a8753b63bc50dd1e2876902
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"url": "http://github.com/insin/react-hn.git"
},
"scripts": {
"build": "npm run lint && cp node_modules/sw-toolbox/sw-toolbox.js public/sw-toolbox.js && ./node_modules/nwb/lib/bin/nwb.js build && npm run precache",
"build": "npm run lint && cp node_modules/sw-toolbox/sw-toolbox.js public/sw-toolbox.js && ./node_modules/.bin/nwb build && npm run precache",
"deploy": "gcloud preview app deploy",
"lint": "./node_modules/eslint-config-jonnybuchanan/bin/lint.js src",
"lint:fix": "./node_modules/eslint-config-jonnybuchanan/bin/lint.js --fix .",
"start": "node server.js",
"postinstall": "npm run build",
"serve": "./node_modules/lib/bin/nwb.js serve",
"serve": "./node_modules/.bin/nwb serve",
"precache": "./node_modules/sw-precache/cli.js --root=public --config=sw-precache-config.json"
},
"engines": {
Expand Down
33 changes: 27 additions & 6 deletions src/stores/StoryStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,18 @@ class StoryStore extends EventEmitter {
}

start() {
firebaseRef = HNService.storiesRef(this.type)
firebaseRef.on('value', this.onStoriesUpdated)
if (typeof window === 'undefined') return
if (SettingsStore.offlineMode) {
HNServiceRest.storiesRef(this.type).then(function(res) {
return res.json()
}).then(function(snapshot) {
this.onStoriesUpdated(snapshot)
}.bind(this))
}
else {
firebaseRef = HNService.storiesRef(this.type)
firebaseRef.on('value', this.onStoriesUpdated)
}
window.addEventListener('storage', this.onStorage)
}

Expand Down Expand Up @@ -136,17 +145,29 @@ extend(StoryStore, {
*/
loadSession() {
if (typeof window === 'undefined') return
idCache = parseJSON(window.sessionStorage.idCache, {})
itemCache = parseJSON(window.sessionStorage.itemCache, {})
if (SettingsStore.offlineMode) {
idCache = parseJSON(window.localStorage.idCache, {})
itemCache = parseJSON(window.localStorage.itemCache, {})
}
else {
idCache = parseJSON(window.sessionStorage.idCache, {})
itemCache = parseJSON(window.sessionStorage.itemCache, {})
}
},

/**
* Serialise caches to sessionStorage as JSON.
*/
saveSession() {
if (typeof window === 'undefined') return
window.sessionStorage.idCache = JSON.stringify(idCache)
window.sessionStorage.itemCache = JSON.stringify(itemCache)
if (SettingsStore.offlineMode) {
window.localStorage.setItem('idCache', JSON.stringify(idCache))
window.localStorage.setItem('itemCache', JSON.stringify(itemCache))
}
else {
window.sessionStorage.idCache = JSON.stringify(idCache)
window.sessionStorage.itemCache = JSON.stringify(itemCache)
}
}
})

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.