Sha256: e772d8123429b4468820eb59ea7f147c81dd6ebd64319a7b082729d6fe105447

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

import Route from "@ember/routing/route";
import MessageCollection from "client-app/models/message-collection";
import { isHidden } from "client-app/lib/utilities";

export default Route.extend({
  model() {
    // TODO from preload json?
    return MessageCollection.create();
  },

  setupController(controller, model) {
    this._super(controller, model);
    model.setProperties(controller.getProperties("filter", "search"));
    model.reload();
    controller.set("initialized", true);

    let times = 0;
    let backoff = 1;

    this.refreshInterval = setInterval(() => {
      if (model.loading) {
        return;
      }
      times += 1;
      const hidden = isHidden();
      let load = !hidden;

      if (hidden) {
        if (times % backoff === 0) {
          load = true;
          if (backoff < 20) {
            backoff++;
          }
        }
      }
      // refresh a lot less aggressively in background
      if (load) {
        model.loadMore();
        if (!hidden) {
          backoff = 1;
        }
      }
    }, 3000);

    this.events.on("panelResized", amount => {
      controller.resizePanels(amount);
    });
  },

  deactivate() {
    clearInterval(this.refreshInterval);
  }
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logster-2.4.2 client-app/app/routes/index.js
logster-2.4.1 client-app/app/routes/index.js