openfoodfoundation/openfoodnetwork

View on GitHub
app/webpacker/controllers/scoped_channel_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import { Controller } from "stimulus";
import consumer from "../channels/consumer";
import CableReady from "cable_ready";

export default class extends Controller {
  static values = { id: String };

  connect() {
    this.subscription = consumer.subscriptions.create(
      { channel: "ScopedChannel", id: this.idValue },
      {
        received(data) {
          if (data.cableReady) CableReady.perform(data.operations);
        },
      }
    );
  }

  disconnect() {
    consumer.subscriptions.remove(this.subscription);
  }
}