events.js 839 B

1234567891011121314151617181920212223242526
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. // This module basically translates system/events to a SDK standard events
  6. // so that `map`, `filter` and other utilities could be used with them.
  7. module.metadata = {
  8. "stability": "experimental"
  9. };
  10. const events = require("../system/events");
  11. const { emit } = require("../event/core");
  12. let channel = {};
  13. function forward({ subject, type, data })
  14. emit(channel, "data", { target: subject, type: type, data: data });
  15. ["popupshowing", "popuphiding", "popupshown", "popuphidden",
  16. "document-element-inserted", "DOMContentLoaded", "load"
  17. ].forEach(function(type) events.on(type, forward));
  18. exports.events = channel;