Bounce events/notifications/etc through intermediary so we can load less code on startup

NEW
Unassigned

Status

()

6 years ago
6 years ago

People

(Reporter: Dolske, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
I've seen code in a number of spots that attempts to be a good citizen by lazy-loading its JSM (or _could_), but the benefit is negated because code in the module wants to observe certain notifications or events or whatever. And so the module ends up being loaded early -- by way of MyModule.init() or addObserver("blah", MyModule.observer) -- even if those notifications will commonly not fire until long after the browser has started running.

We should bounce this stuff through an intermediary, so that JSMs are only actually loaded upon first-real-use.

EG:

  defineLazyModuleGetter("SomeModule.jsm");
  defineLazyModuleGetter("BaconCore.jsm");

  function bounce(thing) {
    switch (thing.type):
      case "foo":
        SomeModule.handleFoo(thing);
        break;
      case "bar":
        SomeModule.doBar(thing);
        BaconCore.doBar(thing);
        break;
      case "burnt":
      case "crispy":
      case "soggy":
        BaconCore.cookingDone(thing);
        break;
  }

  addObserver("foo", bounce);
  addObserver("bar", bounce)
  ...
You need to log in before you can comment on or make changes to this bug.