-
Notifications
You must be signed in to change notification settings - Fork 111
/
hooks.js
41 lines (38 loc) · 1.13 KB
/
hooks.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
/**
* Created by Emmy on 10/11/2017.
*/
import Vue from 'vue'
import {setupVmWithLocalVue} from './initializers'
import Promise from 'promise-polyfill'
export function sanitizeAndPrepareWindow(done) {
Promise.resolve()
.then((function (){
return new Promise(function (resolve) {
// Clean up plugin
if (window.vm && window.vm.$dialog) {
window.vm.$dialog.destroy()
}
resolve()
})
}))
.then((function (){
return new Promise(function (resolve) {
// clean up app
if (window.vm) {
let elem = window.vm.$el
window.vm.$destroy()
window.vm.$off()
elem.remove()
delete window.vm
}
resolve()
})
})).then(() => {
// set them up again
window.vm = setupVmWithLocalVue()
// Proceed
Vue.nextTick(done)
}).catch((err) => {
done(new Error(err.toString()))
})
}