41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = EventTargetSource;
|
||
|
|
||
|
var _dispose = require('../disposable/dispose');
|
||
|
|
||
|
var dispose = _interopRequireWildcard(_dispose);
|
||
|
|
||
|
var _tryEvent = require('./tryEvent');
|
||
|
|
||
|
var tryEvent = _interopRequireWildcard(_tryEvent);
|
||
|
|
||
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
||
|
|
||
|
/** @license MIT License (c) copyright 2010-2016 original author or authors */
|
||
|
/** @author Brian Cavalier */
|
||
|
/** @author John Hann */
|
||
|
|
||
|
function EventTargetSource(event, source, capture) {
|
||
|
this.event = event;
|
||
|
this.source = source;
|
||
|
this.capture = capture;
|
||
|
}
|
||
|
|
||
|
EventTargetSource.prototype.run = function (sink, scheduler) {
|
||
|
function addEvent(e) {
|
||
|
tryEvent.tryEvent(scheduler.now(), e, sink);
|
||
|
}
|
||
|
|
||
|
this.source.addEventListener(this.event, addEvent, this.capture);
|
||
|
|
||
|
return dispose.create(disposeEventTarget, { target: this, addEvent: addEvent });
|
||
|
};
|
||
|
|
||
|
function disposeEventTarget(info) {
|
||
|
var target = info.target;
|
||
|
target.source.removeEventListener(target.event, info.addEvent, target.capture);
|
||
|
}
|