stimulus-rails 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13bb40c97c058db5c313a50333ac02b0fb13d1104e4bae6bc083d5c6e38856f7
4
- data.tar.gz: fd88cf490056444a5fbd16585c9bc6e9ec5a59826612e247ef4c1f30881bb555
3
+ metadata.gz: d9343efc3e70276ca902f488bd6e421abfc33bc7f5f4ae54510ed7fe5861793f
4
+ data.tar.gz: e8ee4935ceab92da342873ccce2ffce00688d9402e49fde1c7264223c98d54ea
5
5
  SHA512:
6
- metadata.gz: f94c4d0858fddb687869d9903e66a40c560d653240b8dfccc02f76b19a46bc3ec8d91855302bcba28667a29e4566678e1926d9022d67c0627f8dde3055bb48a3
7
- data.tar.gz: 699de52b3ce29cc8017079361e8f62d4e1fa87bdfaf7b28f8bc52893b75b15f50de15da83a5b1e0e62f9c926b2c5a658bbd6795a6cd12073305505482ddf016c
6
+ metadata.gz: b67fca17a76bead798c04fdd5ea95885340fd3b82be6b4356179356689573303dff7df2442e1360c5bb977b3ece7a0d5827b77a93f5ea07a53416a2499eab6a0
7
+ data.tar.gz: 2c6063aab10680a1064ab60a33394792508c2e4c19dd13d186b916045f37b873a1d9ce6a79c3ca17e0c7c1cebf650ac26db5ba61e4ecf4f90403ba902044d8c2
@@ -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
+ }