2016-11-23 18:32:49 +00:00
|
|
|
import webpackHotMiddlewareClient from 'webpack-hot-middleware/client?overlay=false&reload=true'
|
2016-12-19 14:40:26 +00:00
|
|
|
import Router from '../lib/router'
|
2016-11-23 18:32:49 +00:00
|
|
|
|
|
|
|
const handlers = {
|
|
|
|
reload (route) {
|
|
|
|
if (route === '/_error') {
|
2016-12-19 14:40:26 +00:00
|
|
|
for (const r of Object.keys(Router.components)) {
|
|
|
|
const { Component } = Router.components[r]
|
2016-11-23 18:32:49 +00:00
|
|
|
if (Component.__route === '/_error-debug') {
|
|
|
|
// reload all '/_error-debug'
|
|
|
|
// which are expected to be errors of '/_error' routes
|
2016-12-19 14:40:26 +00:00
|
|
|
Router.reload(r)
|
2016-11-23 18:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-19 14:40:26 +00:00
|
|
|
Router.reload(route)
|
2016-11-24 14:03:16 +00:00
|
|
|
},
|
|
|
|
change (route) {
|
2016-12-19 14:40:26 +00:00
|
|
|
const { Component } = Router.components[route] || {}
|
2016-11-24 14:03:16 +00:00
|
|
|
if (Component && Component.__route === '/_error-debug') {
|
|
|
|
// reload to recover from runtime errors
|
2016-12-19 14:40:26 +00:00
|
|
|
Router.reload(route)
|
2016-11-24 14:03:16 +00:00
|
|
|
}
|
2016-12-16 18:42:40 +00:00
|
|
|
},
|
|
|
|
hardReload () {
|
|
|
|
window.location.reload()
|
2016-11-23 18:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
webpackHotMiddlewareClient.subscribe((obj) => {
|
|
|
|
const fn = handlers[obj.action]
|
|
|
|
if (fn) {
|
|
|
|
const data = obj.data || []
|
|
|
|
fn(...data)
|
|
|
|
} else {
|
|
|
|
throw new Error('Unexpected action ' + obj.action)
|
|
|
|
}
|
|
|
|
})
|