Created
March 23, 2023 10:11
-
-
Save dcyoung-dev/35c34509fcad1bed8421151ce6a0ba94 to your computer and use it in GitHub Desktop.
Using lodash debounce function in a Stimulus controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Controller} from "@hotwired/stimulus" | |
import {debounce} from "lodash/function"; | |
// Connects to data-controller="auto-save" | |
export default class extends Controller { | |
initialize() { | |
this.autosave = debounce(this.autosave, 200).bind(this) | |
} | |
autosave(event) { | |
this.element.requestSubmit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment