File tree Expand file tree Collapse file tree 5 files changed +17
-5
lines changed Expand file tree Collapse file tree 5 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 1- /* global __VERSION__ */
21var React = require ( 'react' )
32var Link = require ( 'react-router/lib/Link' )
43
@@ -19,10 +18,12 @@ var App = React.createClass({
1918 SettingsStore . load ( )
2019 StoryStore . loadSession ( )
2120 UpdatesStore . loadSession ( )
21+ if ( typeof window === 'undefined' ) return
2222 window . addEventListener ( 'beforeunload' , this . handleBeforeUnload )
2323 } ,
2424
2525 componentWillUnmount ( ) {
26+ if ( typeof window === 'undefined' ) return
2627 window . removeEventListener ( 'beforeunload' , this . handleBeforeUnload )
2728 } ,
2829
@@ -60,7 +61,6 @@ var App = React.createClass({
6061 { this . props . children }
6162 </ div >
6263 < div className = "App__footer" >
63- { `react-hn v${ __VERSION__ } | ` }
6464 < a href = "https://github.com/insin/react-hn" > insin/react-hn</ a >
6565 </ div >
6666 </ div >
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ class StoryStore extends EventEmitter {
9999 start ( ) {
100100 firebaseRef = HNService . storiesRef ( this . type )
101101 firebaseRef . on ( 'value' , this . onStoriesUpdated )
102+ if ( typeof window === 'undefined' ) return
102103 window . addEventListener ( 'storage' , this . onStorage )
103104 }
104105
@@ -107,6 +108,7 @@ class StoryStore extends EventEmitter {
107108 firebaseRef . off ( )
108109 firebaseRef = null
109110 }
111+ if ( typeof window === 'undefined' ) return
110112 window . removeEventListener ( 'storage' , this . onStorage )
111113 }
112114}
@@ -124,6 +126,7 @@ extend(StoryStore, {
124126 * Deserialise caches from sessionStorage.
125127 */
126128 loadSession ( ) {
129+ if ( typeof window === 'undefined' ) return
127130 idCache = parseJSON ( window . sessionStorage . idCache , { } )
128131 itemCache = parseJSON ( window . sessionStorage . itemCache , { } )
129132 } ,
@@ -132,6 +135,7 @@ extend(StoryStore, {
132135 * Serialise caches to sessionStorage as JSON.
133136 */
134137 saveSession ( ) {
138+ if ( typeof window === 'undefined' ) return
135139 window . sessionStorage . idCache = JSON . stringify ( idCache )
136140 window . sessionStorage . itemCache = JSON . stringify ( itemCache )
137141 }
Original file line number Diff line number Diff line change @@ -100,12 +100,14 @@ function handleUpdateItems(items) {
100100
101101var UpdatesStore = extend ( new EventEmitter ( ) , {
102102 loadSession ( ) {
103+ if ( typeof window === 'undefined' ) return
103104 var json = window . sessionStorage . updates
104105 updatesCache = ( json ? JSON . parse ( json ) : { comments : { } , stories : { } } )
105106 populateUpdates ( )
106107 } ,
107108
108109 saveSession ( ) {
110+ if ( typeof window === 'undefined' ) return
109111 window . sessionStorage . updates = JSON . stringify ( updatesCache )
110112 } ,
111113
Original file line number Diff line number Diff line change 11var { SITE_TITLE } = require ( './constants' )
22
33function setTitle ( title ) {
4+ if ( typeof document === 'undefined' ) return
45 document . title = ( title ? title + ' | ' + SITE_TITLE : SITE_TITLE )
56}
67
Original file line number Diff line number Diff line change 11module . exports = {
22 get ( key , defaultValue ) {
3- var value = window . localStorage [ key ]
4- return ( typeof value != 'undefined' ? value : defaultValue )
3+ if ( typeof window !== 'undefined' ) {
4+ var value = window . localStorage [ key ]
5+ return ( typeof value != 'undefined' ? value : defaultValue )
6+ }
57 } ,
68 set ( key , value ) {
7- window . localStorage [ key ] = value
9+ if ( typeof window !== 'undefined' ) {
10+ window . localStorage [ key ] = value
11+ }
812 }
913}
14+
You can’t perform that action at this time.
0 commit comments