Following Rails concerns convention, this package provides a set of Concerns to be used in stimulus controllers.
Import the concern you want to use in your controller and call it in the initialize method.
You can use jsdelivr cdn to import the concern.
Url format is https://cdn.jsdelivr.net/gh/dwaynemac/stimulus-concerns/src/<concern>.js
See: https://www.jsdelivr.com/?docs=gh
# config/importmap.rb
pin "@dwaynemac/loggable", to: "https://cdn.jsdelivr.net/gh/dwaynemac/[email protected]/src/loggable.min.js"
pin "@dwaynemac/showHide", to: "https://cdn.jsdelivr.net/gh/dwaynemac/stimulus-concerns/src/showHide.min.js"
import { Controller } from '@hotwire/stimulus'
import { Loggable } from "@dwaynemac/loggable"
import { ShowHide } from "@dwaynemac/showHide"
export default class extends Controller {
initialize() {
Loggable(this);
ShowHide(this);
}
// ...
}
import { Controller } from '@hotwire/stimulus';
import { Loggable } from 'https://cdn.jsdelivr.net/gh/dwaynemac/[email protected]/src/loggable.min.js';
import { ShowHide } from 'https://cdn.jsdelivr.net/gh/dwaynemac/[email protected]/src/showHide.min.js';
export default class extends Controller {
initialize() {
Loggable(this);
ShowHide(this);
}
// ...
}
- TODO: Add webpacker example. (import {} from "..." doesn't work)