Last active
March 7, 2024 10:33
-
-
Save joeldrapper/1b28a681287b2b8d6ab35aff09ce17f6 to your computer and use it in GitHub Desktop.
Stimulus Controller with CoffeeScript2 Getters and Setters
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 "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 |
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 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