Skip to content

Commit

Permalink
Extract actionsList getter in Stimulus ApplicationController
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Nov 27, 2024
1 parent 0d6f4b1 commit 145507e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/assets/bundle/trestle/admin.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions frontend/js/controllers/application_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Controller } from '@hotwired/stimulus'
import { fetchWithErrorHandling, fetchTurboStream } from '../core/fetch'

export default class extends Controller {
appendAction (event, action, element = this.element) {
const actions = element.dataset.action ? element.dataset.action.split(' ') : []
actions.push(`${event}->${this.identifier}#${action}`)
appendAction (event, method, element = this.element) {
const actions = this.actionsList
actions.push(`${event}->${this.identifier}#${method}`)

element.dataset.action = actions.join(' ')
}

Expand All @@ -20,4 +21,12 @@ export default class extends Controller {
get csrfToken () {
return document.querySelector("[name='csrf-token']").content
}

get actionsList () {
if (element.dataset.action) {
return element.dataset.action.split(' ')
} else {
return []
}
}
}

0 comments on commit 145507e

Please sign in to comment.