87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.of = of;
|
||
|
exports.empty = empty;
|
||
|
exports.never = never;
|
||
|
|
||
|
var _Stream = require('../Stream');
|
||
|
|
||
|
var _Stream2 = _interopRequireDefault(_Stream);
|
||
|
|
||
|
var _dispose = require('../disposable/dispose');
|
||
|
|
||
|
var dispose = _interopRequireWildcard(_dispose);
|
||
|
|
||
|
var _PropagateTask = require('../scheduler/PropagateTask');
|
||
|
|
||
|
var _PropagateTask2 = _interopRequireDefault(_PropagateTask);
|
||
|
|
||
|
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; } }
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
/**
|
||
|
* Stream containing only x
|
||
|
* @param {*} x
|
||
|
* @returns {Stream}
|
||
|
*/
|
||
|
function of(x) {
|
||
|
return new _Stream2.default(new Just(x));
|
||
|
} /** @license MIT License (c) copyright 2010-2016 original author or authors */
|
||
|
/** @author Brian Cavalier */
|
||
|
/** @author John Hann */
|
||
|
|
||
|
function Just(x) {
|
||
|
this.value = x;
|
||
|
}
|
||
|
|
||
|
Just.prototype.run = function (sink, scheduler) {
|
||
|
return scheduler.asap(new _PropagateTask2.default(runJust, this.value, sink));
|
||
|
};
|
||
|
|
||
|
function runJust(t, x, sink) {
|
||
|
sink.event(t, x);
|
||
|
sink.end(t, void 0);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Stream containing no events and ends immediately
|
||
|
* @returns {Stream}
|
||
|
*/
|
||
|
function empty() {
|
||
|
return EMPTY;
|
||
|
}
|
||
|
|
||
|
function EmptySource() {}
|
||
|
|
||
|
EmptySource.prototype.run = function (sink, scheduler) {
|
||
|
var task = _PropagateTask2.default.end(void 0, sink);
|
||
|
scheduler.asap(task);
|
||
|
|
||
|
return dispose.create(disposeEmpty, task);
|
||
|
};
|
||
|
|
||
|
function disposeEmpty(task) {
|
||
|
return task.dispose();
|
||
|
}
|
||
|
|
||
|
var EMPTY = new _Stream2.default(new EmptySource());
|
||
|
|
||
|
/**
|
||
|
* Stream containing no events and never ends
|
||
|
* @returns {Stream}
|
||
|
*/
|
||
|
function never() {
|
||
|
return NEVER;
|
||
|
}
|
||
|
|
||
|
function NeverSource() {}
|
||
|
|
||
|
NeverSource.prototype.run = function () {
|
||
|
return dispose.empty();
|
||
|
};
|
||
|
|
||
|
var NEVER = new _Stream2.default(new NeverSource());
|