-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
73 lines (62 loc) · 1.57 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'babel-polyfill'
// Hot Module Reload patch
import { module } from '@hot'
// import { AppContainer } from 'react-hot-loader'
// Global CSS
import './index.css'
// Libraries
import EventEmitter from 'eventemitter3'
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import fs, {fsReady} from 'fs'
// Application code
import App from './components/App.js'
import { store } from './components/store.js'
console.log('STORE =', store)
// Global variables
window.React = React
window.ReactDOM = ReactDOM
let EventHub = new EventEmitter()
window.EventHub = EventHub
// Hot reload case
if (module) {
console.log('Hot Module! =', module.savedState)
} else {
}
fsReady.then(() => {
ReactDOM.render(
<Provider store={store}>
<App/>
</Provider>,
document.getElementById('app')
)
})
export let savedState = null
export const __unload = () => {
// saving state
console.log('Saving state...')
console.log('Teardown...')
// Unsubscribe from filesystem events
fs.Events.off('change', onChange)
}
// Listen for files that we need to hot-reload when saved.
let base
System.resolve('/').then(here => {
base = here
console.log('BASE =', base)
})
const onChange = ({filename}) => {
// Hack to work around the extra '/' everywhere.
let file = new URL(base)
file.pathname = filename
file = file.href
console.log(file + ' file changed')
if (file in System.loads) {
console.log('Reloading!')
System.reload(file).then(() => {
fs.Events.emit('reload', filename)
})
}
}
fs.Events.on('change', onChange)