Skip to content

Commit

Permalink
Merge pull request #312 from leastbad/ready_event
Browse files Browse the repository at this point in the history
add ready event after setupDeclarativeReflexes
  • Loading branch information
leastbad authored Sep 19, 2020
2 parents c30ecf8 + d40329a commit 23c8631
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 2 additions & 11 deletions javascript/stimulus_reflex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defaultSchema } from './schema'
import { getConsumer } from './consumer'
import { dispatchLifecycleEvent } from './lifecycle'
import { allReflexControllers } from './controllers'
import { uuidv4, debounce } from './utils'
import { uuidv4, debounce, emitEvent } from './utils'
import Log from './log'
import {
attributeValue,
Expand Down Expand Up @@ -44,16 +44,6 @@ const createSubscription = controller => {
let totalOperations
let reflexId

const emitEvent = (event, detail) => {
document.dispatchEvent(
new CustomEvent(event, {
bubbles: true,
cancelable: false,
detail
})
)
}

controller.StimulusReflex.subscription =
actionCableConsumer.subscriptions.findAll(identifier)[0] ||
actionCableConsumer.subscriptions.create(channel, {
Expand Down Expand Up @@ -321,6 +311,7 @@ const setupDeclarativeReflexes = debounce(() => {
actionValue
)
})
emitEvent('stimulus-reflex:ready')
}, 20)

// Given a reflex string such as 'click->TestReflex#create' and a list of
Expand Down
10 changes: 10 additions & 0 deletions javascript/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ export const extractReflexName = reflexString => {

return match ? match[1] : ''
}

export const emitEvent = (event, detail) => {
document.dispatchEvent(
new CustomEvent(event, {
bubbles: true,
cancelable: false,
detail
})
)
}

0 comments on commit 23c8631

Please sign in to comment.