mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Separation of concerns: use a loading controller
Two different events can be used: `show-loading` and `hide-loading`. I'm not 100% sure this is the right way to go, but let's try!
This commit is contained in:
22
app/webpacker/controllers/loading_controller.js
Normal file
22
app/webpacker/controllers/loading_controller.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import ApplicationController from "./application_controller";
|
||||
|
||||
export default class extends ApplicationController {
|
||||
connect() {
|
||||
super.connect();
|
||||
document.addEventListener("show-loading", this.showLoading);
|
||||
document.addEventListener("hide-loading", this.hideLoading);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
document.removeEventListener("show-loading", this.showLoading);
|
||||
document.removeEventListener("hide-loading", this.hideLoading);
|
||||
}
|
||||
|
||||
hideLoading = () => {
|
||||
this.element.classList.add("hidden");
|
||||
};
|
||||
|
||||
showLoading = () => {
|
||||
this.element.classList.remove("hidden");
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user