stimulus_reflex
Advanced tools
Comparing version 3.1.2 to 3.1.3
import { createConsumer } from '@rails/actioncable' | ||
function connectionOpened () { | ||
document.body.removeAttribute('data-action-cable-disconnected') | ||
document.body.setAttribute('data-action-cable-connected', '') | ||
} | ||
function connectionClosed () { | ||
document.body.removeAttribute('data-action-cable-connected') | ||
document.body.setAttribute('data-action-cable-disconnected', '') | ||
} | ||
function isConsumer (object) { | ||
@@ -36,25 +26,4 @@ if (object) { | ||
export function registerConsumer (consumer) { | ||
const connection = consumer ? consumer.connection : null | ||
const socket = connection ? connection.webSocket : null | ||
try { | ||
socket.removeEventListener('open', connectionOpened) | ||
socket.addEventListener('open', connectionOpened) | ||
socket.removeEventListener('close', connectionClosed) | ||
socket.addEventListener('close', connectionClosed) | ||
socket.removeEventListener('error', connectionClosed) | ||
socket.addEventListener('error', connectionClosed) | ||
connection.isOpen() ? connectionOpened() : connectionClosed() | ||
} catch (error) { | ||
console.error( | ||
"StimulusReflex was unable to register the ActionCable consumer. Don't worry, everything should still work.", | ||
consumer, | ||
connection, | ||
socket | ||
) | ||
} | ||
} | ||
export function getConsumer () { | ||
return findConsumer(window) || createConsumer() | ||
} |
{ | ||
"name": "stimulus_reflex", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Build reactive applications with the Rails tooling you already know and love.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,3 @@ import { Controller } from 'stimulus' | ||
import { defaultSchema } from './schema' | ||
import { getConsumer, registerConsumer } from './consumer' | ||
import { getConsumer } from './consumer' | ||
import { dispatchLifecycleEvent } from './lifecycle' | ||
@@ -54,4 +54,2 @@ import { allReflexControllers } from './controllers' | ||
actionCableConsumer = actionCableConsumer || getConsumer() | ||
registerConsumer(actionCableConsumer) | ||
const { channel } = controller.StimulusReflex | ||
@@ -58,0 +56,0 @@ const identifier = JSON.stringify({ channel }) |
25330
6897
706