hotwire-spark 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/hotwire_spark.js +26 -4
- data/app/assets/javascripts/hotwire_spark.min.js +1 -1
- data/app/assets/javascripts/hotwire_spark.min.js.map +1 -1
- data/app/javascript/hotwire/spark/reloaders/stimulus_reloader.js +33 -4
- data/lib/hotwire/spark/version.rb +1 -1
- metadata +1 -1
@@ -18,18 +18,26 @@ export class StimulusReloader {
|
|
18
18
|
log("Reload Stimulus controllers...")
|
19
19
|
|
20
20
|
this.application.stop()
|
21
|
-
|
21
|
+
|
22
|
+
await this.#reloadChangedStimulusControllers()
|
23
|
+
this.#unloadDeletedStimulusControllers()
|
24
|
+
|
22
25
|
this.application.start()
|
23
26
|
}
|
24
27
|
|
25
|
-
async #
|
28
|
+
async #reloadChangedStimulusControllers() {
|
26
29
|
await Promise.all(
|
27
|
-
this.#
|
30
|
+
this.#stimulusControllerPathsToReload.map(async moduleName => this.#reloadStimulusController(moduleName))
|
28
31
|
)
|
29
32
|
}
|
30
33
|
|
34
|
+
get #stimulusControllerPathsToReload() {
|
35
|
+
this.controllerPathsToReload = this.controllerPathsToReload || this.#stimulusControllerPaths.filter(path => this.#shouldReloadController(path))
|
36
|
+
return this.controllerPathsToReload
|
37
|
+
}
|
38
|
+
|
31
39
|
get #stimulusControllerPaths() {
|
32
|
-
return Object.keys(this.#stimulusPathsByModule).filter(path => path.endsWith("_controller")
|
40
|
+
return Object.keys(this.#stimulusPathsByModule).filter(path => path.endsWith("_controller"))
|
33
41
|
}
|
34
42
|
|
35
43
|
#shouldReloadController(path) {
|
@@ -57,6 +65,22 @@ export class StimulusReloader {
|
|
57
65
|
this.#registerController(controllerName, module)
|
58
66
|
}
|
59
67
|
|
68
|
+
#unloadDeletedStimulusControllers() {
|
69
|
+
this.#controllersToUnload.forEach(controller => this.#deregisterController(controller.identifier))
|
70
|
+
}
|
71
|
+
|
72
|
+
get #controllersToUnload() {
|
73
|
+
if (this.#didChangeTriggerAReload) {
|
74
|
+
return []
|
75
|
+
} else {
|
76
|
+
return this.application.controllers.filter(controller => this.filePattern.test(`${controller.identifier}_controller`))
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
get #didChangeTriggerAReload() {
|
81
|
+
return this.#stimulusControllerPathsToReload.length > 0
|
82
|
+
}
|
83
|
+
|
60
84
|
#pathForModuleName(moduleName) {
|
61
85
|
return this.#stimulusPathsByModule[moduleName]
|
62
86
|
}
|
@@ -73,4 +97,9 @@ export class StimulusReloader {
|
|
73
97
|
this.application.unload(name)
|
74
98
|
this.application.register(name, module.default)
|
75
99
|
}
|
100
|
+
|
101
|
+
#deregisterController(name) {
|
102
|
+
log(`\tRemoving controller ${name}`)
|
103
|
+
this.application.unload(name)
|
104
|
+
}
|
76
105
|
}
|