Sha256: b6dbaaf1daf8433ad1fa1395a3243f19322e2ec1b2217bf0008b0e1ac400ef1f

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

// FIXME: es-module-shim won't shim the dynamic import without this explicit import
import "@hotwired/stimulus"

export function registerControllersFrom(under, importmap, application) {
  const paths = Object.keys(importmap)
    .filter(path => path.match(new RegExp(`^${under}/.*_controller$`)))

  paths.forEach(path => registerControllerFromPath(path, under, application))
}

function registerControllerFromPath(path, under, application) {
  const name = path
    .replace(`${under}/`, "")
    .replace("_controller", "")
    .replace(/\//g, "--")
    .replace(/_/g, "-")

  import(path)
    .then(module => application.register(name, module.default))
    .catch(error => console.log(`Failed to register controller: ${name} (${path})`, error))
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stimulus-rails-0.4.1 app/assets/javascripts/stimulus-importmap-autoloader.js
stimulus-rails-0.4.0 app/assets/javascripts/stimulus-importmap-autoloader.js