Skip to content

Instantly share code, notes, and snippets.

@dcyoung-dev
Created March 23, 2023 10:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcyoung-dev/35c34509fcad1bed8421151ce6a0ba94 to your computer and use it in GitHub Desktop.
Save dcyoung-dev/35c34509fcad1bed8421151ce6a0ba94 to your computer and use it in GitHub Desktop.
Using lodash debounce function in a Stimulus controller
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