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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13bb40c97c058db5c313a50333ac02b0fb13d1104e4bae6bc083d5c6e38856f7
4
- data.tar.gz: fd88cf490056444a5fbd16585c9bc6e9ec5a59826612e247ef4c1f30881bb555
3
+ metadata.gz: 73388b59b0405975a85b9e2c627167413e4fba70f6192dd2a2a0f9db32316144
4
+ data.tar.gz: 6cc20dd48030fe78738eca4b0416d0fcd6519ec4e3899ed7fe1e1e033e5c09c3
5
5
  SHA512:
6
- metadata.gz: f94c4d0858fddb687869d9903e66a40c560d653240b8dfccc02f76b19a46bc3ec8d91855302bcba28667a29e4566678e1926d9022d67c0627f8dde3055bb48a3
7
- data.tar.gz: 699de52b3ce29cc8017079361e8f62d4e1fa87bdfaf7b28f8bc52893b75b15f50de15da83a5b1e0e62f9c926b2c5a658bbd6795a6cd12073305505482ddf016c
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", preload: true
61
- pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
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 (!(name in registeredControllers)) {
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 (!(name in registeredControllers)) {
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 (!(name in registeredControllers)) {
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
+ }