Skip to content

Commit

Permalink
Merge pull request #3 from hopsoft/pjforde1978-selectors
Browse files Browse the repository at this point in the history
Preserve `this` context on lifecycle methods
  • Loading branch information
leastbad authored Oct 4, 2019
2 parents 639b55d + 673ab4c commit a3c90d6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions javascript/stimulus_reflex.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,19 @@ const invokeLifecycleMethod = (stage, reflex, element) => {
const genericLifecycleMethod = controller[genericLifecycleMethodName]

if (typeof specificLifecycleMethod === 'function') {
setTimeout(() => specificLifecycleMethod(element, element.reflexError), 1)
setTimeout(
() =>
specificLifecycleMethod.call(controller, element, element.reflexError),
1
)
}

if (typeof genericLifecycleMethod === 'function') {
setTimeout(() => genericLifecycleMethod(element, element.reflexError), 1)
setTimeout(
() =>
genericLifecycleMethod.call(controller, element, element.reflexError),
1
)
}
}

Expand Down

0 comments on commit a3c90d6

Please sign in to comment.