1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@most/prelude'), require('@most/scheduler'), require('@most/disposable')) :
- typeof define === 'function' && define.amd ? define(['exports', '@most/prelude', '@most/scheduler', '@most/disposable'], factory) :
- (factory((global.mostCore = {}),global.mostPrelude,global.mostScheduler,global.mostDisposable));
- }(this, (function (exports,prelude,scheduler,disposable) { 'use strict';
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- function fatalError(e) {
- setTimeout(rethrow, 0, e);
- }
- function rethrow(e) {
- throw e;
- }
- var asyncGenerator = function () {
- function AwaitValue(value) {
- this.value = value;
- }
- function AsyncGenerator(gen) {
- var front, back;
- function send(key, arg) {
- return new Promise(function (resolve, reject) {
- var request = {
- key: key,
- arg: arg,
- resolve: resolve,
- reject: reject,
- next: null
- };
- if (back) {
- back = back.next = request;
- } else {
- front = back = request;
- resume(key, arg);
- }
- });
- }
- function resume(key, arg) {
- try {
- var result = gen[key](arg);
- var value = result.value;
- if (value instanceof AwaitValue) {
- Promise.resolve(value.value).then(function (arg) {
- resume("next", arg);
- }, function (arg) {
- resume("throw", arg);
- });
- } else {
- settle(result.done ? "return" : "normal", result.value);
- }
- } catch (err) {
- settle("throw", err);
- }
- }
- function settle(type, value) {
- switch (type) {
- case "return":
- front.resolve({
- value: value,
- done: true
- });
- break;
- case "throw":
- front.reject(value);
- break;
- default:
- front.resolve({
- value: value,
- done: false
- });
- break;
- }
- front = front.next;
- if (front) {
- resume(front.key, front.arg);
- } else {
- back = null;
- }
- }
- this._invoke = send;
- if (typeof gen.return !== "function") {
- this.return = undefined;
- }
- }
- if (typeof Symbol === "function" && Symbol.asyncIterator) {
- AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
- return this;
- };
- }
- AsyncGenerator.prototype.next = function (arg) {
- return this._invoke("next", arg);
- };
- AsyncGenerator.prototype.throw = function (arg) {
- return this._invoke("throw", arg);
- };
- AsyncGenerator.prototype.return = function (arg) {
- return this._invoke("return", arg);
- };
- return {
- wrap: function (fn) {
- return function () {
- return new AsyncGenerator(fn.apply(this, arguments));
- };
- },
- await: function (value) {
- return new AwaitValue(value);
- }
- };
- }();
- var classCallCheck = function (instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
- };
- var inherits = function (subClass, superClass) {
- if (typeof superClass !== "function" && superClass !== null) {
- throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
- }
- subClass.prototype = Object.create(superClass && superClass.prototype, {
- constructor: {
- value: subClass,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
- if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
- };
- var possibleConstructorReturn = function (self, call) {
- if (!self) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- }
- return call && (typeof call === "object" || typeof call === "function") ? call : self;
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var propagateTask$1 = function propagateTask(run, value, sink) {
- return new PropagateTask(run, value, sink);
- };
- var propagateEventTask$1 = function propagateEventTask(value, sink) {
- return propagateTask$1(runEvent, value, sink);
- };
- var propagateEndTask = function propagateEndTask(sink) {
- return propagateTask$1(runEnd, undefined, sink);
- };
- var propagateErrorTask$1 = function propagateErrorTask(value, sink) {
- return propagateTask$1(runError, value, sink);
- };
- var PropagateTask = /*#__PURE__*/function () {
- function PropagateTask(run, value, sink) {
- classCallCheck(this, PropagateTask);
- this._run = run;
- this.value = value;
- this.sink = sink;
- this.active = true;
- }
- PropagateTask.prototype.dispose = function dispose() {
- this.active = false;
- };
- PropagateTask.prototype.run = function run(t) {
- if (!this.active) {
- return;
- }
- var run = this._run;
- run(t, this.value, this.sink);
- };
- PropagateTask.prototype.error = function error(t, e) {
- // TODO: Remove this check and just do this.sink.error(t, e)?
- if (!this.active) {
- return fatalError(e);
- }
- this.sink.error(t, e);
- };
- return PropagateTask;
- }();
- var runEvent = function runEvent(t, x, sink) {
- return sink.event(t, x);
- };
- var runEnd = function runEnd(t, _, sink) {
- return sink.end(t);
- };
- var runError = function runError(t, e, sink) {
- return sink.error(t, e);
- };
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var empty = function empty() {
- return EMPTY;
- };
- var isCanonicalEmpty = function isCanonicalEmpty(stream) {
- return stream === EMPTY;
- };
- var containsCanonicalEmpty = function containsCanonicalEmpty(streams) {
- return streams.some(isCanonicalEmpty);
- };
- var Empty = /*#__PURE__*/function () {
- function Empty() {
- classCallCheck(this, Empty);
- }
- Empty.prototype.run = function run(sink, scheduler$$1) {
- return scheduler.asap(propagateEndTask(sink), scheduler$$1);
- };
- return Empty;
- }();
- var EMPTY = /*#__PURE__*/new Empty();
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var never = function never() {
- return NEVER;
- };
- var Never = /*#__PURE__*/function () {
- function Never() {
- classCallCheck(this, Never);
- }
- Never.prototype.run = function run() {
- return disposable.disposeNone();
- };
- return Never;
- }();
- var NEVER = /*#__PURE__*/new Never();
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var at = function at(t, x) {
- return new At(t, x);
- };
- var At = /*#__PURE__*/function () {
- function At(t, x) {
- classCallCheck(this, At);
- this.time = t;
- this.value = x;
- }
- At.prototype.run = function run(sink, scheduler$$1) {
- return scheduler.delay(this.time, propagateTask$1(runAt, this.value, sink), scheduler$$1);
- };
- return At;
- }();
- function runAt(t, x, sink) {
- sink.event(t, x);
- sink.end(t);
- }
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var now = function now(x) {
- return at(0, x);
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Create a stream of events that occur at a regular period
- * @param {Number} period periodicity of events
- * @returns {Stream} new stream of periodic events, the event value is undefined
- */
- var periodic$1 = function periodic$$1(period) {
- return new Periodic(period);
- };
- var Periodic = /*#__PURE__*/function () {
- function Periodic(period) {
- classCallCheck(this, Periodic);
- this.period = period;
- }
- Periodic.prototype.run = function run(sink, scheduler$$1) {
- return scheduler.periodic(this.period, propagateEventTask$1(undefined, sink), scheduler$$1);
- };
- return Periodic;
- }();
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var newStream = function newStream(run) {
- return new Stream(run);
- };
- var Stream = function Stream(run) {
- classCallCheck(this, Stream);
- this.run = run;
- };
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- /** @author Brian Cavalier */
- var Pipe = /*#__PURE__*/function () {
- function Pipe(sink) {
- classCallCheck(this, Pipe);
- this.sink = sink;
- }
- Pipe.prototype.event = function event(t, x) {
- return this.sink.event(t, x);
- };
- Pipe.prototype.end = function end(t) {
- return this.sink.end(t);
- };
- Pipe.prototype.error = function error(t, e) {
- return this.sink.error(t, e);
- };
- return Pipe;
- }();
- /** @license MIT License (c) copyright 2010 original author or authors */
- // A slice Bounds type that narrows min values via accumulation
- // and max values via Math.min.
- // type Bounds = { min: number, max: number }
- // Notes:
- // 0 <= min <= max
- // slice(min2, max2, slice(min1, max1, s)) ~ slice(min1 + min2, Math.min(max1, min1 + max2), s)
- // A bounds has a 1d coord system with origin 0, extending to Infinity. Both min and max
- // are relative to the origin (0). However, when merging bounds b1 and b2, we
- // *interpret* b2 as being relative to b1, hence adding min1 to *both* min2 and max2.
- // This essentially translates b2's coordinates back into origin coordinates
- // as bounds are merged.
- // Construct a constrained bounds
- var boundsFrom = function boundsFrom(unsafeMin, unsafeMax) {
- var min = Math.max(0, unsafeMin);
- var max = Math.max(min, unsafeMax);
- return { min: min, max: max };
- };
- // Combine 2 bounds by narrowing min and max
- var mergeBounds = function mergeBounds(b1, b2) {
- return boundsFrom(b1.min + b2.min, Math.min(b1.max, b1.min + b2.max));
- };
- // Nil bounds excludes all slice indices
- var isNilBounds = function isNilBounds(b) {
- return b.min >= b.max;
- };
- // Infinite bounds includes all slice indices
- var isInfiniteBounds = function isInfiniteBounds(b) {
- return b.min <= 0 && b.max === Infinity;
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var Filter = /*#__PURE__*/function () {
- function Filter(p, source) {
- classCallCheck(this, Filter);
- this.p = p;
- this.source = source;
- }
- Filter.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new FilterSink(this.p, sink), scheduler$$1);
- };
- /**
- * Create a filtered source, fusing adjacent filter.filter if possible
- * @param {function(x:*):boolean} p filtering predicate
- * @param {{run:function}} source source to filter
- * @returns {Filter} filtered source
- */
- Filter.create = function create(p, source) {
- if (isCanonicalEmpty(source)) {
- return source;
- }
- if (source instanceof Filter) {
- return new Filter(and(source.p, p), source.source);
- }
- return new Filter(p, source);
- };
- return Filter;
- }();
- var FilterSink = /*#__PURE__*/function (_Pipe) {
- inherits(FilterSink, _Pipe);
- function FilterSink(p, sink) {
- classCallCheck(this, FilterSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.p = p;
- return _this;
- }
- FilterSink.prototype.event = function event(t, x) {
- var p = this.p;
- p(x) && this.sink.event(t, x);
- };
- return FilterSink;
- }(Pipe);
- var and = function and(p, q) {
- return function (x) {
- return p(x) && q(x);
- };
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var FilterMap = /*#__PURE__*/function () {
- function FilterMap(p, f, source) {
- classCallCheck(this, FilterMap);
- this.p = p;
- this.f = f;
- this.source = source;
- }
- FilterMap.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new FilterMapSink(this.p, this.f, sink), scheduler$$1);
- };
- return FilterMap;
- }();
- var FilterMapSink = /*#__PURE__*/function (_Pipe) {
- inherits(FilterMapSink, _Pipe);
- function FilterMapSink(p, f, sink) {
- classCallCheck(this, FilterMapSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.p = p;
- _this.f = f;
- return _this;
- }
- FilterMapSink.prototype.event = function event(t, x) {
- var f = this.f;
- var p = this.p;
- p(x) && this.sink.event(t, f(x));
- };
- return FilterMapSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var Map = /*#__PURE__*/function () {
- function Map(f, source) {
- classCallCheck(this, Map);
- this.f = f;
- this.source = source;
- }
- Map.prototype.run = function run(sink, scheduler$$1) {
- // eslint-disable-line no-extend-native
- return this.source.run(new MapSink(this.f, sink), scheduler$$1);
- };
- /**
- * Create a mapped source, fusing adjacent map.map, filter.map,
- * and filter.map.map if possible
- * @param {function(*):*} f mapping function
- * @param {{run:function}} source source to map
- * @returns {Map|FilterMap} mapped source, possibly fused
- */
- Map.create = function create(f, source) {
- if (isCanonicalEmpty(source)) {
- return empty();
- }
- if (source instanceof Map) {
- return new Map(prelude.compose(f, source.f), source.source);
- }
- if (source instanceof Filter) {
- return new FilterMap(source.p, f, source.source);
- }
- return new Map(f, source);
- };
- return Map;
- }();
- var MapSink = /*#__PURE__*/function (_Pipe) {
- inherits(MapSink, _Pipe);
- function MapSink(f, sink) {
- classCallCheck(this, MapSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- return _this;
- }
- MapSink.prototype.event = function event(t, x) {
- var f = this.f;
- this.sink.event(t, f(x));
- };
- return MapSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var SettableDisposable = /*#__PURE__*/function () {
- function SettableDisposable() {
- classCallCheck(this, SettableDisposable);
- this.disposable = undefined;
- this.disposed = false;
- }
- SettableDisposable.prototype.setDisposable = function setDisposable(disposable$$1) {
- if (this.disposable !== void 0) {
- throw new Error('setDisposable called more than once');
- }
- this.disposable = disposable$$1;
- if (this.disposed) {
- disposable$$1.dispose();
- }
- };
- SettableDisposable.prototype.dispose = function dispose() {
- if (this.disposed) {
- return;
- }
- this.disposed = true;
- if (this.disposable !== void 0) {
- this.disposable.dispose();
- }
- };
- return SettableDisposable;
- }();
- /**
- * @param {number} n
- * @param {Stream} stream
- * @returns {Stream} new stream containing only up to the first n items from stream
- */
- var take$1 = function take(n, stream) {
- return slice$1(0, n, stream);
- };
- /**
- * @param {number} n
- * @param {Stream} stream
- * @returns {Stream} new stream with the first n items removed
- */
- var skip$1 = function skip(n, stream) {
- return slice$1(n, Infinity, stream);
- };
- /**
- * Slice a stream by index. Negative start/end indexes are not supported
- * @param {number} start
- * @param {number} end
- * @param {Stream} stream
- * @returns {Stream} stream containing items where start <= index < end
- */
- var slice$1 = function slice(start, end, stream) {
- return sliceBounds(boundsFrom(start, end), stream);
- };
- var sliceBounds = function sliceBounds(bounds, stream) {
- return isSliceEmpty(bounds, stream) ? empty() : stream instanceof Map ? commuteMapSlice(bounds, stream) : stream instanceof Slice ? fuseSlice(bounds, stream) : createSlice(bounds, stream);
- };
- var isSliceEmpty = function isSliceEmpty(bounds, stream) {
- return isCanonicalEmpty(stream) || isNilBounds(bounds);
- };
- var createSlice = function createSlice(bounds, stream) {
- return isInfiniteBounds(bounds) ? stream : new Slice(bounds, stream);
- };
- var commuteMapSlice = function commuteMapSlice(bounds, mapStream) {
- return Map.create(mapStream.f, sliceBounds(bounds, mapStream.source));
- };
- var fuseSlice = function fuseSlice(bounds, sliceStream) {
- return sliceBounds(mergeBounds(sliceStream.bounds, bounds), sliceStream.source);
- };
- var Slice = /*#__PURE__*/function () {
- function Slice(bounds, source) {
- classCallCheck(this, Slice);
- this.source = source;
- this.bounds = bounds;
- }
- Slice.prototype.run = function run(sink, scheduler$$1) {
- var disposable$$1 = new SettableDisposable();
- var sliceSink = new SliceSink(this.bounds.min, this.bounds.max - this.bounds.min, sink, disposable$$1);
- disposable$$1.setDisposable(this.source.run(sliceSink, scheduler$$1));
- return disposable$$1;
- };
- return Slice;
- }();
- var SliceSink = /*#__PURE__*/function (_Pipe) {
- inherits(SliceSink, _Pipe);
- function SliceSink(skip, take, sink, disposable$$1) {
- classCallCheck(this, SliceSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.skip = skip;
- _this.take = take;
- _this.disposable = disposable$$1;
- return _this;
- }
- SliceSink.prototype.event = function event(t, x) {
- /* eslint complexity: [1, 4] */
- if (this.skip > 0) {
- this.skip -= 1;
- return;
- }
- if (this.take === 0) {
- return;
- }
- this.take -= 1;
- this.sink.event(t, x);
- if (this.take === 0) {
- this.disposable.dispose();
- this.sink.end(t);
- }
- };
- return SliceSink;
- }(Pipe);
- var takeWhile$1 = function takeWhile(p, stream) {
- return isCanonicalEmpty(stream) ? empty() : new TakeWhile(p, stream);
- };
- var TakeWhile = /*#__PURE__*/function () {
- function TakeWhile(p, source) {
- classCallCheck(this, TakeWhile);
- this.p = p;
- this.source = source;
- }
- TakeWhile.prototype.run = function run(sink, scheduler$$1) {
- var disposable$$1 = new SettableDisposable();
- var takeWhileSink = new TakeWhileSink(this.p, sink, disposable$$1);
- disposable$$1.setDisposable(this.source.run(takeWhileSink, scheduler$$1));
- return disposable$$1;
- };
- return TakeWhile;
- }();
- var TakeWhileSink = /*#__PURE__*/function (_Pipe2) {
- inherits(TakeWhileSink, _Pipe2);
- function TakeWhileSink(p, sink, disposable$$1) {
- classCallCheck(this, TakeWhileSink);
- var _this2 = possibleConstructorReturn(this, _Pipe2.call(this, sink));
- _this2.p = p;
- _this2.active = true;
- _this2.disposable = disposable$$1;
- return _this2;
- }
- TakeWhileSink.prototype.event = function event(t, x) {
- if (!this.active) {
- return;
- }
- var p = this.p;
- this.active = p(x);
- if (this.active) {
- this.sink.event(t, x);
- } else {
- this.disposable.dispose();
- this.sink.end(t);
- }
- };
- return TakeWhileSink;
- }(Pipe);
- var skipWhile$1 = function skipWhile(p, stream) {
- return isCanonicalEmpty(stream) ? empty() : new SkipWhile(p, stream);
- };
- var SkipWhile = /*#__PURE__*/function () {
- function SkipWhile(p, source) {
- classCallCheck(this, SkipWhile);
- this.p = p;
- this.source = source;
- }
- SkipWhile.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new SkipWhileSink(this.p, sink), scheduler$$1);
- };
- return SkipWhile;
- }();
- var SkipWhileSink = /*#__PURE__*/function (_Pipe3) {
- inherits(SkipWhileSink, _Pipe3);
- function SkipWhileSink(p, sink) {
- classCallCheck(this, SkipWhileSink);
- var _this3 = possibleConstructorReturn(this, _Pipe3.call(this, sink));
- _this3.p = p;
- _this3.skipping = true;
- return _this3;
- }
- SkipWhileSink.prototype.event = function event(t, x) {
- if (this.skipping) {
- var p = this.p;
- this.skipping = p(x);
- if (this.skipping) {
- return;
- }
- }
- this.sink.event(t, x);
- };
- return SkipWhileSink;
- }(Pipe);
- var skipAfter$1 = function skipAfter(p, stream) {
- return isCanonicalEmpty(stream) ? empty() : new SkipAfter(p, stream);
- };
- var SkipAfter = /*#__PURE__*/function () {
- function SkipAfter(p, source) {
- classCallCheck(this, SkipAfter);
- this.p = p;
- this.source = source;
- }
- SkipAfter.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new SkipAfterSink(this.p, sink), scheduler$$1);
- };
- return SkipAfter;
- }();
- var SkipAfterSink = /*#__PURE__*/function (_Pipe4) {
- inherits(SkipAfterSink, _Pipe4);
- function SkipAfterSink(p, sink) {
- classCallCheck(this, SkipAfterSink);
- var _this4 = possibleConstructorReturn(this, _Pipe4.call(this, sink));
- _this4.p = p;
- _this4.skipping = false;
- return _this4;
- }
- SkipAfterSink.prototype.event = function event(t, x) {
- if (this.skipping) {
- return;
- }
- var p = this.p;
- this.skipping = p(x);
- this.sink.event(t, x);
- if (this.skipping) {
- this.sink.end(t);
- }
- };
- return SkipAfterSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2017 original author or authors */
- var withItems$1 = function withItems(items, stream) {
- return zipItems$1(keepLeft, items, stream);
- };
- var zipItems$1 = function zipItems(f, items, stream) {
- return isCanonicalEmpty(stream) || items.length === 0 ? empty() : new ZipItems(f, items, take$1(items.length, stream));
- };
- var keepLeft = function keepLeft(a, _) {
- return a;
- };
- var ZipItems = /*#__PURE__*/function () {
- function ZipItems(f, items, source) {
- classCallCheck(this, ZipItems);
- this.f = f;
- this.items = items;
- this.source = source;
- }
- ZipItems.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new ZipItemsSink(this.f, this.items, sink), scheduler$$1);
- };
- return ZipItems;
- }();
- var ZipItemsSink = /*#__PURE__*/function (_Pipe) {
- inherits(ZipItemsSink, _Pipe);
- function ZipItemsSink(f, items, sink) {
- classCallCheck(this, ZipItemsSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- _this.items = items;
- _this.index = 0;
- return _this;
- }
- ZipItemsSink.prototype.event = function event(t, b) {
- var f = this.f;
- this.sink.event(t, f(this.items[this.index], b));
- this.index += 1;
- };
- return ZipItemsSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var runEffects$1 = /*#__PURE__*/prelude.curry2(function (stream, scheduler$$1) {
- return new Promise(function (resolve, reject) {
- return runStream(stream, scheduler$$1, resolve, reject);
- });
- });
- function runStream(stream, scheduler$$1, resolve, reject) {
- var disposable$$1 = new SettableDisposable();
- var observer = new RunEffectsSink(resolve, reject, disposable$$1);
- disposable$$1.setDisposable(stream.run(observer, scheduler$$1));
- }
- var RunEffectsSink = /*#__PURE__*/function () {
- function RunEffectsSink(end, error, disposable$$1) {
- classCallCheck(this, RunEffectsSink);
- this._end = end;
- this._error = error;
- this._disposable = disposable$$1;
- this.active = true;
- }
- RunEffectsSink.prototype.event = function event(t, x) {};
- RunEffectsSink.prototype.end = function end(t) {
- if (!this.active) {
- return;
- }
- this._dispose(this._error, this._end, undefined);
- };
- RunEffectsSink.prototype.error = function error(t, e) {
- this._dispose(this._error, this._error, e);
- };
- RunEffectsSink.prototype._dispose = function _dispose(error, end, x) {
- this.active = false;
- tryDispose$1(error, end, x, this._disposable);
- };
- return RunEffectsSink;
- }();
- function tryDispose$1(error, end, x, disposable$$1) {
- try {
- disposable$$1.dispose();
- } catch (e) {
- error(e);
- return;
- }
- end(x);
- }
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- // Run a Stream, sending all its events to the
- // provided Sink.
- var run$1 = function run(sink, scheduler$$1, stream) {
- return stream.run(sink, scheduler$$1);
- };
- var RelativeSink = /*#__PURE__*/function () {
- function RelativeSink(offset, sink) {
- classCallCheck(this, RelativeSink);
- this.sink = sink;
- this.offset = offset;
- }
- RelativeSink.prototype.event = function event(t, x) {
- this.sink.event(t + this.offset, x);
- };
- RelativeSink.prototype.error = function error(t, e) {
- this.sink.error(t + this.offset, e);
- };
- RelativeSink.prototype.end = function end(t) {
- this.sink.end(t + this.offset);
- };
- return RelativeSink;
- }();
- // Create a stream with its own local clock
- // This transforms time from the provided scheduler's clock to a stream-local
- // clock (which starts at 0), and then *back* to the scheduler's clock before
- // propagating events to sink. In other words, upstream sources will see local times,
- // and downstream sinks will see non-local (original) times.
- var withLocalTime$1 = function withLocalTime(origin, stream) {
- return new WithLocalTime(origin, stream);
- };
- var WithLocalTime = /*#__PURE__*/function () {
- function WithLocalTime(origin, source) {
- classCallCheck(this, WithLocalTime);
- this.origin = origin;
- this.source = source;
- }
- WithLocalTime.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(relativeSink(this.origin, sink), scheduler.schedulerRelativeTo(this.origin, scheduler$$1));
- };
- return WithLocalTime;
- }();
- // Accumulate offsets instead of nesting RelativeSinks, which can happen
- // with higher-order stream and combinators like continueWith when they're
- // applied recursively.
- var relativeSink = function relativeSink(origin, sink) {
- return sink instanceof RelativeSink ? new RelativeSink(origin + sink.offset, sink.sink) : new RelativeSink(origin, sink);
- };
- /** @license MIT License (c) copyright 2010 original author or authors */
- /**
- * Generalized feedback loop. Call a stepper function for each event. The stepper
- * will be called with 2 params: the current seed and the an event value. It must
- * return a new { seed, value } pair. The `seed` will be fed back into the next
- * invocation of stepper, and the `value` will be propagated as the event value.
- * @param {function(seed:*, value:*):{seed:*, value:*}} stepper loop step function
- * @param {*} seed initial seed value passed to first stepper call
- * @param {Stream} stream event stream
- * @returns {Stream} new stream whose values are the `value` field of the objects
- * returned by the stepper
- */
- var loop$1 = function loop(stepper, seed, stream) {
- return isCanonicalEmpty(stream) ? empty() : new Loop(stepper, seed, stream);
- };
- var Loop = /*#__PURE__*/function () {
- function Loop(stepper, seed, source) {
- classCallCheck(this, Loop);
- this.step = stepper;
- this.seed = seed;
- this.source = source;
- }
- Loop.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new LoopSink(this.step, this.seed, sink), scheduler$$1);
- };
- return Loop;
- }();
- var LoopSink = /*#__PURE__*/function (_Pipe) {
- inherits(LoopSink, _Pipe);
- function LoopSink(stepper, seed, sink) {
- classCallCheck(this, LoopSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.step = stepper;
- _this.seed = seed;
- return _this;
- }
- LoopSink.prototype.event = function event(t, x) {
- var result = this.step(this.seed, x);
- this.seed = result.seed;
- this.sink.event(t, result.value);
- };
- return LoopSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Create a stream containing successive reduce results of applying f to
- * the previous reduce result and the current stream item.
- * @param {function(result:*, x:*):*} f reducer function
- * @param {*} initial initial value
- * @param {Stream} stream stream to scan
- * @returns {Stream} new stream containing successive reduce results
- */
- var scan$1 = function scan(f, initial, stream) {
- return new Scan(f, initial, stream);
- };
- var Scan = /*#__PURE__*/function () {
- function Scan(f, z, source) {
- classCallCheck(this, Scan);
- this.source = source;
- this.f = f;
- this.value = z;
- }
- Scan.prototype.run = function run(sink, scheduler$$1) {
- var d1 = scheduler.asap(propagateEventTask$1(this.value, sink), scheduler$$1);
- var d2 = this.source.run(new ScanSink(this.f, this.value, sink), scheduler$$1);
- return disposable.disposeBoth(d1, d2);
- };
- return Scan;
- }();
- var ScanSink = /*#__PURE__*/function (_Pipe) {
- inherits(ScanSink, _Pipe);
- function ScanSink(f, z, sink) {
- classCallCheck(this, ScanSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- _this.value = z;
- return _this;
- }
- ScanSink.prototype.event = function event(t, x) {
- var f = this.f;
- this.value = f(this.value, x);
- this.sink.event(t, this.value);
- };
- return ScanSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var continueWith$1 = function continueWith(f, stream) {
- return new ContinueWith(f, stream);
- };
- var ContinueWith = /*#__PURE__*/function () {
- function ContinueWith(f, source) {
- classCallCheck(this, ContinueWith);
- this.f = f;
- this.source = source;
- }
- ContinueWith.prototype.run = function run(sink, scheduler$$1) {
- return new ContinueWithSink(this.f, this.source, sink, scheduler$$1);
- };
- return ContinueWith;
- }();
- var ContinueWithSink = /*#__PURE__*/function (_Pipe) {
- inherits(ContinueWithSink, _Pipe);
- function ContinueWithSink(f, source, sink, scheduler$$1) {
- classCallCheck(this, ContinueWithSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- _this.scheduler = scheduler$$1;
- _this.active = true;
- _this.disposable = disposable.disposeOnce(source.run(_this, scheduler$$1));
- return _this;
- }
- ContinueWithSink.prototype.event = function event(t, x) {
- if (!this.active) {
- return;
- }
- this.sink.event(t, x);
- };
- ContinueWithSink.prototype.end = function end(t) {
- if (!this.active) {
- return;
- }
- disposable.tryDispose(t, this.disposable, this.sink);
- this._startNext(t, this.sink);
- };
- ContinueWithSink.prototype._startNext = function _startNext(t, sink) {
- try {
- this.disposable = this._continue(this.f, t, sink);
- } catch (e) {
- sink.error(t, e);
- }
- };
- ContinueWithSink.prototype._continue = function _continue(f, t, sink) {
- return run$1(sink, this.scheduler, withLocalTime$1(t, f()));
- };
- ContinueWithSink.prototype.dispose = function dispose() {
- this.active = false;
- return this.disposable.dispose();
- };
- return ContinueWithSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- var startWith$1 = function startWith(x, stream) {
- return continueWith$1(function () {
- return stream;
- }, now(x));
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Transform each value in the stream by applying f to each
- * @param {function(*):*} f mapping function
- * @param {Stream} stream stream to map
- * @returns {Stream} stream containing items transformed by f
- */
- var map$2 = function map$$1(f, stream) {
- return Map.create(f, stream);
- };
- /**
- * Replace each value in the stream with x
- * @param {*} x
- * @param {Stream} stream
- * @returns {Stream} stream containing items replaced with x
- */
- var constant$1 = function constant(x, stream) {
- return map$2(function () {
- return x;
- }, stream);
- };
- /**
- * Perform a side effect for each item in the stream
- * @param {function(x:*):*} f side effect to execute for each item. The
- * return value will be discarded.
- * @param {Stream} stream stream to tap
- * @returns {Stream} new stream containing the same items as this stream
- */
- var tap$1 = function tap(f, stream) {
- return new Tap(f, stream);
- };
- var Tap = /*#__PURE__*/function () {
- function Tap(f, source) {
- classCallCheck(this, Tap);
- this.source = source;
- this.f = f;
- }
- Tap.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new TapSink(this.f, sink), scheduler$$1);
- };
- return Tap;
- }();
- var TapSink = /*#__PURE__*/function (_Pipe) {
- inherits(TapSink, _Pipe);
- function TapSink(f, sink) {
- classCallCheck(this, TapSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- return _this;
- }
- TapSink.prototype.event = function event(t, x) {
- var f = this.f;
- f(x);
- this.sink.event(t, x);
- };
- return TapSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var IndexSink = /*#__PURE__*/function (_Sink) {
- inherits(IndexSink, _Sink);
- function IndexSink(i, sink) {
- classCallCheck(this, IndexSink);
- var _this = possibleConstructorReturn(this, _Sink.call(this, sink));
- _this.index = i;
- _this.active = true;
- _this.value = undefined;
- return _this;
- }
- IndexSink.prototype.event = function event(t, x) {
- if (!this.active) {
- return;
- }
- this.value = x;
- this.sink.event(t, this);
- };
- IndexSink.prototype.end = function end(t) {
- if (!this.active) {
- return;
- }
- this.active = false;
- this.sink.event(t, this);
- };
- return IndexSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- function invoke(f, args) {
- /* eslint complexity: [2,7] */
- switch (args.length) {
- case 0:
- return f();
- case 1:
- return f(args[0]);
- case 2:
- return f(args[0], args[1]);
- case 3:
- return f(args[0], args[1], args[2]);
- case 4:
- return f(args[0], args[1], args[2], args[3]);
- case 5:
- return f(args[0], args[1], args[2], args[3], args[4]);
- default:
- return f.apply(void 0, args);
- }
- }
- /** @license MIT License (c) copyright 2010 original author or authors */
- /**
- * Combine latest events from two streams
- * @param {function(...events):*} f function to combine most recent events
- * @returns {Stream} stream containing the result of applying f to the most recent
- * event of each input stream, whenever a new event arrives on any stream.
- */
- var combine$1 = function combine(f, stream1, stream2) {
- return combineArray$1(f, [stream1, stream2]);
- };
- /**
- * Combine latest events from all input streams
- * @param {function(...events):*} f function to combine most recent events
- * @param {[Stream]} streams most recent events
- * @returns {Stream} stream containing the result of applying f to the most recent
- * event of each input stream, whenever a new event arrives on any stream.
- */
- var combineArray$1 = function combineArray(f, streams) {
- return streams.length === 0 || containsCanonicalEmpty(streams) ? empty() : streams.length === 1 ? map$2(f, streams[0]) : new Combine(f, streams);
- };
- var Combine = /*#__PURE__*/function () {
- function Combine(f, sources) {
- classCallCheck(this, Combine);
- this.f = f;
- this.sources = sources;
- }
- Combine.prototype.run = function run(sink, scheduler$$1) {
- var l = this.sources.length;
- var disposables = new Array(l);
- var sinks = new Array(l);
- var mergeSink = new CombineSink(disposables, sinks, sink, this.f);
- for (var indexSink, i = 0; i < l; ++i) {
- indexSink = sinks[i] = new IndexSink(i, mergeSink);
- disposables[i] = this.sources[i].run(indexSink, scheduler$$1);
- }
- return disposable.disposeAll(disposables);
- };
- return Combine;
- }();
- var CombineSink = /*#__PURE__*/function (_Pipe) {
- inherits(CombineSink, _Pipe);
- function CombineSink(disposables, sinks, sink, f) {
- classCallCheck(this, CombineSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.disposables = disposables;
- _this.sinks = sinks;
- _this.f = f;
- var l = sinks.length;
- _this.awaiting = l;
- _this.values = new Array(l);
- _this.hasValue = new Array(l).fill(false);
- _this.activeCount = sinks.length;
- return _this;
- }
- CombineSink.prototype.event = function event(t, indexedValue) {
- if (!indexedValue.active) {
- this._dispose(t, indexedValue.index);
- return;
- }
- var i = indexedValue.index;
- var awaiting = this._updateReady(i);
- this.values[i] = indexedValue.value;
- if (awaiting === 0) {
- this.sink.event(t, invoke(this.f, this.values));
- }
- };
- CombineSink.prototype._updateReady = function _updateReady(index) {
- if (this.awaiting > 0) {
- if (!this.hasValue[index]) {
- this.hasValue[index] = true;
- this.awaiting -= 1;
- }
- }
- return this.awaiting;
- };
- CombineSink.prototype._dispose = function _dispose(t, index) {
- disposable.tryDispose(t, this.disposables[index], this.sink);
- if (--this.activeCount === 0) {
- this.sink.end(t);
- }
- };
- return CombineSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Assume fs is a stream containing functions, and apply the latest function
- * in fs to the latest value in xs.
- * fs: --f---------g--------h------>
- * xs: -a-------b-------c-------d-->
- * ap(fs, xs): --fa-----fb-gb---gc--hc--hd->
- * @param {Stream} fs stream of functions to apply to the latest x
- * @param {Stream} xs stream of values to which to apply all the latest f
- * @returns {Stream} stream containing all the applications of fs to xs
- */
- function ap$1(fs, xs) {
- return combine$1(prelude.apply, fs, xs);
- }
- /** @license MIT License (c) copyright 2010 original author or authors */
- var mergeConcurrently$1 = function mergeConcurrently(concurrency, stream) {
- return mergeMapConcurrently$1(prelude.id, concurrency, stream);
- };
- var mergeMapConcurrently$1 = function mergeMapConcurrently(f, concurrency, stream) {
- return isCanonicalEmpty(stream) ? empty() : new MergeConcurrently(f, concurrency, stream);
- };
- var MergeConcurrently = /*#__PURE__*/function () {
- function MergeConcurrently(f, concurrency, source) {
- classCallCheck(this, MergeConcurrently);
- this.f = f;
- this.concurrency = concurrency;
- this.source = source;
- }
- MergeConcurrently.prototype.run = function run(sink, scheduler$$1) {
- return new Outer(this.f, this.concurrency, this.source, sink, scheduler$$1);
- };
- return MergeConcurrently;
- }();
- var Outer = /*#__PURE__*/function () {
- function Outer(f, concurrency, source, sink, scheduler$$1) {
- classCallCheck(this, Outer);
- this.f = f;
- this.concurrency = concurrency;
- this.sink = sink;
- this.scheduler = scheduler$$1;
- this.pending = [];
- this.current = [];
- this.disposable = disposable.disposeOnce(source.run(this, scheduler$$1));
- this.active = true;
- }
- Outer.prototype.event = function event(t, x) {
- this._addInner(t, x);
- };
- Outer.prototype._addInner = function _addInner(t, x) {
- if (this.current.length < this.concurrency) {
- this._startInner(t, x);
- } else {
- this.pending.push(x);
- }
- };
- Outer.prototype._startInner = function _startInner(t, x) {
- try {
- this._initInner(t, x);
- } catch (e) {
- this.error(t, e);
- }
- };
- Outer.prototype._initInner = function _initInner(t, x) {
- var innerSink = new Inner(t, this, this.sink);
- innerSink.disposable = mapAndRun(this.f, t, x, innerSink, this.scheduler);
- this.current.push(innerSink);
- };
- Outer.prototype.end = function end(t) {
- this.active = false;
- disposable.tryDispose(t, this.disposable, this.sink);
- this._checkEnd(t);
- };
- Outer.prototype.error = function error(t, e) {
- this.active = false;
- this.sink.error(t, e);
- };
- Outer.prototype.dispose = function dispose() {
- this.active = false;
- this.pending.length = 0;
- this.disposable.dispose();
- disposable.disposeAll(this.current).dispose();
- };
- Outer.prototype._endInner = function _endInner(t, inner) {
- var i = this.current.indexOf(inner);
- if (i >= 0) {
- this.current.splice(i, 1);
- }
- disposable.tryDispose(t, inner, this);
- if (this.pending.length === 0) {
- this._checkEnd(t);
- } else {
- this._startInner(t, this.pending.shift());
- }
- };
- Outer.prototype._checkEnd = function _checkEnd(t) {
- if (!this.active && this.current.length === 0) {
- this.sink.end(t);
- }
- };
- return Outer;
- }();
- var mapAndRun = function mapAndRun(f, t, x, sink, scheduler$$1) {
- return f(x).run(sink, scheduler.schedulerRelativeTo(t, scheduler$$1));
- };
- var Inner = /*#__PURE__*/function () {
- function Inner(time, outer, sink) {
- classCallCheck(this, Inner);
- this.time = time;
- this.outer = outer;
- this.sink = sink;
- this.disposable = disposable.disposeNone();
- }
- Inner.prototype.event = function event(t, x) {
- this.sink.event(t + this.time, x);
- };
- Inner.prototype.end = function end(t) {
- this.outer._endInner(t + this.time, this);
- };
- Inner.prototype.error = function error(t, e) {
- this.outer.error(t + this.time, e);
- };
- Inner.prototype.dispose = function dispose() {
- return this.disposable.dispose();
- };
- return Inner;
- }();
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Map each value in the stream to a new stream, and merge it into the
- * returned outer stream. Event arrival times are preserved.
- * @param {function(x:*):Stream} f chaining function, must return a Stream
- * @param {Stream} stream
- * @returns {Stream} new stream containing all events from each stream returned by f
- */
- var chain$1 = function chain(f, stream) {
- return mergeMapConcurrently$1(f, Infinity, stream);
- };
- /**
- * Monadic join. Flatten a Stream<Stream<X>> to Stream<X> by merging inner
- * streams to the outer. Event arrival times are preserved.
- * @param {Stream<Stream<X>>} stream stream of streams
- * @returns {Stream<X>} new stream containing all events of all inner streams
- */
- var join = function join(stream) {
- return mergeConcurrently$1(Infinity, stream);
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Map each value in stream to a new stream, and concatenate them all
- * stream: -a---b---cX
- * f(a): 1-1-1-1X
- * f(b): -2-2-2-2X
- * f(c): -3-3-3-3X
- * stream.concatMap(f): -1-1-1-1-2-2-2-2-3-3-3-3X
- * @param {function(x:*):Stream} f function to map each value to a stream
- * @param {Stream} stream
- * @returns {Stream} new stream containing all events from each stream returned by f
- */
- var concatMap$1 = function concatMap(f, stream) {
- return mergeMapConcurrently$1(f, 1, stream);
- };
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * @returns {Stream} stream containing events from two streams in time order.
- * If two events are simultaneous they will be merged in arbitrary order.
- */
- function merge$1(stream1, stream2) {
- return mergeArray([stream1, stream2]);
- }
- /**
- * @param {Array} streams array of stream to merge
- * @returns {Stream} stream containing events from all input observables
- * in time order. If two events are simultaneous they will be merged in
- * arbitrary order.
- */
- var mergeArray = function mergeArray(streams) {
- return mergeStreams(withoutCanonicalEmpty(streams));
- };
- /**
- * This implements fusion/flattening for merge. It will
- * fuse adjacent merge operations. For example:
- * - a.merge(b).merge(c) effectively becomes merge(a, b, c)
- * - merge(a, merge(b, c)) effectively becomes merge(a, b, c)
- * It does this by concatenating the sources arrays of
- * any nested Merge sources, in effect "flattening" nested
- * merge operations into a single merge.
- */
- var mergeStreams = function mergeStreams(streams) {
- return streams.length === 0 ? empty() : streams.length === 1 ? streams[0] : new Merge(prelude.reduce(appendSources, [], streams));
- };
- var withoutCanonicalEmpty = function withoutCanonicalEmpty(streams) {
- return streams.filter(isNotCanonicalEmpty);
- };
- var isNotCanonicalEmpty = function isNotCanonicalEmpty(stream) {
- return !isCanonicalEmpty(stream);
- };
- var appendSources = function appendSources(sources, stream) {
- return sources.concat(stream instanceof Merge ? stream.sources : stream);
- };
- var Merge = /*#__PURE__*/function () {
- function Merge(sources) {
- classCallCheck(this, Merge);
- this.sources = sources;
- }
- Merge.prototype.run = function run(sink, scheduler$$1) {
- var l = this.sources.length;
- var disposables = new Array(l);
- var sinks = new Array(l);
- var mergeSink = new MergeSink(disposables, sinks, sink);
- for (var indexSink, i = 0; i < l; ++i) {
- indexSink = sinks[i] = new IndexSink(i, mergeSink);
- disposables[i] = this.sources[i].run(indexSink, scheduler$$1);
- }
- return disposable.disposeAll(disposables);
- };
- return Merge;
- }();
- var MergeSink = /*#__PURE__*/function (_Pipe) {
- inherits(MergeSink, _Pipe);
- function MergeSink(disposables, sinks, sink) {
- classCallCheck(this, MergeSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.disposables = disposables;
- _this.activeCount = sinks.length;
- return _this;
- }
- MergeSink.prototype.event = function event(t, indexValue) {
- if (!indexValue.active) {
- this._dispose(t, indexValue.index);
- return;
- }
- this.sink.event(t, indexValue.value);
- };
- MergeSink.prototype._dispose = function _dispose(t, index) {
- disposable.tryDispose(t, this.disposables[index], this.sink);
- if (--this.activeCount === 0) {
- this.sink.end(t);
- }
- };
- return MergeSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010 original author or authors */
- var sample$1 = function sample(values, sampler) {
- return snapshot$1(function (x, _) {
- return x;
- }, values, sampler);
- };
- var snapshot$1 = function snapshot(f, values, sampler) {
- return isCanonicalEmpty(sampler) || isCanonicalEmpty(values) ? empty() : new Snapshot(f, values, sampler);
- };
- var Snapshot = /*#__PURE__*/function () {
- function Snapshot(f, values, sampler) {
- classCallCheck(this, Snapshot);
- this.f = f;
- this.values = values;
- this.sampler = sampler;
- }
- Snapshot.prototype.run = function run(sink, scheduler$$1) {
- var sampleSink = new SnapshotSink(this.f, sink);
- var valuesDisposable = this.values.run(sampleSink.latest, scheduler$$1);
- var samplerDisposable = this.sampler.run(sampleSink, scheduler$$1);
- return disposable.disposeBoth(samplerDisposable, valuesDisposable);
- };
- return Snapshot;
- }();
- var SnapshotSink = /*#__PURE__*/function (_Pipe) {
- inherits(SnapshotSink, _Pipe);
- function SnapshotSink(f, sink) {
- classCallCheck(this, SnapshotSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- _this.latest = new LatestValueSink(_this);
- return _this;
- }
- SnapshotSink.prototype.event = function event(t, x) {
- if (this.latest.hasValue) {
- var f = this.f;
- this.sink.event(t, f(this.latest.value, x));
- }
- };
- return SnapshotSink;
- }(Pipe);
- var LatestValueSink = /*#__PURE__*/function (_Pipe2) {
- inherits(LatestValueSink, _Pipe2);
- function LatestValueSink(sink) {
- classCallCheck(this, LatestValueSink);
- var _this2 = possibleConstructorReturn(this, _Pipe2.call(this, sink));
- _this2.hasValue = false;
- return _this2;
- }
- LatestValueSink.prototype.event = function event(t, x) {
- this.value = x;
- this.hasValue = true;
- };
- LatestValueSink.prototype.end = function end() {};
- return LatestValueSink;
- }(Pipe);
- // Copied and modified from https://github.com/invertase/denque
- // MIT License
- // These constants were extracted directly from denque's shift()
- // It's not clear exactly why the authors chose these particular
- // values, but given denque's stated goals, it seems likely that
- // they were chosen for speed/memory reasons.
- // Max value of _head at which Queue is willing to shink
- // its internal array
- var HEAD_MAX_SHRINK = 2;
- // Min value of _tail at which Queue is willing to shink
- // its internal array
- var TAIL_MIN_SHRINK = 10000;
- var Queue = /*#__PURE__*/function () {
- function Queue() {
- classCallCheck(this, Queue);
- this._head = 0;
- this._tail = 0;
- this._capacityMask = 0x3;
- this._list = new Array(4);
- }
- Queue.prototype.push = function push(x) {
- var tail = this._tail;
- this._list[tail] = x;
- this._tail = tail + 1 & this._capacityMask;
- if (this._tail === this._head) {
- this._growArray();
- }
- if (this._head < this._tail) {
- return this._tail - this._head;
- } else {
- return this._capacityMask + 1 - (this._head - this._tail);
- }
- };
- Queue.prototype.shift = function shift() {
- var head = this._head;
- if (head === this._tail) {
- return undefined;
- }
- var x = this._list[head];
- this._list[head] = undefined;
- this._head = head + 1 & this._capacityMask;
- if (head < HEAD_MAX_SHRINK && this._tail > TAIL_MIN_SHRINK && this._tail <= this._list.length >>> 2) {
- this._shrinkArray();
- }
- return x;
- };
- Queue.prototype.isEmpty = function isEmpty() {
- return this._head === this._tail;
- };
- Queue.prototype.length = function length() {
- if (this._head === this._tail) {
- return 0;
- } else if (this._head < this._tail) {
- return this._tail - this._head;
- } else {
- return this._capacityMask + 1 - (this._head - this._tail);
- }
- };
- Queue.prototype._growArray = function _growArray() {
- if (this._head) {
- // copy existing data, head to end, then beginning to tail.
- this._list = this._copyArray();
- this._head = 0;
- }
- // head is at 0 and array is now full, safe to extend
- this._tail = this._list.length;
- this._list.length *= 2;
- this._capacityMask = this._capacityMask << 1 | 1;
- };
- Queue.prototype._shrinkArray = function _shrinkArray() {
- this._list.length >>>= 1;
- this._capacityMask >>>= 1;
- };
- Queue.prototype._copyArray = function _copyArray() {
- var newArray = [];
- var list = this._list;
- var len = list.length;
- var i = void 0;
- for (i = this._head; i < len; i++) {
- newArray.push(list[i]);
- }
- for (i = 0; i < this._tail; i++) {
- newArray.push(list[i]);
- }
- return newArray;
- };
- return Queue;
- }();
- /** @license MIT License (c) copyright 2010 original author or authors */
- /**
- * Combine two streams pairwise by index by applying f to values at corresponding
- * indices. The returned stream ends when either of the input streams ends.
- * @param {function} f function to combine values
- * @returns {Stream} new stream with items at corresponding indices combined
- * using f
- */
- function zip$1(f, stream1, stream2) {
- return zipArray$1(f, [stream1, stream2]);
- }
- /**
- * Combine streams pairwise (or tuple-wise) by index by applying f to values
- * at corresponding indices. The returned stream ends when any of the input
- * streams ends.
- * @param {function} f function to combine values
- * @param {[Stream]} streams streams to zip using f
- * @returns {Stream} new stream with items at corresponding indices combined
- * using f
- */
- var zipArray$1 = function zipArray(f, streams) {
- return streams.length === 0 || containsCanonicalEmpty(streams) ? empty() : streams.length === 1 ? map$2(f, streams[0]) : new Zip(f, streams);
- };
- var Zip = /*#__PURE__*/function () {
- function Zip(f, sources) {
- classCallCheck(this, Zip);
- this.f = f;
- this.sources = sources;
- }
- Zip.prototype.run = function run(sink, scheduler$$1) {
- var l = this.sources.length;
- var disposables = new Array(l);
- var sinks = new Array(l);
- var buffers = new Array(l);
- var zipSink = new ZipSink(this.f, buffers, sinks, sink);
- for (var indexSink, i = 0; i < l; ++i) {
- buffers[i] = new Queue();
- indexSink = sinks[i] = new IndexSink(i, zipSink);
- disposables[i] = this.sources[i].run(indexSink, scheduler$$1);
- }
- return disposable.disposeAll(disposables);
- };
- return Zip;
- }();
- var ZipSink = /*#__PURE__*/function (_Pipe) {
- inherits(ZipSink, _Pipe);
- function ZipSink(f, buffers, sinks, sink) {
- classCallCheck(this, ZipSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.f = f;
- _this.sinks = sinks;
- _this.buffers = buffers;
- return _this;
- }
- ZipSink.prototype.event = function event(t, indexedValue) {
- /* eslint complexity: [1, 5] */
- if (!indexedValue.active) {
- this._dispose(t, indexedValue.index);
- return;
- }
- var buffers = this.buffers;
- var buffer = buffers[indexedValue.index];
- buffer.push(indexedValue.value);
- if (buffer.length() === 1) {
- if (!ready(this.buffers)) {
- return;
- }
- emitZipped(this.f, t, buffers, this.sink);
- if (ended(this.buffers, this.sinks)) {
- this.sink.end(t);
- }
- }
- };
- ZipSink.prototype._dispose = function _dispose(t, index) {
- var buffer = this.buffers[index];
- if (buffer.isEmpty()) {
- this.sink.end(t);
- }
- };
- return ZipSink;
- }(Pipe);
- var emitZipped = function emitZipped(f, t, buffers, sink) {
- return sink.event(t, invoke(f, prelude.map(head, buffers)));
- };
- var head = function head(buffer) {
- return buffer.shift();
- };
- function ended(buffers, sinks) {
- for (var i = 0, l = buffers.length; i < l; ++i) {
- if (buffers[i].isEmpty() && !sinks[i].active) {
- return true;
- }
- }
- return false;
- }
- function ready(buffers) {
- for (var i = 0, l = buffers.length; i < l; ++i) {
- if (buffers[i].isEmpty()) {
- return false;
- }
- }
- return true;
- }
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Given a stream of streams, return a new stream that adopts the behavior
- * of the most recent inner stream.
- * @param {Stream} stream of streams on which to switch
- * @returns {Stream} switching stream
- */
- var switchLatest = function switchLatest(stream) {
- return isCanonicalEmpty(stream) ? empty() : new Switch(stream);
- };
- var Switch = /*#__PURE__*/function () {
- function Switch(source) {
- classCallCheck(this, Switch);
- this.source = source;
- }
- Switch.prototype.run = function run(sink, scheduler$$1) {
- var switchSink = new SwitchSink(sink, scheduler$$1);
- return disposable.disposeBoth(switchSink, this.source.run(switchSink, scheduler$$1));
- };
- return Switch;
- }();
- var SwitchSink = /*#__PURE__*/function () {
- function SwitchSink(sink, scheduler$$1) {
- classCallCheck(this, SwitchSink);
- this.sink = sink;
- this.scheduler = scheduler$$1;
- this.current = null;
- this.ended = false;
- }
- SwitchSink.prototype.event = function event(t, stream) {
- this._disposeCurrent(t);
- this.current = new Segment(stream, t, Infinity, this, this.sink, this.scheduler);
- };
- SwitchSink.prototype.end = function end(t) {
- this.ended = true;
- this._checkEnd(t);
- };
- SwitchSink.prototype.error = function error(t, e) {
- this.ended = true;
- this.sink.error(t, e);
- };
- SwitchSink.prototype.dispose = function dispose() {
- return this._disposeCurrent(scheduler.currentTime(this.scheduler));
- };
- SwitchSink.prototype._disposeCurrent = function _disposeCurrent(t) {
- if (this.current !== null) {
- return this.current._dispose(t);
- }
- };
- SwitchSink.prototype._disposeInner = function _disposeInner(t, inner) {
- inner._dispose(t);
- if (inner === this.current) {
- this.current = null;
- }
- };
- SwitchSink.prototype._checkEnd = function _checkEnd(t) {
- if (this.ended && this.current === null) {
- this.sink.end(t);
- }
- };
- SwitchSink.prototype._endInner = function _endInner(t, inner) {
- this._disposeInner(t, inner);
- this._checkEnd(t);
- };
- SwitchSink.prototype._errorInner = function _errorInner(t, e, inner) {
- this._disposeInner(t, inner);
- this.sink.error(t, e);
- };
- return SwitchSink;
- }();
- var Segment = /*#__PURE__*/function () {
- function Segment(source, min, max, outer, sink, scheduler$$1) {
- classCallCheck(this, Segment);
- this.min = min;
- this.max = max;
- this.outer = outer;
- this.sink = sink;
- this.disposable = source.run(this, scheduler.schedulerRelativeTo(min, scheduler$$1));
- }
- Segment.prototype.event = function event(t, x) {
- var time = Math.max(0, t + this.min);
- if (time < this.max) {
- this.sink.event(time, x);
- }
- };
- Segment.prototype.end = function end(t) {
- this.outer._endInner(t + this.min, this);
- };
- Segment.prototype.error = function error(t, e) {
- this.outer._errorInner(t + this.min, e, this);
- };
- Segment.prototype._dispose = function _dispose(t) {
- disposable.tryDispose(t, this.disposable, this.sink);
- };
- return Segment;
- }();
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Retain only items matching a predicate
- * @param {function(x:*):boolean} p filtering predicate called for each item
- * @param {Stream} stream stream to filter
- * @returns {Stream} stream containing only items for which predicate returns truthy
- */
- var filter$1 = function filter(p, stream) {
- return Filter.create(p, stream);
- };
- /**
- * Skip repeated events, using === to detect duplicates
- * @param {Stream} stream stream from which to omit repeated events
- * @returns {Stream} stream without repeated events
- */
- var skipRepeats = function skipRepeats(stream) {
- return skipRepeatsWith$1(same, stream);
- };
- /**
- * Skip repeated events using the provided equals function to detect duplicates
- * @param {function(a:*, b:*):boolean} equals optional function to compare items
- * @param {Stream} stream stream from which to omit repeated events
- * @returns {Stream} stream without repeated events
- */
- var skipRepeatsWith$1 = function skipRepeatsWith(equals, stream) {
- return isCanonicalEmpty(stream) ? empty() : new SkipRepeats(equals, stream);
- };
- var SkipRepeats = /*#__PURE__*/function () {
- function SkipRepeats(equals, source) {
- classCallCheck(this, SkipRepeats);
- this.equals = equals;
- this.source = source;
- }
- SkipRepeats.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new SkipRepeatsSink(this.equals, sink), scheduler$$1);
- };
- return SkipRepeats;
- }();
- var SkipRepeatsSink = /*#__PURE__*/function (_Pipe) {
- inherits(SkipRepeatsSink, _Pipe);
- function SkipRepeatsSink(equals, sink) {
- classCallCheck(this, SkipRepeatsSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.equals = equals;
- _this.value = void 0;
- _this.init = true;
- return _this;
- }
- SkipRepeatsSink.prototype.event = function event(t, x) {
- if (this.init) {
- this.init = false;
- this.value = x;
- this.sink.event(t, x);
- } else if (!this.equals(this.value, x)) {
- this.value = x;
- this.sink.event(t, x);
- }
- };
- return SkipRepeatsSink;
- }(Pipe);
- function same(a, b) {
- return a === b;
- }
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var until$1 = function until(signal, stream) {
- return new Until(signal, stream);
- };
- var since$1 = function since(signal, stream) {
- return new Since(signal, stream);
- };
- var during$1 = function during(timeWindow, stream) {
- return until$1(join(timeWindow), since$1(timeWindow, stream));
- };
- var Until = /*#__PURE__*/function () {
- function Until(maxSignal, source) {
- classCallCheck(this, Until);
- this.maxSignal = maxSignal;
- this.source = source;
- }
- Until.prototype.run = function run(sink, scheduler$$1) {
- var disposable$$1 = new SettableDisposable();
- var d1 = this.source.run(sink, scheduler$$1);
- var d2 = this.maxSignal.run(new UntilSink(sink, disposable$$1), scheduler$$1);
- disposable$$1.setDisposable(disposable.disposeBoth(d1, d2));
- return disposable$$1;
- };
- return Until;
- }();
- var Since = /*#__PURE__*/function () {
- function Since(minSignal, source) {
- classCallCheck(this, Since);
- this.minSignal = minSignal;
- this.source = source;
- }
- Since.prototype.run = function run(sink, scheduler$$1) {
- var min = new LowerBoundSink(this.minSignal, sink, scheduler$$1);
- var d = this.source.run(new SinceSink(min, sink), scheduler$$1);
- return disposable.disposeBoth(min, d);
- };
- return Since;
- }();
- var SinceSink = /*#__PURE__*/function (_Pipe) {
- inherits(SinceSink, _Pipe);
- function SinceSink(min, sink) {
- classCallCheck(this, SinceSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.min = min;
- return _this;
- }
- SinceSink.prototype.event = function event(t, x) {
- if (this.min.allow) {
- this.sink.event(t, x);
- }
- };
- return SinceSink;
- }(Pipe);
- var LowerBoundSink = /*#__PURE__*/function (_Pipe2) {
- inherits(LowerBoundSink, _Pipe2);
- function LowerBoundSink(signal, sink, scheduler$$1) {
- classCallCheck(this, LowerBoundSink);
- var _this2 = possibleConstructorReturn(this, _Pipe2.call(this, sink));
- _this2.allow = false;
- _this2.disposable = signal.run(_this2, scheduler$$1);
- return _this2;
- }
- LowerBoundSink.prototype.event = function event() /* t, x */{
- this.allow = true;
- this.dispose();
- };
- LowerBoundSink.prototype.end = function end() {};
- LowerBoundSink.prototype.dispose = function dispose() {
- this.disposable.dispose();
- };
- return LowerBoundSink;
- }(Pipe);
- var UntilSink = /*#__PURE__*/function (_Pipe3) {
- inherits(UntilSink, _Pipe3);
- function UntilSink(sink, disposable$$1) {
- classCallCheck(this, UntilSink);
- var _this3 = possibleConstructorReturn(this, _Pipe3.call(this, sink));
- _this3.disposable = disposable$$1;
- return _this3;
- }
- UntilSink.prototype.event = function event(t, x) {
- this.disposable.dispose();
- this.sink.end(t);
- };
- UntilSink.prototype.end = function end() {};
- return UntilSink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * @param {Number} delayTime milliseconds to delay each item
- * @param {Stream} stream
- * @returns {Stream} new stream containing the same items, but delayed by ms
- */
- var delay$2 = function delay$$1(delayTime, stream) {
- return delayTime <= 0 ? stream : new Delay(delayTime, stream);
- };
- var Delay = /*#__PURE__*/function () {
- function Delay(dt, source) {
- classCallCheck(this, Delay);
- this.dt = dt;
- this.source = source;
- }
- Delay.prototype.run = function run(sink, scheduler$$1) {
- var delaySink = new DelaySink(this.dt, sink, scheduler$$1);
- return disposable.disposeBoth(delaySink, this.source.run(delaySink, scheduler$$1));
- };
- return Delay;
- }();
- var DelaySink = /*#__PURE__*/function (_Pipe) {
- inherits(DelaySink, _Pipe);
- function DelaySink(dt, sink, scheduler$$1) {
- classCallCheck(this, DelaySink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.dt = dt;
- _this.scheduler = scheduler$$1;
- _this.tasks = [];
- return _this;
- }
- DelaySink.prototype.dispose = function dispose() {
- this.tasks.forEach(scheduler.cancelTask);
- };
- DelaySink.prototype.event = function event(t, x) {
- this.tasks.push(scheduler.delay(this.dt, propagateEventTask$1(x, this.sink), this.scheduler));
- };
- DelaySink.prototype.end = function end(t) {
- this.tasks.push(scheduler.delay(this.dt, propagateEndTask(this.sink), this.scheduler));
- };
- return DelaySink;
- }(Pipe);
- /** @license MIT License (c) copyright 2010-2017 original author or authors */
- /**
- * Limit the rate of events by suppressing events that occur too often
- * @param {Number} period time to suppress events
- * @param {Stream} stream
- * @returns {Stream}
- */
- var throttle$1 = function throttle(period, stream) {
- return isCanonicalEmpty(stream) ? empty() : stream instanceof Map ? commuteMapThrottle(period, stream) : stream instanceof Throttle ? fuseThrottle(period, stream) : new Throttle(period, stream);
- };
- var commuteMapThrottle = function commuteMapThrottle(period, mapStream) {
- return Map.create(mapStream.f, throttle$1(period, mapStream.source));
- };
- var fuseThrottle = function fuseThrottle(period, throttleStream) {
- return new Throttle(Math.max(period, throttleStream.period), throttleStream.source);
- };
- var Throttle = /*#__PURE__*/function () {
- function Throttle(period, source) {
- classCallCheck(this, Throttle);
- this.period = period;
- this.source = source;
- }
- Throttle.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new ThrottleSink(this.period, sink), scheduler$$1);
- };
- return Throttle;
- }();
- var ThrottleSink = /*#__PURE__*/function (_Pipe) {
- inherits(ThrottleSink, _Pipe);
- function ThrottleSink(period, sink) {
- classCallCheck(this, ThrottleSink);
- var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
- _this.time = 0;
- _this.period = period;
- return _this;
- }
- ThrottleSink.prototype.event = function event(t, x) {
- if (t >= this.time) {
- this.time = t + this.period;
- this.sink.event(t, x);
- }
- };
- return ThrottleSink;
- }(Pipe);
- /**
- * Wait for a burst of events to subside and emit only the last event in the burst
- * @param {Number} period events occuring more frequently than this
- * will be suppressed
- * @param {Stream} stream stream to debounce
- * @returns {Stream} new debounced stream
- */
- var debounce$1 = function debounce(period, stream) {
- return isCanonicalEmpty(stream) ? empty() : new Debounce(period, stream);
- };
- var Debounce = /*#__PURE__*/function () {
- function Debounce(dt, source) {
- classCallCheck(this, Debounce);
- this.dt = dt;
- this.source = source;
- }
- Debounce.prototype.run = function run(sink, scheduler$$1) {
- return new DebounceSink(this.dt, this.source, sink, scheduler$$1);
- };
- return Debounce;
- }();
- var DebounceSink = /*#__PURE__*/function () {
- function DebounceSink(dt, source, sink, scheduler$$1) {
- classCallCheck(this, DebounceSink);
- this.dt = dt;
- this.sink = sink;
- this.scheduler = scheduler$$1;
- this.value = void 0;
- this.timer = null;
- this.disposable = source.run(this, scheduler$$1);
- }
- DebounceSink.prototype.event = function event(t, x) {
- this._clearTimer();
- this.value = x;
- this.timer = scheduler.delay(this.dt, new DebounceTask(this, x), this.scheduler);
- };
- DebounceSink.prototype._event = function _event(t, x) {
- this._clearTimer();
- this.sink.event(t, x);
- };
- DebounceSink.prototype.end = function end(t) {
- if (this._clearTimer()) {
- this.sink.event(t, this.value);
- this.value = undefined;
- }
- this.sink.end(t);
- };
- DebounceSink.prototype.error = function error(t, x) {
- this._clearTimer();
- this.sink.error(t, x);
- };
- DebounceSink.prototype.dispose = function dispose() {
- this._clearTimer();
- this.disposable.dispose();
- };
- DebounceSink.prototype._clearTimer = function _clearTimer() {
- if (this.timer === null) {
- return false;
- }
- this.timer.dispose();
- this.timer = null;
- return true;
- };
- return DebounceSink;
- }();
- var DebounceTask = /*#__PURE__*/function () {
- function DebounceTask(debounce, value) {
- classCallCheck(this, DebounceTask);
- this.debounce = debounce;
- this.value = value;
- }
- DebounceTask.prototype.run = function run(t) {
- this.debounce._event(t, this.value);
- };
- DebounceTask.prototype.error = function error(t, e) {
- this.debounce.error(t, e);
- };
- DebounceTask.prototype.dispose = function dispose() {};
- return DebounceTask;
- }();
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * Turn a Stream<Promise<T>> into Stream<T> by awaiting each promise.
- * Event order is preserved. The stream will fail if any promise rejects.
- */
- var awaitPromises = function awaitPromises(stream) {
- return isCanonicalEmpty(stream) ? empty() : new Await(stream);
- };
- /**
- * Create a stream containing only the promise's fulfillment
- * value at the time it fulfills.
- * @param {Promise<T>} p promise
- * @return {Stream<T>} stream containing promise's fulfillment value.
- * If the promise rejects, the stream will error
- */
- var fromPromise = /*#__PURE__*/prelude.compose(awaitPromises, now);
- var Await = /*#__PURE__*/function () {
- function Await(source) {
- classCallCheck(this, Await);
- this.source = source;
- }
- Await.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(new AwaitSink(sink, scheduler$$1), scheduler$$1);
- };
- return Await;
- }();
- var AwaitSink = /*#__PURE__*/function () {
- function AwaitSink(sink, scheduler$$1) {
- var _this = this;
- classCallCheck(this, AwaitSink);
- this.sink = sink;
- this.scheduler = scheduler$$1;
- this.queue = Promise.resolve();
- // Pre-create closures, to avoid creating them per event
- this._eventBound = function (x) {
- return _this.sink.event(scheduler.currentTime(_this.scheduler), x);
- };
- this._endBound = function () {
- return _this.sink.end(scheduler.currentTime(_this.scheduler));
- };
- this._errorBound = function (e) {
- return _this.sink.error(scheduler.currentTime(_this.scheduler), e);
- };
- }
- AwaitSink.prototype.event = function event(t, promise) {
- var _this2 = this;
- this.queue = this.queue.then(function () {
- return _this2._event(promise);
- }).catch(this._errorBound);
- };
- AwaitSink.prototype.end = function end(t) {
- this.queue = this.queue.then(this._endBound).catch(this._errorBound);
- };
- AwaitSink.prototype.error = function error(t, e) {
- var _this3 = this;
- // Don't resolve error values, propagate directly
- this.queue = this.queue.then(function () {
- return _this3._errorBound(e);
- }).catch(fatalError);
- };
- AwaitSink.prototype._event = function _event(promise) {
- return promise.then(this._eventBound);
- };
- return AwaitSink;
- }();
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- var SafeSink = /*#__PURE__*/function () {
- function SafeSink(sink) {
- classCallCheck(this, SafeSink);
- this.sink = sink;
- this.active = true;
- }
- SafeSink.prototype.event = function event(t, x) {
- if (!this.active) {
- return;
- }
- this.sink.event(t, x);
- };
- SafeSink.prototype.end = function end(t, x) {
- if (!this.active) {
- return;
- }
- this.disable();
- this.sink.end(t, x);
- };
- SafeSink.prototype.error = function error(t, e) {
- this.disable();
- this.sink.error(t, e);
- };
- SafeSink.prototype.disable = function disable() {
- this.active = false;
- return this.sink;
- };
- return SafeSink;
- }();
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- function tryEvent(t, x, sink) {
- try {
- sink.event(t, x);
- } catch (e) {
- sink.error(t, e);
- }
- }
- function tryEnd(t, sink) {
- try {
- sink.end(t);
- } catch (e) {
- sink.error(t, e);
- }
- }
- /** @license MIT License (c) copyright 2010-2016 original author or authors */
- /** @author Brian Cavalier */
- /** @author John Hann */
- /**
- * If stream encounters an error, recover and continue with items from stream
- * returned by f.
- * @param {function(error:*):Stream} f function which returns a new stream
- * @param {Stream} stream
- * @returns {Stream} new stream which will recover from an error by calling f
- */
- var recoverWith$1 = function recoverWith(f, stream) {
- return isCanonicalEmpty(stream) ? empty() : new RecoverWith(f, stream);
- };
- /**
- * Create a stream containing only an error
- * @param {*} e error value, preferably an Error or Error subtype
- * @returns {Stream} new stream containing only an error
- */
- var throwError = function throwError(e) {
- return new ErrorStream(e);
- };
- var ErrorStream = /*#__PURE__*/function () {
- function ErrorStream(e) {
- classCallCheck(this, ErrorStream);
- this.value = e;
- }
- ErrorStream.prototype.run = function run(sink, scheduler$$1) {
- return scheduler.asap(propagateErrorTask$1(this.value, sink), scheduler$$1);
- };
- return ErrorStream;
- }();
- var RecoverWith = /*#__PURE__*/function () {
- function RecoverWith(f, source) {
- classCallCheck(this, RecoverWith);
- this.f = f;
- this.source = source;
- }
- RecoverWith.prototype.run = function run(sink, scheduler$$1) {
- return new RecoverWithSink(this.f, this.source, sink, scheduler$$1);
- };
- return RecoverWith;
- }();
- var RecoverWithSink = /*#__PURE__*/function () {
- function RecoverWithSink(f, source, sink, scheduler$$1) {
- classCallCheck(this, RecoverWithSink);
- this.f = f;
- this.sink = new SafeSink(sink);
- this.scheduler = scheduler$$1;
- this.disposable = source.run(this, scheduler$$1);
- }
- RecoverWithSink.prototype.event = function event(t, x) {
- tryEvent(t, x, this.sink);
- };
- RecoverWithSink.prototype.end = function end(t) {
- tryEnd(t, this.sink);
- };
- RecoverWithSink.prototype.error = function error(t, e) {
- var nextSink = this.sink.disable();
- disposable.tryDispose(t, this.disposable, this.sink);
- this._startNext(t, e, nextSink);
- };
- RecoverWithSink.prototype._startNext = function _startNext(t, x, sink) {
- try {
- this.disposable = this._continue(this.f, t, x, sink);
- } catch (e) {
- sink.error(t, e);
- }
- };
- RecoverWithSink.prototype._continue = function _continue(f, t, x, sink) {
- return run$1(sink, this.scheduler, withLocalTime$1(t, f(x)));
- };
- RecoverWithSink.prototype.dispose = function dispose() {
- return this.disposable.dispose();
- };
- return RecoverWithSink;
- }();
- var multicast = function multicast(stream) {
- return stream instanceof Multicast || isCanonicalEmpty(stream) ? stream : new Multicast(stream);
- };
- var Multicast = /*#__PURE__*/function () {
- function Multicast(source) {
- classCallCheck(this, Multicast);
- this.source = new MulticastSource(source);
- }
- Multicast.prototype.run = function run(sink, scheduler$$1) {
- return this.source.run(sink, scheduler$$1);
- };
- return Multicast;
- }();
- var MulticastSource = /*#__PURE__*/function () {
- function MulticastSource(source) {
- classCallCheck(this, MulticastSource);
- this.source = source;
- this.sinks = [];
- this.disposable = disposable.disposeNone();
- }
- MulticastSource.prototype.run = function run(sink, scheduler$$1) {
- var n = this.add(sink);
- if (n === 1) {
- this.disposable = this.source.run(this, scheduler$$1);
- }
- return disposable.disposeOnce(new MulticastDisposable(this, sink));
- };
- MulticastSource.prototype.dispose = function dispose() {
- var disposable$$1 = this.disposable;
- this.disposable = disposable.disposeNone();
- return disposable$$1.dispose();
- };
- MulticastSource.prototype.add = function add(sink) {
- this.sinks = prelude.append(sink, this.sinks);
- return this.sinks.length;
- };
- MulticastSource.prototype.remove = function remove$$1(sink) {
- var i = prelude.findIndex(sink, this.sinks);
- // istanbul ignore next
- if (i >= 0) {
- this.sinks = prelude.remove(i, this.sinks);
- }
- return this.sinks.length;
- };
- MulticastSource.prototype.event = function event(time, value) {
- var s = this.sinks;
- if (s.length === 1) {
- return s[0].event(time, value);
- }
- for (var i = 0; i < s.length; ++i) {
- tryEvent(time, value, s[i]);
- }
- };
- MulticastSource.prototype.end = function end(time) {
- var s = this.sinks;
- for (var i = 0; i < s.length; ++i) {
- tryEnd(time, s[i]);
- }
- };
- MulticastSource.prototype.error = function error(time, err) {
- var s = this.sinks;
- for (var i = 0; i < s.length; ++i) {
- s[i].error(time, err);
- }
- };
- return MulticastSource;
- }();
- var MulticastDisposable = /*#__PURE__*/function () {
- function MulticastDisposable(source, sink) {
- classCallCheck(this, MulticastDisposable);
- this.source = source;
- this.sink = sink;
- }
- MulticastDisposable.prototype.dispose = function dispose() {
- if (this.source.remove(this.sink) === 0) {
- this.source.dispose();
- }
- };
- return MulticastDisposable;
- }();
- /** @license MIT License (c) copyright 2016 original author or authors */
- /* eslint-disable import/first */
- var zipItems$$1 = /*#__PURE__*/prelude.curry3(zipItems$1);
- var withItems$$1 = /*#__PURE__*/prelude.curry2(withItems$1);
- // -----------------------------------------------------------------------
- // Observing
- var runEffects$$1 = /*#__PURE__*/prelude.curry2(runEffects$1);
- var run$$1 = /*#__PURE__*/prelude.curry3(run$1);
- // -------------------------------------------------------
- var withLocalTime$$1 = /*#__PURE__*/prelude.curry2(withLocalTime$1);
- // -------------------------------------------------------
- var loop$$1 = /*#__PURE__*/prelude.curry3(loop$1);
- // -------------------------------------------------------
- var scan$$1 = /*#__PURE__*/prelude.curry3(scan$1);
- // -----------------------------------------------------------------------
- // Extending
- var startWith$$1 = /*#__PURE__*/prelude.curry2(startWith$1);
- // -----------------------------------------------------------------------
- // Transforming
- var map$1 = /*#__PURE__*/prelude.curry2(map$2);
- var constant$$1 = /*#__PURE__*/prelude.curry2(constant$1);
- var tap$$1 = /*#__PURE__*/prelude.curry2(tap$1);
- var ap$$1 = /*#__PURE__*/prelude.curry2(ap$1);
- // -----------------------------------------------------------------------
- // FlatMapping
- var chain$$1 = /*#__PURE__*/prelude.curry2(chain$1);
- var continueWith$$1 = /*#__PURE__*/prelude.curry2(continueWith$1);
- var concatMap$$1 = /*#__PURE__*/prelude.curry2(concatMap$1);
- // -----------------------------------------------------------------------
- // Concurrent merging
- var mergeConcurrently$$1 = /*#__PURE__*/prelude.curry2(mergeConcurrently$1);
- var mergeMapConcurrently$$1 = /*#__PURE__*/prelude.curry3(mergeMapConcurrently$1);
- // -----------------------------------------------------------------------
- // Merging
- var merge$$1 = /*#__PURE__*/prelude.curry2(merge$1);
- // -----------------------------------------------------------------------
- // Combining
- var combine$$1 = /*#__PURE__*/prelude.curry3(combine$1);
- var combineArray$$1 = /*#__PURE__*/prelude.curry2(combineArray$1);
- // -----------------------------------------------------------------------
- // Sampling
- var sample$$1 = /*#__PURE__*/prelude.curry2(sample$1);
- var snapshot$$1 = /*#__PURE__*/prelude.curry3(snapshot$1);
- // -----------------------------------------------------------------------
- // Zipping
- var zip$$1 = /*#__PURE__*/prelude.curry3(zip$1);
- var zipArray$$1 = /*#__PURE__*/prelude.curry2(zipArray$1);
- // -----------------------------------------------------------------------
- // Filtering
- var filter$$1 = /*#__PURE__*/prelude.curry2(filter$1);
- var skipRepeatsWith$$1 = /*#__PURE__*/prelude.curry2(skipRepeatsWith$1);
- // -----------------------------------------------------------------------
- // Slicing
- var take$$1 = /*#__PURE__*/prelude.curry2(take$1);
- var skip$$1 = /*#__PURE__*/prelude.curry2(skip$1);
- var slice$$1 = /*#__PURE__*/prelude.curry3(slice$1);
- var takeWhile$$1 = /*#__PURE__*/prelude.curry2(takeWhile$1);
- var skipWhile$$1 = /*#__PURE__*/prelude.curry2(skipWhile$1);
- var skipAfter$$1 = /*#__PURE__*/prelude.curry2(skipAfter$1);
- // -----------------------------------------------------------------------
- // Time slicing
- var until$$1 = /*#__PURE__*/prelude.curry2(until$1);
- var since$$1 = /*#__PURE__*/prelude.curry2(since$1);
- var during$$1 = /*#__PURE__*/prelude.curry2(during$1);
- // -----------------------------------------------------------------------
- // Delaying
- var delay$1 = /*#__PURE__*/prelude.curry2(delay$2);
- // -----------------------------------------------------------------------
- // Rate limiting
- var throttle$$1 = /*#__PURE__*/prelude.curry2(throttle$1);
- var debounce$$1 = /*#__PURE__*/prelude.curry2(debounce$1);
- // -----------------------------------------------------------------------
- // Error handling
- var recoverWith$$1 = /*#__PURE__*/prelude.curry2(recoverWith$1);
- // ----------------------------------------------------------------------
- var propagateTask$$1 = /*#__PURE__*/prelude.curry3(propagateTask$1);
- var propagateEventTask$$1 = /*#__PURE__*/prelude.curry2(propagateEventTask$1);
- var propagateErrorTask$$1 = /*#__PURE__*/prelude.curry2(propagateErrorTask$1);
- exports.zipItems = zipItems$$1;
- exports.withItems = withItems$$1;
- exports.runEffects = runEffects$$1;
- exports.run = run$$1;
- exports.withLocalTime = withLocalTime$$1;
- exports.loop = loop$$1;
- exports.scan = scan$$1;
- exports.startWith = startWith$$1;
- exports.map = map$1;
- exports.constant = constant$$1;
- exports.tap = tap$$1;
- exports.ap = ap$$1;
- exports.chain = chain$$1;
- exports.join = join;
- exports.continueWith = continueWith$$1;
- exports.concatMap = concatMap$$1;
- exports.mergeConcurrently = mergeConcurrently$$1;
- exports.mergeMapConcurrently = mergeMapConcurrently$$1;
- exports.merge = merge$$1;
- exports.mergeArray = mergeArray;
- exports.combine = combine$$1;
- exports.combineArray = combineArray$$1;
- exports.sample = sample$$1;
- exports.snapshot = snapshot$$1;
- exports.zip = zip$$1;
- exports.zipArray = zipArray$$1;
- exports.filter = filter$$1;
- exports.skipRepeats = skipRepeats;
- exports.skipRepeatsWith = skipRepeatsWith$$1;
- exports.take = take$$1;
- exports.skip = skip$$1;
- exports.slice = slice$$1;
- exports.takeWhile = takeWhile$$1;
- exports.skipWhile = skipWhile$$1;
- exports.skipAfter = skipAfter$$1;
- exports.until = until$$1;
- exports.since = since$$1;
- exports.during = during$$1;
- exports.delay = delay$1;
- exports.throttle = throttle$$1;
- exports.debounce = debounce$$1;
- exports.recoverWith = recoverWith$$1;
- exports.throwError = throwError;
- exports.propagateTask = propagateTask$$1;
- exports.propagateEventTask = propagateEventTask$$1;
- exports.propagateErrorTask = propagateErrorTask$$1;
- exports.propagateEndTask = propagateEndTask;
- exports.empty = empty;
- exports.never = never;
- exports.now = now;
- exports.at = at;
- exports.periodic = periodic$1;
- exports.newStream = newStream;
- exports.switchLatest = switchLatest;
- exports.fromPromise = fromPromise;
- exports.awaitPromises = awaitPromises;
- exports.multicast = multicast;
- exports.MulticastSource = MulticastSource;
- Object.defineProperty(exports, '__esModule', { value: true });
- })));
- //# sourceMappingURL=index.js.map
|