michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: module.metadata = { michael@0: "stability": "unstable" michael@0: }; michael@0: michael@0: let { emit } = require("./core"); michael@0: michael@0: // Simple utility function takes event target, event type and optional michael@0: // `options.capture` and returns node style event stream that emits "data" michael@0: // events every time event of that type occurs on the given `target`. michael@0: function open(target, type, options) { michael@0: let output = {}; michael@0: let capture = options && options.capture ? true : false; michael@0: michael@0: target.addEventListener(type, function(event) { michael@0: emit(output, "data", event); michael@0: }, capture); michael@0: michael@0: return output; michael@0: } michael@0: exports.open = open;