Sha256: cea19fb8980fa1a7fac3ccf57464ed72dce446f21c04befb87bf32c8918713f0

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

import { Env } from "loco-js";

import UserController from "controllers/User";
import RoomsController from "controllers/user/Rooms";

class NotificationCenter {
  receivedSignal(data) {
    switch (data.signal) {
      case "ping":
        this._pingSignal();
        break;
      case "message":
        this._messageSignal(data);
    }
  }

  _pingSignal() {
    if (Env.namespaceController.constructor !== UserController) return;
    alert("Ping!");
  }

  _messageSignal(data) {
    const view = this._getRoomView();
    if (!view) return;
    view.receivedMessage(data.message, data.author);
  }

  _getRoomView() {
    if (Env.namespaceController.constructor !== UserController) return false;
    if (Env.controller.constructor !== RoomsController) return false;
    if (Env.action !== "show") return false;
    return Env.controller.getView("show");
  }
}

export default NotificationCenter;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
loco-rails-3.0.5 test/dummy/frontend/js/services/NotificationCenter.js
loco-rails-3.0.4 test/dummy/frontend/js/services/NotificationCenter.js