hotwire-spark 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/app/assets/javascripts/hotwire_spark.js +32 -6
- 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/helpers.js +1 -1
- data/app/javascript/hotwire/spark/reloaders/stimulus_reloader.js +34 -5
- data/lib/hotwire/spark/engine.rb +1 -1
- data/lib/hotwire/spark/file_watcher.rb +5 -1
- data/lib/hotwire/spark/version.rb +1 -1
- data/lib/hotwire-spark.rb +1 -0
- metadata +2 -2
@@ -20,7 +20,7 @@ export function cacheBustedUrl(urlString) {
|
|
20
20
|
|
21
21
|
export async function reloadHtmlDocument() {
|
22
22
|
let currentUrl = cacheBustedUrl(urlWithParams(window.location.href, { hotwire_spark: "true" }))
|
23
|
-
const response = await fetch(currentUrl)
|
23
|
+
const response = await fetch(currentUrl, { headers: { "Accept": "text/html" }})
|
24
24
|
|
25
25
|
if (!response.ok) {
|
26
26
|
throw new Error(`${response.status} when fetching ${currentUrl}`)
|
@@ -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
|
}
|
@@ -70,7 +94,12 @@ export class StimulusReloader {
|
|
70
94
|
}
|
71
95
|
|
72
96
|
#registerController(name, module) {
|
73
|
-
this
|
97
|
+
this.#deregisterController(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
|
}
|
data/lib/hotwire/spark/engine.rb
CHANGED
@@ -7,7 +7,7 @@ module Hotwire::Spark
|
|
7
7
|
config.hotwire = ActiveSupport::OrderedOptions.new unless config.respond_to?(:hotwire)
|
8
8
|
config.hotwire.spark = ActiveSupport::OrderedOptions.new
|
9
9
|
config.hotwire.spark.merge! \
|
10
|
-
enabled: Rails.env.development
|
10
|
+
enabled: Rails.env.development? && defined?(Rails::Server),
|
11
11
|
css_paths: File.directory?("app/assets/builds") ? %w[ app/assets/builds ] : %w[ app/assets/stylesheets ],
|
12
12
|
html_paths: %w[ app/controllers app/helpers app/models app/views ],
|
13
13
|
stimulus_paths: %w[ app/javascript/controllers ]
|
@@ -25,7 +25,11 @@ class Hotwire::Spark::FileWatcher
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def paths
|
28
|
-
@callbacks_by_path.keys
|
28
|
+
only_existing_paths @callbacks_by_path.keys
|
29
|
+
end
|
30
|
+
|
31
|
+
def only_existing_paths(paths)
|
32
|
+
paths.select(&:exist?)
|
29
33
|
end
|
30
34
|
|
31
35
|
def process_changed_files(changed_files)
|
data/lib/hotwire-spark.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotwire-spark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jorge Manrubia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|