This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/papercraft/openjscad/node_modules/most/lib/observable/fromObservable.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fromObservable = fromObservable;
exports.ObservableSource = ObservableSource;
exports.SubscriberSink = SubscriberSink;
var _Stream = require('../Stream');
var _Stream2 = _interopRequireDefault(_Stream);
var _dispose = require('../disposable/dispose');
var dispose = _interopRequireWildcard(_dispose);
var _tryEvent = require('../source/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; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function fromObservable(observable) {
return new _Stream2.default(new ObservableSource(observable));
} /** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
function ObservableSource(observable) {
this.observable = observable;
}
ObservableSource.prototype.run = function (sink, scheduler) {
var sub = this.observable.subscribe(new SubscriberSink(sink, scheduler));
if (typeof sub === 'function') {
return dispose.create(sub);
} else if (sub && typeof sub.unsubscribe === 'function') {
return dispose.create(unsubscribe, sub);
}
throw new TypeError('Observable returned invalid subscription ' + String(sub));
};
function SubscriberSink(sink, scheduler) {
this.sink = sink;
this.scheduler = scheduler;
}
SubscriberSink.prototype.next = function (x) {
(0, _tryEvent.tryEvent)(this.scheduler.now(), x, this.sink);
};
SubscriberSink.prototype.complete = function (x) {
(0, _tryEvent.tryEnd)(this.scheduler.now(), x, this.sink);
};
SubscriberSink.prototype.error = function (e) {
this.sink.error(this.scheduler.now(), e);
};
function unsubscribe(subscription) {
return subscription.unsubscribe();
}