stimulus-rails 1.2.0 → 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: c9fcc874403d400e09caccf0cb74453d4462f3f100fb9d71913bcc8b9fcdaf2d
4
- data.tar.gz: 7dc309c4bec71820adf8b4c542bc7e9ee26833fcf91845f9d3c244a2e822ca0d
3
+ metadata.gz: d9343efc3e70276ca902f488bd6e421abfc33bc7f5f4ae54510ed7fe5861793f
4
+ data.tar.gz: e8ee4935ceab92da342873ccce2ffce00688d9402e49fde1c7264223c98d54ea
5
5
  SHA512:
6
- metadata.gz: e4cd684e10199d5c5c8f6f78eaef5c0d59c192a759a173c3987874f6e50dd76060af1ea632680ab7c33338f2e1bc66be19393237f031892fd5b17000e4b37f23
7
- data.tar.gz: cf1f1bc5f42d7fcef7e373771e68378c1ffecb1b0aa8a4bfe5ed958a31109f325655202342d48cce3f3fa16b2be596a8fd51ffdebf9fc7a93d316bd774a1d358
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
+ }