-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathruntime.js
More file actions
74 lines (69 loc) · 2.01 KB
/
runtime.js
File metadata and controls
74 lines (69 loc) · 2.01 KB
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
74
import element from '../shared/element'
import fragment from '../shared/fragment'
import invoke from './invoke'
import context from './context'
import windowEvent from './windowEvent'
import client from './client'
import lazy from './lazy'
const $runtime = {
element,
fragment,
invoke,
lazy
}
if (module.hot) {
$runtime.dependencies = new Map()
$runtime.accept = function accept(target, file, dependencies, declarations) {
if (declarations.length > 0) {
target.hot.accept()
}
let initiateQueue = []
const old = $runtime.dependencies.get(file)
if (old) {
if (old.length !== dependencies.length) {
return window.location.reload()
}
for (const index in old) {
if (old[index] !== dependencies[index]) {
return window.location.reload()
}
}
}
$runtime.dependencies.set(file, dependencies)
if (client.skipHotReplacement) {
return window.location.reload()
}
for (const declaration of declarations) {
let oldConstructor
for (const key in context.instances) {
const instance = context.instances[key]
if (instance.constructor.hash === declaration.klass.hash) {
oldConstructor = instance.constructor
Object.setPrototypeOf(instance, declaration.klass.prototype)
if (oldConstructor.__hashes !== undefined) {
for (const dep of declaration.initiate) {
if (oldConstructor.__hashes[dep] !== declaration.hashes[dep]) {
initiateQueue.push(instance)
break
}
}
}
}
}
client.klasses[declaration.klass.hash] = declaration.klass
declaration.klass.__hashes = declaration.hashes
}
windowEvent('environment')
for (const instance of initiateQueue) {
instance.initiate()
}
client.update()
}
}
$runtime.restart = function restart(target, path) {
target.hot.accept()
target.hot.accept(path, () => {
window.location.reload()
})
}
export default $runtime