Skip to content

Commit

Permalink
pass data attributes object as a method parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed Nov 26, 2020
1 parent 2b6facc commit 61f804e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/@stimulus/core/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Binding {

private invokeWithEvent(event: Event) {
try {
this.method.call(this.controller, event)
this.method.call(this.controller, event, { ...this.dataAttributes(event) })
} catch (error) {
const { identifier, controller, element, index } = this
const detail = { identifier, controller, element, index, event }
Expand All @@ -67,6 +67,14 @@ export class Binding {
}
}

private dataAttributes(event: Event): object {
if (event.currentTarget instanceof HTMLElement) {
return event.currentTarget.dataset
} else {
return {}
}
}

private get controller(): Controller {
return this.context.controller
}
Expand Down

0 comments on commit 61f804e

Please sign in to comment.