Page MenuHomePhabricator

Consolidate singleton state
Closed, DeclinedPublic

Description

Keeping singletons distinct doesn't seem very useful and only disperses the app's dependencies unnecessarily. They're primary distinction from the rest of the code is that they're instantiated once and shared globally. If the dependencies cannot be passed by parameter, consolidating them seems preferable.

Acceptance criteria

  • Move singletons to one file, singleton.js.
  • Lazily initialize singletons on access. Maybe something like:
/** @prop {OO.EventEmitter} [_eventBus] */
class Singleton {
  /** @return {OO.EventEmitter} */
  eventBus() {
    if ( !this._eventBus ) this._eventBus = new OO.EventEmitter();
    return this._eventBus;
  },
  moduleLoader() { ... }
}
  • State should be resetable by tests if that's useful.
  • References in MobileFrontend and MinervaNeue are updated.

Event Timeline

ovasileva moved this task from Incoming to Needs Prioritization on the Web-Team-Backlog board.

This change may impact the tests which often initialize in beforeEach(). I think it should be ok due to lazy init but we most probably want to check.

(Low priority) Am going through the backlog checking the status of old bugs. is this bug still relevant? If so, have the goalposts changed? Does the description need updating?