Skip to content

Instantly share code, notes, and snippets.

@joeldrapper
Last active March 7, 2024 10:33
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 joeldrapper/1b28a681287b2b8d6ab35aff09ce17f6 to your computer and use it in GitHub Desktop.
Save joeldrapper/1b28a681287b2b8d6ab35aff09ce17f6 to your computer and use it in GitHub Desktop.
Stimulus Controller with CoffeeScript2 Getters and Setters
import { Controller } from "stimulus"
export default class extends Controller
@get: (name, getter) ->
Object.defineProperty @::, name,
get: getter
configurable: true
@set: (name, setter) ->
Object.defineProperty @::, name,
set: setter
configurable: true
import ApplicationController from "controllers/application_controller"
export default class extends ApplicationController
copy: ->
@sourceElement.select()
document.execCommand "copy"
@get "sourceElement", ->
@targets.find "source"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment