stimulus_reflex
Advanced tools
Comparing version 3.3.0-pre5 to 3.3.0-pre6
@@ -21,4 +21,3 @@ const logs = {} | ||
const { event } = response | ||
const { reflexId, target, last, broadcaster, updates } = | ||
event.detail.stimulusReflex || {} | ||
const { reflexId, target, broadcaster } = event.detail.stimulusReflex || {} | ||
@@ -29,6 +28,5 @@ console.log(`\u2193 reflex \u2193 ${target}`, { | ||
halted: options.halted, | ||
broadcaster, | ||
updates | ||
broadcaster | ||
}) | ||
if (last) delete logs[reflexId] | ||
delete logs[reflexId] | ||
} | ||
@@ -35,0 +33,0 @@ |
{ | ||
"name": "stimulus_reflex", | ||
"version": "3.3.0-pre5", | ||
"version": "3.3.0-pre6", | ||
"description": "Build reactive applications with the Rails tooling you already know and love.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,3 +8,3 @@ import { Controller } from 'stimulus' | ||
import { allReflexControllers } from './controllers' | ||
import { uuidv4, debounce } from './utils' | ||
import { uuidv4, debounce, emitEvent } from './utils' | ||
import Log from './log' | ||
@@ -29,2 +29,5 @@ import { | ||
// A reference to an optional object called params defined in the StimulusReflex.initialize and passed to channels | ||
let actionCableParams | ||
// Flag which will be false if the server does not accept the channel subscription | ||
@@ -45,19 +48,10 @@ let actionCableSubscriptionActive = false | ||
const { channel } = controller.StimulusReflex | ||
const identifier = JSON.stringify({ channel }) | ||
const subscription = { channel, ...actionCableParams } | ||
const identifier = JSON.stringify(subscription) | ||
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, { | ||
actionCableConsumer.subscriptions.create(subscription, { | ||
received: data => { | ||
@@ -327,2 +321,3 @@ if (!data.cableReady) return | ||
}) | ||
emitEvent('stimulus-reflex:ready') | ||
}, 20) | ||
@@ -385,4 +380,5 @@ | ||
const initialize = (application, initializeOptions = {}) => { | ||
const { controller, consumer, debug } = initializeOptions | ||
const { controller, consumer, debug, params } = initializeOptions | ||
actionCableConsumer = consumer | ||
actionCableParams = params | ||
stimulusApplication = application | ||
@@ -389,0 +385,0 @@ stimulusApplication.schema = { ...defaultSchema, ...application.schema } |
10
utils.js
@@ -42,1 +42,11 @@ // uuid4 function taken from stackoverflow | ||
} | ||
export const emitEvent = (event, detail) => { | ||
document.dispatchEvent( | ||
new CustomEvent(event, { | ||
bubbles: true, | ||
cancelable: false, | ||
detail | ||
}) | ||
) | ||
} |
48400
1320