mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Add StimulusJS and example controller
This commit is contained in:
18
app/webpacker/controllers/example_controller.js
Normal file
18
app/webpacker/controllers/example_controller.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// This is what a basic Stimulus Controller looks like. To apply it to an element you can do:
|
||||
// div{"data-controller": "example"}
|
||||
// or:
|
||||
// div{data: {controller: "example"}}
|
||||
|
||||
import { Controller } from "stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
// connect() is a built-in lifecycle callback for Stimulus Controllers. It fires when the
|
||||
// element is loaded on the page, and that also *includes* when some HTML is asynchronously
|
||||
// injected into the DOM. This means initialization is not tied to the page load event, but
|
||||
// will also happen dynamically if and when new DOM elements are added or removed.
|
||||
connect() {
|
||||
console.log("We're connected!")
|
||||
}
|
||||
}
|
||||
|
||||
// For more info take a look at https://stimulus.hotwired.dev/handbook/introduction
|
||||
Reference in New Issue
Block a user