Completed
Push — master ( e9cdde...e60414 )
by Ajeh
33s
created

hooks.js ➔ sanitizeAndPrepareWindow   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
dl 0
loc 33
rs 8.8571
nop 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A hooks.js ➔ ... ➔ ??? 0 6 1
A hooks.js ➔ ... ➔ Promise.then 0 9 1
1
/**
2
 * Created by Emmy on 10/11/2017.
3
 */
4
5
import Vue from 'vue'
6
import {setupVmWithLocalVue} from './initializers'
7
import Promise from 'promise-polyfill'
8
9
export function sanitizeAndPrepareWindow(done) {
10
    Promise.resolve()
11
        .then((function (){
12
            return new Promise(function (resolve) {
13
                // Clean up plugin
14
                if (window.vm && window.vm.$dialog) {
15
                    window.vm.$dialog.destroy()
16
                }
17
                resolve()
18
            })
19
        }))
20
        .then((function (){
21
            return new Promise(function (resolve) {
22
                // clean up app
23
                if (window.vm) {
24
                    let elem = window.vm.$el
25
                    window.vm.$destroy()
26
                    window.vm.$off()
27
                    elem.remove()
28
                    delete window.vm
29
                }
30
                resolve()
31
            })
32
        })).then(() => {
33
            // set them up again
34
            window.vm = setupVmWithLocalVue()
35
            // Proceed
36
            Vue.nextTick(done)
37
        }).catch((err) => {
38
            done(new Error(err.toString()))
39
        })
40
41
}
42