Sha256: d386b5ee12e32fec72c360ad09312c1579b0a5482913e1c1cc7d8d5252e55b7a

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

import consumer from "channels/consumer"
import { Turbo } from "@hotwired/turbo-rails"

export default componentSubscription = (componentId, componentClass, element) => consumer.subscriptions.create(
  { channel: "ComponentChannel", componentClass: componentClass, componentId: componentId },
  {
    connected() {
      // Called when the subscription is ready for use on the server
    },
    disconnected() {
      // Called when the subscription has been terminated by the server
    },
    received(data) {
      if (data.type == "redraw") {
        element.outerHTML = data.html
      } else if (data.type == "remove") {
        element.remove()
      } else if (data.type == "reload") {
        Turbo.visit(window.location.href, { action: "replace" })
      } else if (data.type == "redirect") {
        Turbo.visit(data.redirectUrl)
      }
      // TODO: add in types for animations and events - and add event handlers to components
    },
    performAction(params) {
      this.perform("action", params)
    }
  }
);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stimul8-0.1.0 app/javascript/channels/stimul8/component_channel.js