Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 1.46 KB

README.md

File metadata and controls

58 lines (42 loc) · 1.46 KB

README

Following Rails concerns convention, this package provides a set of Concerns to be used in stimulus controllers.

Usage

Import the concern you want to use in your controller and call it in the initialize method.

CDN

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

Example (Importmap)

# 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);
  }

  // ...
}

Example (wout Importmap nor Webpacker)

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);
  }

  // ...
}

Example (using Webpacker)

  • TODO: Add webpacker example. (import {} from "..." doesn't work)