mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Add StimulusReflex
This commit is contained in:
65
app/webpacker/controllers/application_controller.js
Normal file
65
app/webpacker/controllers/application_controller.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Controller } from "@hotwired/stimulus";
|
||||
import StimulusReflex from "stimulus_reflex";
|
||||
|
||||
/* This is your ApplicationController.
|
||||
* All StimulusReflex controllers should inherit from this class.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* import ApplicationController from './application_controller'
|
||||
*
|
||||
* export default class extends ApplicationController { ... }
|
||||
*
|
||||
* Learn more at: https://docs.stimulusreflex.com
|
||||
*/
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
StimulusReflex.register(this);
|
||||
}
|
||||
|
||||
/* Application-wide lifecycle methods
|
||||
*
|
||||
* Use these methods to handle lifecycle concerns for the entire application.
|
||||
* Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
|
||||
*
|
||||
* Arguments:
|
||||
*
|
||||
* element - the element that triggered the reflex
|
||||
* may be different than the Stimulus controller's this.element
|
||||
*
|
||||
* reflex - the name of the reflex e.g. "Example#demo"
|
||||
*
|
||||
* error/noop - the error message (for reflexError), otherwise null
|
||||
*
|
||||
* reflexId - a UUID4 or developer-provided unique identifier for each Reflex
|
||||
*/
|
||||
|
||||
beforeReflex(element, reflex, noop, reflexId) {
|
||||
// document.body.classList.add('wait')
|
||||
}
|
||||
|
||||
reflexSuccess(element, reflex, noop, reflexId) {
|
||||
// show success message
|
||||
}
|
||||
|
||||
reflexError(element, reflex, error, reflexId) {
|
||||
// show error message
|
||||
}
|
||||
|
||||
reflexForbidden(element, reflex, noop, reflexId) {
|
||||
// Reflex action did not have permission to run
|
||||
// window.location = '/'
|
||||
}
|
||||
|
||||
reflexHalted(element, reflex, noop, reflexId) {
|
||||
// handle aborted Reflex action
|
||||
}
|
||||
|
||||
afterReflex(element, reflex, noop, reflexId) {
|
||||
// document.body.classList.remove('wait')
|
||||
}
|
||||
|
||||
finalizeReflex(element, reflex, noop, reflexId) {
|
||||
// all operations have completed, animation etc is now safe
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user