stimulus-rails 1.2.1 → 1.3.4
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 -3
- data/app/assets/javascripts/stimulus-loading.js +7 -5
- data/app/assets/javascripts/stimulus.js +266 -111
- data/app/assets/javascripts/stimulus.min.js +1 -1
- data/app/assets/javascripts/stimulus.min.js.map +1 -1
- data/lib/generators/stimulus/stimulus_generator.rb +3 -1
- data/lib/install/app/javascript/controllers/index_for_importmap.js +1 -8
- data/lib/install/stimulus_with_bun.rb +18 -0
- data/lib/install/stimulus_with_importmap.rb +4 -4
- data/lib/install/stimulus_with_node.rb +5 -1
- data/lib/stimulus/manifest.rb +4 -2
- data/lib/stimulus/version.rb +1 -1
- data/lib/tasks/stimulus_tasks.rake +23 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73388b59b0405975a85b9e2c627167413e4fba70f6192dd2a2a0f9db32316144
|
4
|
+
data.tar.gz: 6cc20dd48030fe78738eca4b0416d0fcd6519ec4e3899ed7fe1e1e033e5c09c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cd0e5e11da726dd240e6edd651549bc7a84c320576470f9526728c960fb1769c12addcd76643abbc079c7d6683a2a1faa16f864e5b9bf139de7255971513bbc
|
7
|
+
data.tar.gz: 69146705608c0958eaf9950a12061000c604bd9962e58761ce65b554132d0e6147805ba846afadc731a932e4c8b41d76188254d70974c20d13c8924d3e649efe
|
data/README.md
CHANGED
@@ -57,8 +57,8 @@ import "controllers"
|
|
57
57
|
|
58
58
|
6. Finally, Pin Stimulus and controllers in `config/importmap.rb` by adding:
|
59
59
|
```ruby
|
60
|
-
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
61
|
-
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
60
|
+
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
61
|
+
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
62
62
|
pin_all_from "app/javascript/controllers", under: "controllers"
|
63
63
|
|
64
64
|
```
|
@@ -94,7 +94,7 @@ export { application }
|
|
94
94
|
|
95
95
|
5. Add the following line to `app/javascript/application.js` to import all your controllers:
|
96
96
|
```javascript
|
97
|
-
import "controllers"
|
97
|
+
import "./controllers"
|
98
98
|
```
|
99
99
|
|
100
100
|
6. Finally, add the Stimulus package to yarn:
|
@@ -2,7 +2,6 @@
|
|
2
2
|
import "@hotwired/stimulus"
|
3
3
|
|
4
4
|
const controllerAttribute = "data-controller"
|
5
|
-
const registeredControllers = {}
|
6
5
|
|
7
6
|
// Eager load all controllers registered beneath the `under` path in the import map to the passed application instance.
|
8
7
|
export function eagerLoadControllersFrom(under, application) {
|
@@ -21,7 +20,7 @@ function registerControllerFromPath(path, under, application) {
|
|
21
20
|
.replace(/\//g, "--")
|
22
21
|
.replace(/_/g, "-")
|
23
22
|
|
24
|
-
if (
|
23
|
+
if (canRegisterController(name, application)) {
|
25
24
|
import(path)
|
26
25
|
.then(module => registerController(name, module, application))
|
27
26
|
.catch(error => console.error(`Failed to register controller: ${name} (${path})`, error))
|
@@ -66,7 +65,7 @@ function extractControllerNamesFrom(element) {
|
|
66
65
|
}
|
67
66
|
|
68
67
|
function loadController(name, under, application) {
|
69
|
-
if (
|
68
|
+
if (canRegisterController(name, application)) {
|
70
69
|
import(controllerFilename(name, under))
|
71
70
|
.then(module => registerController(name, module, application))
|
72
71
|
.catch(error => console.error(`Failed to autoload controller: ${name}`, error))
|
@@ -78,8 +77,11 @@ function controllerFilename(name, under) {
|
|
78
77
|
}
|
79
78
|
|
80
79
|
function registerController(name, module, application) {
|
81
|
-
if (
|
80
|
+
if (canRegisterController(name, application)) {
|
82
81
|
application.register(name, module.default)
|
83
|
-
registeredControllers[name] = true
|
84
82
|
}
|
85
83
|
}
|
84
|
+
|
85
|
+
function canRegisterController(name, application){
|
86
|
+
return !application.router.modulesByIdentifier.has(name)
|
87
|
+
}
|