dom.js 788 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. module.metadata = {
  6. "stability": "unstable"
  7. };
  8. let { emit, on, off } = require("./core");
  9. // Simple utility function takes event target, event type and optional
  10. // `options.capture` and returns node style event stream that emits "data"
  11. // events every time event of that type occurs on the given `target`.
  12. function open(target, type, options) {
  13. let output = {};
  14. let capture = options && options.capture ? true : false;
  15. target.addEventListener(type, function(event) {
  16. emit(output, "data", event);
  17. }, capture);
  18. return output;
  19. }
  20. exports.open = open;