Skip to content

Commit

Permalink
Pass element to actionsList method in Stimulus ApplicationController
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Dec 4, 2024
1 parent 4ce8062 commit d5b7d3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/assets/bundle/trestle/admin.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions frontend/js/controllers/application_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fetchWithErrorHandling, fetchTurboStream } from '../core/fetch'

export default class extends Controller {
appendAction (event, method, element = this.element) {
const actions = this.actionsList
const actions = this.actionsList(element)
const newAction = `${event}->${this.identifier}#${method}`

if (!actions.includes(newAction)) {
Expand All @@ -16,7 +16,7 @@ export default class extends Controller {

removeAction (event, method, element = this.element) {
const newAction = `${event}->${this.identifier}#${method}`
const actions = this.actionsList.filter(action => action !== newAction)
const actions = this.actionsList(element).filter(action => action !== newAction)

element.dataset.action = actions.join(' ')
}
Expand All @@ -29,15 +29,15 @@ export default class extends Controller {
return fetchTurboStream(url, options)
}

get csrfToken () {
return document.querySelector("[name='csrf-token']").content
}

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

get csrfToken () {
return document.querySelector("[name='csrf-token']").content
}
}

0 comments on commit d5b7d3b

Please sign in to comment.