-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.js
37 lines (32 loc) · 1.05 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require('babel/polyfill')
var React = require('react')
var Router = require('react-router')
var injectTapEventPlugin = require('react-tap-event-plugin')
var FingerBlast = require('fingerblast/dist/fingerblast.umd')
var isDesktop = require('./util/is-desktop')
var routes = require('./components/routes')
var stores = {
TopStory: require('./stores/top-story'),
Story: require('./stores/story'),
}
React.initializeTouchEvents(true)
injectTapEventPlugin()
document.addEventListener('DOMContentLoaded', (e) => {
if (isDesktop()) {
new FingerBlast(document.body) // simulate touch events from mouse
}
// bootstrap stores with initial data
if (window.HackerNewsInitialData) {
var initialData = window.HackerNewsInitialData
Object.keys(initialData).forEach((storeName) => {
if (stores[storeName]) {
stores[storeName].reset(initialData[storeName])
} else {
console.warn('unknown store '+storeName)
}
})
}
Router.run(routes, Router.HistoryLocation, (Handler) => {
React.render(<Handler />, document.body)
})
})