rxjs-compat.umd.js 357 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define('rxjs', ['exports'], factory) :
  4. (factory((global.rxjs = {})));
  5. }(this, (function (exports) { 'use strict';
  6. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation. All rights reserved.
  8. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  9. this file except in compliance with the License. You may obtain a copy of the
  10. License at http://www.apache.org/licenses/LICENSE-2.0
  11. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  13. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  14. MERCHANTABLITY OR NON-INFRINGEMENT.
  15. See the Apache Version 2.0 License for specific language governing permissions
  16. and limitations under the License.
  17. ***************************************************************************** */
  18. /* global Reflect, Promise */
  19. var extendStatics = Object.setPrototypeOf ||
  20. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  21. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  22. function __extends(d, b) {
  23. extendStatics(d, b);
  24. function __() { this.constructor = d; }
  25. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  26. }
  27. var __assign = Object.assign || function __assign(t) {
  28. for (var s, i = 1, n = arguments.length; i < n; i++) {
  29. s = arguments[i];
  30. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  31. }
  32. return t;
  33. };
  34. function isFunction(x) {
  35. return typeof x === 'function';
  36. }
  37. var _enable_super_gross_mode_that_will_cause_bad_things = false;
  38. var config = {
  39. Promise: undefined,
  40. set useDeprecatedSynchronousErrorHandling(value) {
  41. if (value) {
  42. var error = new Error();
  43. console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
  44. }
  45. else if (_enable_super_gross_mode_that_will_cause_bad_things) {
  46. console.log('RxJS: Back to a better error behavior. Thank you. <3');
  47. }
  48. _enable_super_gross_mode_that_will_cause_bad_things = value;
  49. },
  50. get useDeprecatedSynchronousErrorHandling() {
  51. return _enable_super_gross_mode_that_will_cause_bad_things;
  52. },
  53. };
  54. function hostReportError(err) {
  55. setTimeout(function () { throw err; }, 0);
  56. }
  57. var empty = {
  58. closed: true,
  59. next: function (value) { },
  60. error: function (err) {
  61. if (config.useDeprecatedSynchronousErrorHandling) {
  62. throw err;
  63. }
  64. else {
  65. hostReportError(err);
  66. }
  67. },
  68. complete: function () { }
  69. };
  70. var isArray = (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();
  71. function isObject(x) {
  72. return x !== null && typeof x === 'object';
  73. }
  74. var UnsubscriptionErrorImpl = (function () {
  75. function UnsubscriptionErrorImpl(errors) {
  76. Error.call(this);
  77. this.message = errors ?
  78. errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : '';
  79. this.name = 'UnsubscriptionError';
  80. this.errors = errors;
  81. return this;
  82. }
  83. UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype);
  84. return UnsubscriptionErrorImpl;
  85. })();
  86. var UnsubscriptionError = UnsubscriptionErrorImpl;
  87. var Subscription = (function () {
  88. function Subscription(unsubscribe) {
  89. this.closed = false;
  90. this._parentOrParents = null;
  91. this._subscriptions = null;
  92. if (unsubscribe) {
  93. this._unsubscribe = unsubscribe;
  94. }
  95. }
  96. Subscription.prototype.unsubscribe = function () {
  97. var errors;
  98. if (this.closed) {
  99. return;
  100. }
  101. var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
  102. this.closed = true;
  103. this._parentOrParents = null;
  104. this._subscriptions = null;
  105. if (_parentOrParents instanceof Subscription) {
  106. _parentOrParents.remove(this);
  107. }
  108. else if (_parentOrParents !== null) {
  109. for (var index = 0; index < _parentOrParents.length; ++index) {
  110. var parent_1 = _parentOrParents[index];
  111. parent_1.remove(this);
  112. }
  113. }
  114. if (isFunction(_unsubscribe)) {
  115. try {
  116. _unsubscribe.call(this);
  117. }
  118. catch (e) {
  119. errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
  120. }
  121. }
  122. if (isArray(_subscriptions)) {
  123. var index = -1;
  124. var len = _subscriptions.length;
  125. while (++index < len) {
  126. var sub = _subscriptions[index];
  127. if (isObject(sub)) {
  128. try {
  129. sub.unsubscribe();
  130. }
  131. catch (e) {
  132. errors = errors || [];
  133. if (e instanceof UnsubscriptionError) {
  134. errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
  135. }
  136. else {
  137. errors.push(e);
  138. }
  139. }
  140. }
  141. }
  142. }
  143. if (errors) {
  144. throw new UnsubscriptionError(errors);
  145. }
  146. };
  147. Subscription.prototype.add = function (teardown) {
  148. var subscription = teardown;
  149. if (!teardown) {
  150. return Subscription.EMPTY;
  151. }
  152. switch (typeof teardown) {
  153. case 'function':
  154. subscription = new Subscription(teardown);
  155. case 'object':
  156. if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
  157. return subscription;
  158. }
  159. else if (this.closed) {
  160. subscription.unsubscribe();
  161. return subscription;
  162. }
  163. else if (!(subscription instanceof Subscription)) {
  164. var tmp = subscription;
  165. subscription = new Subscription();
  166. subscription._subscriptions = [tmp];
  167. }
  168. break;
  169. default: {
  170. throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
  171. }
  172. }
  173. var _parentOrParents = subscription._parentOrParents;
  174. if (_parentOrParents === null) {
  175. subscription._parentOrParents = this;
  176. }
  177. else if (_parentOrParents instanceof Subscription) {
  178. if (_parentOrParents === this) {
  179. return subscription;
  180. }
  181. subscription._parentOrParents = [_parentOrParents, this];
  182. }
  183. else if (_parentOrParents.indexOf(this) === -1) {
  184. _parentOrParents.push(this);
  185. }
  186. else {
  187. return subscription;
  188. }
  189. var subscriptions = this._subscriptions;
  190. if (subscriptions === null) {
  191. this._subscriptions = [subscription];
  192. }
  193. else {
  194. subscriptions.push(subscription);
  195. }
  196. return subscription;
  197. };
  198. Subscription.prototype.remove = function (subscription) {
  199. var subscriptions = this._subscriptions;
  200. if (subscriptions) {
  201. var subscriptionIndex = subscriptions.indexOf(subscription);
  202. if (subscriptionIndex !== -1) {
  203. subscriptions.splice(subscriptionIndex, 1);
  204. }
  205. }
  206. };
  207. Subscription.EMPTY = (function (empty) {
  208. empty.closed = true;
  209. return empty;
  210. }(new Subscription()));
  211. return Subscription;
  212. }());
  213. function flattenUnsubscriptionErrors(errors) {
  214. return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
  215. }
  216. var rxSubscriber = (function () {
  217. return typeof Symbol === 'function'
  218. ? Symbol('rxSubscriber')
  219. : '@@rxSubscriber_' + Math.random();
  220. })();
  221. var Subscriber = (function (_super) {
  222. __extends(Subscriber, _super);
  223. function Subscriber(destinationOrNext, error, complete) {
  224. var _this = _super.call(this) || this;
  225. _this.syncErrorValue = null;
  226. _this.syncErrorThrown = false;
  227. _this.syncErrorThrowable = false;
  228. _this.isStopped = false;
  229. switch (arguments.length) {
  230. case 0:
  231. _this.destination = empty;
  232. break;
  233. case 1:
  234. if (!destinationOrNext) {
  235. _this.destination = empty;
  236. break;
  237. }
  238. if (typeof destinationOrNext === 'object') {
  239. if (destinationOrNext instanceof Subscriber) {
  240. _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
  241. _this.destination = destinationOrNext;
  242. destinationOrNext.add(_this);
  243. }
  244. else {
  245. _this.syncErrorThrowable = true;
  246. _this.destination = new SafeSubscriber(_this, destinationOrNext);
  247. }
  248. break;
  249. }
  250. default:
  251. _this.syncErrorThrowable = true;
  252. _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
  253. break;
  254. }
  255. return _this;
  256. }
  257. Subscriber.prototype[rxSubscriber] = function () { return this; };
  258. Subscriber.create = function (next, error, complete) {
  259. var subscriber = new Subscriber(next, error, complete);
  260. subscriber.syncErrorThrowable = false;
  261. return subscriber;
  262. };
  263. Subscriber.prototype.next = function (value) {
  264. if (!this.isStopped) {
  265. this._next(value);
  266. }
  267. };
  268. Subscriber.prototype.error = function (err) {
  269. if (!this.isStopped) {
  270. this.isStopped = true;
  271. this._error(err);
  272. }
  273. };
  274. Subscriber.prototype.complete = function () {
  275. if (!this.isStopped) {
  276. this.isStopped = true;
  277. this._complete();
  278. }
  279. };
  280. Subscriber.prototype.unsubscribe = function () {
  281. if (this.closed) {
  282. return;
  283. }
  284. this.isStopped = true;
  285. _super.prototype.unsubscribe.call(this);
  286. };
  287. Subscriber.prototype._next = function (value) {
  288. this.destination.next(value);
  289. };
  290. Subscriber.prototype._error = function (err) {
  291. this.destination.error(err);
  292. this.unsubscribe();
  293. };
  294. Subscriber.prototype._complete = function () {
  295. this.destination.complete();
  296. this.unsubscribe();
  297. };
  298. Subscriber.prototype._unsubscribeAndRecycle = function () {
  299. var _parentOrParents = this._parentOrParents;
  300. this._parentOrParents = null;
  301. this.unsubscribe();
  302. this.closed = false;
  303. this.isStopped = false;
  304. this._parentOrParents = _parentOrParents;
  305. return this;
  306. };
  307. return Subscriber;
  308. }(Subscription));
  309. var SafeSubscriber = (function (_super) {
  310. __extends(SafeSubscriber, _super);
  311. function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
  312. var _this = _super.call(this) || this;
  313. _this._parentSubscriber = _parentSubscriber;
  314. var next;
  315. var context = _this;
  316. if (isFunction(observerOrNext)) {
  317. next = observerOrNext;
  318. }
  319. else if (observerOrNext) {
  320. next = observerOrNext.next;
  321. error = observerOrNext.error;
  322. complete = observerOrNext.complete;
  323. if (observerOrNext !== empty) {
  324. context = Object.create(observerOrNext);
  325. if (isFunction(context.unsubscribe)) {
  326. _this.add(context.unsubscribe.bind(context));
  327. }
  328. context.unsubscribe = _this.unsubscribe.bind(_this);
  329. }
  330. }
  331. _this._context = context;
  332. _this._next = next;
  333. _this._error = error;
  334. _this._complete = complete;
  335. return _this;
  336. }
  337. SafeSubscriber.prototype.next = function (value) {
  338. if (!this.isStopped && this._next) {
  339. var _parentSubscriber = this._parentSubscriber;
  340. if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
  341. this.__tryOrUnsub(this._next, value);
  342. }
  343. else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
  344. this.unsubscribe();
  345. }
  346. }
  347. };
  348. SafeSubscriber.prototype.error = function (err) {
  349. if (!this.isStopped) {
  350. var _parentSubscriber = this._parentSubscriber;
  351. var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
  352. if (this._error) {
  353. if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
  354. this.__tryOrUnsub(this._error, err);
  355. this.unsubscribe();
  356. }
  357. else {
  358. this.__tryOrSetError(_parentSubscriber, this._error, err);
  359. this.unsubscribe();
  360. }
  361. }
  362. else if (!_parentSubscriber.syncErrorThrowable) {
  363. this.unsubscribe();
  364. if (useDeprecatedSynchronousErrorHandling) {
  365. throw err;
  366. }
  367. hostReportError(err);
  368. }
  369. else {
  370. if (useDeprecatedSynchronousErrorHandling) {
  371. _parentSubscriber.syncErrorValue = err;
  372. _parentSubscriber.syncErrorThrown = true;
  373. }
  374. else {
  375. hostReportError(err);
  376. }
  377. this.unsubscribe();
  378. }
  379. }
  380. };
  381. SafeSubscriber.prototype.complete = function () {
  382. var _this = this;
  383. if (!this.isStopped) {
  384. var _parentSubscriber = this._parentSubscriber;
  385. if (this._complete) {
  386. var wrappedComplete = function () { return _this._complete.call(_this._context); };
  387. if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
  388. this.__tryOrUnsub(wrappedComplete);
  389. this.unsubscribe();
  390. }
  391. else {
  392. this.__tryOrSetError(_parentSubscriber, wrappedComplete);
  393. this.unsubscribe();
  394. }
  395. }
  396. else {
  397. this.unsubscribe();
  398. }
  399. }
  400. };
  401. SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
  402. try {
  403. fn.call(this._context, value);
  404. }
  405. catch (err) {
  406. this.unsubscribe();
  407. if (config.useDeprecatedSynchronousErrorHandling) {
  408. throw err;
  409. }
  410. else {
  411. hostReportError(err);
  412. }
  413. }
  414. };
  415. SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
  416. if (!config.useDeprecatedSynchronousErrorHandling) {
  417. throw new Error('bad call');
  418. }
  419. try {
  420. fn.call(this._context, value);
  421. }
  422. catch (err) {
  423. if (config.useDeprecatedSynchronousErrorHandling) {
  424. parent.syncErrorValue = err;
  425. parent.syncErrorThrown = true;
  426. return true;
  427. }
  428. else {
  429. hostReportError(err);
  430. return true;
  431. }
  432. }
  433. return false;
  434. };
  435. SafeSubscriber.prototype._unsubscribe = function () {
  436. var _parentSubscriber = this._parentSubscriber;
  437. this._context = null;
  438. this._parentSubscriber = null;
  439. _parentSubscriber.unsubscribe();
  440. };
  441. return SafeSubscriber;
  442. }(Subscriber));
  443. function canReportError(observer) {
  444. while (observer) {
  445. var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
  446. if (closed_1 || isStopped) {
  447. return false;
  448. }
  449. else if (destination && destination instanceof Subscriber) {
  450. observer = destination;
  451. }
  452. else {
  453. observer = null;
  454. }
  455. }
  456. return true;
  457. }
  458. function toSubscriber(nextOrObserver, error, complete) {
  459. if (nextOrObserver) {
  460. if (nextOrObserver instanceof Subscriber) {
  461. return nextOrObserver;
  462. }
  463. if (nextOrObserver[rxSubscriber]) {
  464. return nextOrObserver[rxSubscriber]();
  465. }
  466. }
  467. if (!nextOrObserver && !error && !complete) {
  468. return new Subscriber(empty);
  469. }
  470. return new Subscriber(nextOrObserver, error, complete);
  471. }
  472. var observable = (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();
  473. function noop() { }
  474. function pipe() {
  475. var fns = [];
  476. for (var _i = 0; _i < arguments.length; _i++) {
  477. fns[_i] = arguments[_i];
  478. }
  479. return pipeFromArray(fns);
  480. }
  481. function pipeFromArray(fns) {
  482. if (!fns) {
  483. return noop;
  484. }
  485. if (fns.length === 1) {
  486. return fns[0];
  487. }
  488. return function piped(input) {
  489. return fns.reduce(function (prev, fn) { return fn(prev); }, input);
  490. };
  491. }
  492. var Observable = (function () {
  493. function Observable(subscribe) {
  494. this._isScalar = false;
  495. if (subscribe) {
  496. this._subscribe = subscribe;
  497. }
  498. }
  499. Observable.prototype.lift = function (operator) {
  500. var observable$$1 = new Observable();
  501. observable$$1.source = this;
  502. observable$$1.operator = operator;
  503. return observable$$1;
  504. };
  505. Observable.prototype.subscribe = function (observerOrNext, error, complete) {
  506. var operator = this.operator;
  507. var sink = toSubscriber(observerOrNext, error, complete);
  508. if (operator) {
  509. sink.add(operator.call(sink, this.source));
  510. }
  511. else {
  512. sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
  513. this._subscribe(sink) :
  514. this._trySubscribe(sink));
  515. }
  516. if (config.useDeprecatedSynchronousErrorHandling) {
  517. if (sink.syncErrorThrowable) {
  518. sink.syncErrorThrowable = false;
  519. if (sink.syncErrorThrown) {
  520. throw sink.syncErrorValue;
  521. }
  522. }
  523. }
  524. return sink;
  525. };
  526. Observable.prototype._trySubscribe = function (sink) {
  527. try {
  528. return this._subscribe(sink);
  529. }
  530. catch (err) {
  531. if (config.useDeprecatedSynchronousErrorHandling) {
  532. sink.syncErrorThrown = true;
  533. sink.syncErrorValue = err;
  534. }
  535. if (canReportError(sink)) {
  536. sink.error(err);
  537. }
  538. else {
  539. console.warn(err);
  540. }
  541. }
  542. };
  543. Observable.prototype.forEach = function (next, promiseCtor) {
  544. var _this = this;
  545. promiseCtor = getPromiseCtor(promiseCtor);
  546. return new promiseCtor(function (resolve, reject) {
  547. var subscription;
  548. subscription = _this.subscribe(function (value) {
  549. try {
  550. next(value);
  551. }
  552. catch (err) {
  553. reject(err);
  554. if (subscription) {
  555. subscription.unsubscribe();
  556. }
  557. }
  558. }, reject, resolve);
  559. });
  560. };
  561. Observable.prototype._subscribe = function (subscriber) {
  562. var source = this.source;
  563. return source && source.subscribe(subscriber);
  564. };
  565. Observable.prototype[observable] = function () {
  566. return this;
  567. };
  568. Observable.prototype.pipe = function () {
  569. var operations = [];
  570. for (var _i = 0; _i < arguments.length; _i++) {
  571. operations[_i] = arguments[_i];
  572. }
  573. if (operations.length === 0) {
  574. return this;
  575. }
  576. return pipeFromArray(operations)(this);
  577. };
  578. Observable.prototype.toPromise = function (promiseCtor) {
  579. var _this = this;
  580. promiseCtor = getPromiseCtor(promiseCtor);
  581. return new promiseCtor(function (resolve, reject) {
  582. var value;
  583. _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
  584. });
  585. };
  586. Observable.create = function (subscribe) {
  587. return new Observable(subscribe);
  588. };
  589. return Observable;
  590. }());
  591. function getPromiseCtor(promiseCtor) {
  592. if (!promiseCtor) {
  593. promiseCtor = config.Promise || Promise;
  594. }
  595. if (!promiseCtor) {
  596. throw new Error('no Promise impl found');
  597. }
  598. return promiseCtor;
  599. }
  600. var ObjectUnsubscribedErrorImpl = (function () {
  601. function ObjectUnsubscribedErrorImpl() {
  602. Error.call(this);
  603. this.message = 'object unsubscribed';
  604. this.name = 'ObjectUnsubscribedError';
  605. return this;
  606. }
  607. ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
  608. return ObjectUnsubscribedErrorImpl;
  609. })();
  610. var ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
  611. var SubjectSubscription = (function (_super) {
  612. __extends(SubjectSubscription, _super);
  613. function SubjectSubscription(subject, subscriber) {
  614. var _this = _super.call(this) || this;
  615. _this.subject = subject;
  616. _this.subscriber = subscriber;
  617. _this.closed = false;
  618. return _this;
  619. }
  620. SubjectSubscription.prototype.unsubscribe = function () {
  621. if (this.closed) {
  622. return;
  623. }
  624. this.closed = true;
  625. var subject = this.subject;
  626. var observers = subject.observers;
  627. this.subject = null;
  628. if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
  629. return;
  630. }
  631. var subscriberIndex = observers.indexOf(this.subscriber);
  632. if (subscriberIndex !== -1) {
  633. observers.splice(subscriberIndex, 1);
  634. }
  635. };
  636. return SubjectSubscription;
  637. }(Subscription));
  638. var SubjectSubscriber = (function (_super) {
  639. __extends(SubjectSubscriber, _super);
  640. function SubjectSubscriber(destination) {
  641. var _this = _super.call(this, destination) || this;
  642. _this.destination = destination;
  643. return _this;
  644. }
  645. return SubjectSubscriber;
  646. }(Subscriber));
  647. var Subject = (function (_super) {
  648. __extends(Subject, _super);
  649. function Subject() {
  650. var _this = _super.call(this) || this;
  651. _this.observers = [];
  652. _this.closed = false;
  653. _this.isStopped = false;
  654. _this.hasError = false;
  655. _this.thrownError = null;
  656. return _this;
  657. }
  658. Subject.prototype[rxSubscriber] = function () {
  659. return new SubjectSubscriber(this);
  660. };
  661. Subject.prototype.lift = function (operator) {
  662. var subject = new AnonymousSubject(this, this);
  663. subject.operator = operator;
  664. return subject;
  665. };
  666. Subject.prototype.next = function (value) {
  667. if (this.closed) {
  668. throw new ObjectUnsubscribedError();
  669. }
  670. if (!this.isStopped) {
  671. var observers = this.observers;
  672. var len = observers.length;
  673. var copy = observers.slice();
  674. for (var i = 0; i < len; i++) {
  675. copy[i].next(value);
  676. }
  677. }
  678. };
  679. Subject.prototype.error = function (err) {
  680. if (this.closed) {
  681. throw new ObjectUnsubscribedError();
  682. }
  683. this.hasError = true;
  684. this.thrownError = err;
  685. this.isStopped = true;
  686. var observers = this.observers;
  687. var len = observers.length;
  688. var copy = observers.slice();
  689. for (var i = 0; i < len; i++) {
  690. copy[i].error(err);
  691. }
  692. this.observers.length = 0;
  693. };
  694. Subject.prototype.complete = function () {
  695. if (this.closed) {
  696. throw new ObjectUnsubscribedError();
  697. }
  698. this.isStopped = true;
  699. var observers = this.observers;
  700. var len = observers.length;
  701. var copy = observers.slice();
  702. for (var i = 0; i < len; i++) {
  703. copy[i].complete();
  704. }
  705. this.observers.length = 0;
  706. };
  707. Subject.prototype.unsubscribe = function () {
  708. this.isStopped = true;
  709. this.closed = true;
  710. this.observers = null;
  711. };
  712. Subject.prototype._trySubscribe = function (subscriber) {
  713. if (this.closed) {
  714. throw new ObjectUnsubscribedError();
  715. }
  716. else {
  717. return _super.prototype._trySubscribe.call(this, subscriber);
  718. }
  719. };
  720. Subject.prototype._subscribe = function (subscriber) {
  721. if (this.closed) {
  722. throw new ObjectUnsubscribedError();
  723. }
  724. else if (this.hasError) {
  725. subscriber.error(this.thrownError);
  726. return Subscription.EMPTY;
  727. }
  728. else if (this.isStopped) {
  729. subscriber.complete();
  730. return Subscription.EMPTY;
  731. }
  732. else {
  733. this.observers.push(subscriber);
  734. return new SubjectSubscription(this, subscriber);
  735. }
  736. };
  737. Subject.prototype.asObservable = function () {
  738. var observable = new Observable();
  739. observable.source = this;
  740. return observable;
  741. };
  742. Subject.create = function (destination, source) {
  743. return new AnonymousSubject(destination, source);
  744. };
  745. return Subject;
  746. }(Observable));
  747. var AnonymousSubject = (function (_super) {
  748. __extends(AnonymousSubject, _super);
  749. function AnonymousSubject(destination, source) {
  750. var _this = _super.call(this) || this;
  751. _this.destination = destination;
  752. _this.source = source;
  753. return _this;
  754. }
  755. AnonymousSubject.prototype.next = function (value) {
  756. var destination = this.destination;
  757. if (destination && destination.next) {
  758. destination.next(value);
  759. }
  760. };
  761. AnonymousSubject.prototype.error = function (err) {
  762. var destination = this.destination;
  763. if (destination && destination.error) {
  764. this.destination.error(err);
  765. }
  766. };
  767. AnonymousSubject.prototype.complete = function () {
  768. var destination = this.destination;
  769. if (destination && destination.complete) {
  770. this.destination.complete();
  771. }
  772. };
  773. AnonymousSubject.prototype._subscribe = function (subscriber) {
  774. var source = this.source;
  775. if (source) {
  776. return this.source.subscribe(subscriber);
  777. }
  778. else {
  779. return Subscription.EMPTY;
  780. }
  781. };
  782. return AnonymousSubject;
  783. }(Subject));
  784. function refCount() {
  785. return function refCountOperatorFunction(source) {
  786. return source.lift(new RefCountOperator(source));
  787. };
  788. }
  789. var RefCountOperator = (function () {
  790. function RefCountOperator(connectable) {
  791. this.connectable = connectable;
  792. }
  793. RefCountOperator.prototype.call = function (subscriber, source) {
  794. var connectable = this.connectable;
  795. connectable._refCount++;
  796. var refCounter = new RefCountSubscriber(subscriber, connectable);
  797. var subscription = source.subscribe(refCounter);
  798. if (!refCounter.closed) {
  799. refCounter.connection = connectable.connect();
  800. }
  801. return subscription;
  802. };
  803. return RefCountOperator;
  804. }());
  805. var RefCountSubscriber = (function (_super) {
  806. __extends(RefCountSubscriber, _super);
  807. function RefCountSubscriber(destination, connectable) {
  808. var _this = _super.call(this, destination) || this;
  809. _this.connectable = connectable;
  810. return _this;
  811. }
  812. RefCountSubscriber.prototype._unsubscribe = function () {
  813. var connectable = this.connectable;
  814. if (!connectable) {
  815. this.connection = null;
  816. return;
  817. }
  818. this.connectable = null;
  819. var refCount = connectable._refCount;
  820. if (refCount <= 0) {
  821. this.connection = null;
  822. return;
  823. }
  824. connectable._refCount = refCount - 1;
  825. if (refCount > 1) {
  826. this.connection = null;
  827. return;
  828. }
  829. var connection = this.connection;
  830. var sharedConnection = connectable._connection;
  831. this.connection = null;
  832. if (sharedConnection && (!connection || sharedConnection === connection)) {
  833. sharedConnection.unsubscribe();
  834. }
  835. };
  836. return RefCountSubscriber;
  837. }(Subscriber));
  838. var ConnectableObservable = (function (_super) {
  839. __extends(ConnectableObservable, _super);
  840. function ConnectableObservable(source, subjectFactory) {
  841. var _this = _super.call(this) || this;
  842. _this.source = source;
  843. _this.subjectFactory = subjectFactory;
  844. _this._refCount = 0;
  845. _this._isComplete = false;
  846. return _this;
  847. }
  848. ConnectableObservable.prototype._subscribe = function (subscriber) {
  849. return this.getSubject().subscribe(subscriber);
  850. };
  851. ConnectableObservable.prototype.getSubject = function () {
  852. var subject = this._subject;
  853. if (!subject || subject.isStopped) {
  854. this._subject = this.subjectFactory();
  855. }
  856. return this._subject;
  857. };
  858. ConnectableObservable.prototype.connect = function () {
  859. var connection = this._connection;
  860. if (!connection) {
  861. this._isComplete = false;
  862. connection = this._connection = new Subscription();
  863. connection.add(this.source
  864. .subscribe(new ConnectableSubscriber(this.getSubject(), this)));
  865. if (connection.closed) {
  866. this._connection = null;
  867. connection = Subscription.EMPTY;
  868. }
  869. }
  870. return connection;
  871. };
  872. ConnectableObservable.prototype.refCount = function () {
  873. return refCount()(this);
  874. };
  875. return ConnectableObservable;
  876. }(Observable));
  877. var connectableObservableDescriptor = (function () {
  878. var connectableProto = ConnectableObservable.prototype;
  879. return {
  880. operator: { value: null },
  881. _refCount: { value: 0, writable: true },
  882. _subject: { value: null, writable: true },
  883. _connection: { value: null, writable: true },
  884. _subscribe: { value: connectableProto._subscribe },
  885. _isComplete: { value: connectableProto._isComplete, writable: true },
  886. getSubject: { value: connectableProto.getSubject },
  887. connect: { value: connectableProto.connect },
  888. refCount: { value: connectableProto.refCount }
  889. };
  890. })();
  891. var ConnectableSubscriber = (function (_super) {
  892. __extends(ConnectableSubscriber, _super);
  893. function ConnectableSubscriber(destination, connectable) {
  894. var _this = _super.call(this, destination) || this;
  895. _this.connectable = connectable;
  896. return _this;
  897. }
  898. ConnectableSubscriber.prototype._error = function (err) {
  899. this._unsubscribe();
  900. _super.prototype._error.call(this, err);
  901. };
  902. ConnectableSubscriber.prototype._complete = function () {
  903. this.connectable._isComplete = true;
  904. this._unsubscribe();
  905. _super.prototype._complete.call(this);
  906. };
  907. ConnectableSubscriber.prototype._unsubscribe = function () {
  908. var connectable = this.connectable;
  909. if (connectable) {
  910. this.connectable = null;
  911. var connection = connectable._connection;
  912. connectable._refCount = 0;
  913. connectable._subject = null;
  914. connectable._connection = null;
  915. if (connection) {
  916. connection.unsubscribe();
  917. }
  918. }
  919. };
  920. return ConnectableSubscriber;
  921. }(SubjectSubscriber));
  922. var RefCountSubscriber$1 = (function (_super) {
  923. __extends(RefCountSubscriber, _super);
  924. function RefCountSubscriber(destination, connectable) {
  925. var _this = _super.call(this, destination) || this;
  926. _this.connectable = connectable;
  927. return _this;
  928. }
  929. RefCountSubscriber.prototype._unsubscribe = function () {
  930. var connectable = this.connectable;
  931. if (!connectable) {
  932. this.connection = null;
  933. return;
  934. }
  935. this.connectable = null;
  936. var refCount$$1 = connectable._refCount;
  937. if (refCount$$1 <= 0) {
  938. this.connection = null;
  939. return;
  940. }
  941. connectable._refCount = refCount$$1 - 1;
  942. if (refCount$$1 > 1) {
  943. this.connection = null;
  944. return;
  945. }
  946. var connection = this.connection;
  947. var sharedConnection = connectable._connection;
  948. this.connection = null;
  949. if (sharedConnection && (!connection || sharedConnection === connection)) {
  950. sharedConnection.unsubscribe();
  951. }
  952. };
  953. return RefCountSubscriber;
  954. }(Subscriber));
  955. function groupBy(keySelector, elementSelector, durationSelector, subjectSelector) {
  956. return function (source) {
  957. return source.lift(new GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector));
  958. };
  959. }
  960. var GroupByOperator = (function () {
  961. function GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector) {
  962. this.keySelector = keySelector;
  963. this.elementSelector = elementSelector;
  964. this.durationSelector = durationSelector;
  965. this.subjectSelector = subjectSelector;
  966. }
  967. GroupByOperator.prototype.call = function (subscriber, source) {
  968. return source.subscribe(new GroupBySubscriber(subscriber, this.keySelector, this.elementSelector, this.durationSelector, this.subjectSelector));
  969. };
  970. return GroupByOperator;
  971. }());
  972. var GroupBySubscriber = (function (_super) {
  973. __extends(GroupBySubscriber, _super);
  974. function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector, subjectSelector) {
  975. var _this = _super.call(this, destination) || this;
  976. _this.keySelector = keySelector;
  977. _this.elementSelector = elementSelector;
  978. _this.durationSelector = durationSelector;
  979. _this.subjectSelector = subjectSelector;
  980. _this.groups = null;
  981. _this.attemptedToUnsubscribe = false;
  982. _this.count = 0;
  983. return _this;
  984. }
  985. GroupBySubscriber.prototype._next = function (value) {
  986. var key;
  987. try {
  988. key = this.keySelector(value);
  989. }
  990. catch (err) {
  991. this.error(err);
  992. return;
  993. }
  994. this._group(value, key);
  995. };
  996. GroupBySubscriber.prototype._group = function (value, key) {
  997. var groups = this.groups;
  998. if (!groups) {
  999. groups = this.groups = new Map();
  1000. }
  1001. var group = groups.get(key);
  1002. var element;
  1003. if (this.elementSelector) {
  1004. try {
  1005. element = this.elementSelector(value);
  1006. }
  1007. catch (err) {
  1008. this.error(err);
  1009. }
  1010. }
  1011. else {
  1012. element = value;
  1013. }
  1014. if (!group) {
  1015. group = (this.subjectSelector ? this.subjectSelector() : new Subject());
  1016. groups.set(key, group);
  1017. var groupedObservable = new GroupedObservable(key, group, this);
  1018. this.destination.next(groupedObservable);
  1019. if (this.durationSelector) {
  1020. var duration = void 0;
  1021. try {
  1022. duration = this.durationSelector(new GroupedObservable(key, group));
  1023. }
  1024. catch (err) {
  1025. this.error(err);
  1026. return;
  1027. }
  1028. this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this)));
  1029. }
  1030. }
  1031. if (!group.closed) {
  1032. group.next(element);
  1033. }
  1034. };
  1035. GroupBySubscriber.prototype._error = function (err) {
  1036. var groups = this.groups;
  1037. if (groups) {
  1038. groups.forEach(function (group, key) {
  1039. group.error(err);
  1040. });
  1041. groups.clear();
  1042. }
  1043. this.destination.error(err);
  1044. };
  1045. GroupBySubscriber.prototype._complete = function () {
  1046. var groups = this.groups;
  1047. if (groups) {
  1048. groups.forEach(function (group, key) {
  1049. group.complete();
  1050. });
  1051. groups.clear();
  1052. }
  1053. this.destination.complete();
  1054. };
  1055. GroupBySubscriber.prototype.removeGroup = function (key) {
  1056. this.groups.delete(key);
  1057. };
  1058. GroupBySubscriber.prototype.unsubscribe = function () {
  1059. if (!this.closed) {
  1060. this.attemptedToUnsubscribe = true;
  1061. if (this.count === 0) {
  1062. _super.prototype.unsubscribe.call(this);
  1063. }
  1064. }
  1065. };
  1066. return GroupBySubscriber;
  1067. }(Subscriber));
  1068. var GroupDurationSubscriber = (function (_super) {
  1069. __extends(GroupDurationSubscriber, _super);
  1070. function GroupDurationSubscriber(key, group, parent) {
  1071. var _this = _super.call(this, group) || this;
  1072. _this.key = key;
  1073. _this.group = group;
  1074. _this.parent = parent;
  1075. return _this;
  1076. }
  1077. GroupDurationSubscriber.prototype._next = function (value) {
  1078. this.complete();
  1079. };
  1080. GroupDurationSubscriber.prototype._unsubscribe = function () {
  1081. var _a = this, parent = _a.parent, key = _a.key;
  1082. this.key = this.parent = null;
  1083. if (parent) {
  1084. parent.removeGroup(key);
  1085. }
  1086. };
  1087. return GroupDurationSubscriber;
  1088. }(Subscriber));
  1089. var GroupedObservable = (function (_super) {
  1090. __extends(GroupedObservable, _super);
  1091. function GroupedObservable(key, groupSubject, refCountSubscription) {
  1092. var _this = _super.call(this) || this;
  1093. _this.key = key;
  1094. _this.groupSubject = groupSubject;
  1095. _this.refCountSubscription = refCountSubscription;
  1096. return _this;
  1097. }
  1098. GroupedObservable.prototype._subscribe = function (subscriber) {
  1099. var subscription = new Subscription();
  1100. var _a = this, refCountSubscription = _a.refCountSubscription, groupSubject = _a.groupSubject;
  1101. if (refCountSubscription && !refCountSubscription.closed) {
  1102. subscription.add(new InnerRefCountSubscription(refCountSubscription));
  1103. }
  1104. subscription.add(groupSubject.subscribe(subscriber));
  1105. return subscription;
  1106. };
  1107. return GroupedObservable;
  1108. }(Observable));
  1109. var InnerRefCountSubscription = (function (_super) {
  1110. __extends(InnerRefCountSubscription, _super);
  1111. function InnerRefCountSubscription(parent) {
  1112. var _this = _super.call(this) || this;
  1113. _this.parent = parent;
  1114. parent.count++;
  1115. return _this;
  1116. }
  1117. InnerRefCountSubscription.prototype.unsubscribe = function () {
  1118. var parent = this.parent;
  1119. if (!parent.closed && !this.closed) {
  1120. _super.prototype.unsubscribe.call(this);
  1121. parent.count -= 1;
  1122. if (parent.count === 0 && parent.attemptedToUnsubscribe) {
  1123. parent.unsubscribe();
  1124. }
  1125. }
  1126. };
  1127. return InnerRefCountSubscription;
  1128. }(Subscription));
  1129. var BehaviorSubject = (function (_super) {
  1130. __extends(BehaviorSubject, _super);
  1131. function BehaviorSubject(_value) {
  1132. var _this = _super.call(this) || this;
  1133. _this._value = _value;
  1134. return _this;
  1135. }
  1136. Object.defineProperty(BehaviorSubject.prototype, "value", {
  1137. get: function () {
  1138. return this.getValue();
  1139. },
  1140. enumerable: true,
  1141. configurable: true
  1142. });
  1143. BehaviorSubject.prototype._subscribe = function (subscriber) {
  1144. var subscription = _super.prototype._subscribe.call(this, subscriber);
  1145. if (subscription && !subscription.closed) {
  1146. subscriber.next(this._value);
  1147. }
  1148. return subscription;
  1149. };
  1150. BehaviorSubject.prototype.getValue = function () {
  1151. if (this.hasError) {
  1152. throw this.thrownError;
  1153. }
  1154. else if (this.closed) {
  1155. throw new ObjectUnsubscribedError();
  1156. }
  1157. else {
  1158. return this._value;
  1159. }
  1160. };
  1161. BehaviorSubject.prototype.next = function (value) {
  1162. _super.prototype.next.call(this, this._value = value);
  1163. };
  1164. return BehaviorSubject;
  1165. }(Subject));
  1166. var Action = (function (_super) {
  1167. __extends(Action, _super);
  1168. function Action(scheduler, work) {
  1169. return _super.call(this) || this;
  1170. }
  1171. Action.prototype.schedule = function (state, delay) {
  1172. if (delay === void 0) { delay = 0; }
  1173. return this;
  1174. };
  1175. return Action;
  1176. }(Subscription));
  1177. var AsyncAction = (function (_super) {
  1178. __extends(AsyncAction, _super);
  1179. function AsyncAction(scheduler, work) {
  1180. var _this = _super.call(this, scheduler, work) || this;
  1181. _this.scheduler = scheduler;
  1182. _this.work = work;
  1183. _this.pending = false;
  1184. return _this;
  1185. }
  1186. AsyncAction.prototype.schedule = function (state, delay) {
  1187. if (delay === void 0) { delay = 0; }
  1188. if (this.closed) {
  1189. return this;
  1190. }
  1191. this.state = state;
  1192. var id = this.id;
  1193. var scheduler = this.scheduler;
  1194. if (id != null) {
  1195. this.id = this.recycleAsyncId(scheduler, id, delay);
  1196. }
  1197. this.pending = true;
  1198. this.delay = delay;
  1199. this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
  1200. return this;
  1201. };
  1202. AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1203. if (delay === void 0) { delay = 0; }
  1204. return setInterval(scheduler.flush.bind(scheduler, this), delay);
  1205. };
  1206. AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1207. if (delay === void 0) { delay = 0; }
  1208. if (delay !== null && this.delay === delay && this.pending === false) {
  1209. return id;
  1210. }
  1211. clearInterval(id);
  1212. return undefined;
  1213. };
  1214. AsyncAction.prototype.execute = function (state, delay) {
  1215. if (this.closed) {
  1216. return new Error('executing a cancelled action');
  1217. }
  1218. this.pending = false;
  1219. var error = this._execute(state, delay);
  1220. if (error) {
  1221. return error;
  1222. }
  1223. else if (this.pending === false && this.id != null) {
  1224. this.id = this.recycleAsyncId(this.scheduler, this.id, null);
  1225. }
  1226. };
  1227. AsyncAction.prototype._execute = function (state, delay) {
  1228. var errored = false;
  1229. var errorValue = undefined;
  1230. try {
  1231. this.work(state);
  1232. }
  1233. catch (e) {
  1234. errored = true;
  1235. errorValue = !!e && e || new Error(e);
  1236. }
  1237. if (errored) {
  1238. this.unsubscribe();
  1239. return errorValue;
  1240. }
  1241. };
  1242. AsyncAction.prototype._unsubscribe = function () {
  1243. var id = this.id;
  1244. var scheduler = this.scheduler;
  1245. var actions = scheduler.actions;
  1246. var index = actions.indexOf(this);
  1247. this.work = null;
  1248. this.state = null;
  1249. this.pending = false;
  1250. this.scheduler = null;
  1251. if (index !== -1) {
  1252. actions.splice(index, 1);
  1253. }
  1254. if (id != null) {
  1255. this.id = this.recycleAsyncId(scheduler, id, null);
  1256. }
  1257. this.delay = null;
  1258. };
  1259. return AsyncAction;
  1260. }(Action));
  1261. var QueueAction = (function (_super) {
  1262. __extends(QueueAction, _super);
  1263. function QueueAction(scheduler, work) {
  1264. var _this = _super.call(this, scheduler, work) || this;
  1265. _this.scheduler = scheduler;
  1266. _this.work = work;
  1267. return _this;
  1268. }
  1269. QueueAction.prototype.schedule = function (state, delay) {
  1270. if (delay === void 0) { delay = 0; }
  1271. if (delay > 0) {
  1272. return _super.prototype.schedule.call(this, state, delay);
  1273. }
  1274. this.delay = delay;
  1275. this.state = state;
  1276. this.scheduler.flush(this);
  1277. return this;
  1278. };
  1279. QueueAction.prototype.execute = function (state, delay) {
  1280. return (delay > 0 || this.closed) ?
  1281. _super.prototype.execute.call(this, state, delay) :
  1282. this._execute(state, delay);
  1283. };
  1284. QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1285. if (delay === void 0) { delay = 0; }
  1286. if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
  1287. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  1288. }
  1289. return scheduler.flush(this);
  1290. };
  1291. return QueueAction;
  1292. }(AsyncAction));
  1293. var Scheduler = (function () {
  1294. function Scheduler(SchedulerAction, now) {
  1295. if (now === void 0) { now = Scheduler.now; }
  1296. this.SchedulerAction = SchedulerAction;
  1297. this.now = now;
  1298. }
  1299. Scheduler.prototype.schedule = function (work, delay, state) {
  1300. if (delay === void 0) { delay = 0; }
  1301. return new this.SchedulerAction(this, work).schedule(state, delay);
  1302. };
  1303. Scheduler.now = function () { return Date.now(); };
  1304. return Scheduler;
  1305. }());
  1306. var AsyncScheduler = (function (_super) {
  1307. __extends(AsyncScheduler, _super);
  1308. function AsyncScheduler(SchedulerAction, now) {
  1309. if (now === void 0) { now = Scheduler.now; }
  1310. var _this = _super.call(this, SchedulerAction, function () {
  1311. if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {
  1312. return AsyncScheduler.delegate.now();
  1313. }
  1314. else {
  1315. return now();
  1316. }
  1317. }) || this;
  1318. _this.actions = [];
  1319. _this.active = false;
  1320. _this.scheduled = undefined;
  1321. return _this;
  1322. }
  1323. AsyncScheduler.prototype.schedule = function (work, delay, state) {
  1324. if (delay === void 0) { delay = 0; }
  1325. if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
  1326. return AsyncScheduler.delegate.schedule(work, delay, state);
  1327. }
  1328. else {
  1329. return _super.prototype.schedule.call(this, work, delay, state);
  1330. }
  1331. };
  1332. AsyncScheduler.prototype.flush = function (action) {
  1333. var actions = this.actions;
  1334. if (this.active) {
  1335. actions.push(action);
  1336. return;
  1337. }
  1338. var error;
  1339. this.active = true;
  1340. do {
  1341. if (error = action.execute(action.state, action.delay)) {
  1342. break;
  1343. }
  1344. } while (action = actions.shift());
  1345. this.active = false;
  1346. if (error) {
  1347. while (action = actions.shift()) {
  1348. action.unsubscribe();
  1349. }
  1350. throw error;
  1351. }
  1352. };
  1353. return AsyncScheduler;
  1354. }(Scheduler));
  1355. var QueueScheduler = (function (_super) {
  1356. __extends(QueueScheduler, _super);
  1357. function QueueScheduler() {
  1358. return _super !== null && _super.apply(this, arguments) || this;
  1359. }
  1360. return QueueScheduler;
  1361. }(AsyncScheduler));
  1362. var queue = new QueueScheduler(QueueAction);
  1363. var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
  1364. function empty$1(scheduler) {
  1365. return scheduler ? emptyScheduled(scheduler) : EMPTY;
  1366. }
  1367. function emptyScheduled(scheduler) {
  1368. return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });
  1369. }
  1370. function isScheduler(value) {
  1371. return value && typeof value.schedule === 'function';
  1372. }
  1373. var subscribeToArray = function (array) { return function (subscriber) {
  1374. for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) {
  1375. subscriber.next(array[i]);
  1376. }
  1377. subscriber.complete();
  1378. }; };
  1379. function scheduleArray(input, scheduler) {
  1380. return new Observable(function (subscriber) {
  1381. var sub = new Subscription();
  1382. var i = 0;
  1383. sub.add(scheduler.schedule(function () {
  1384. if (i === input.length) {
  1385. subscriber.complete();
  1386. return;
  1387. }
  1388. subscriber.next(input[i++]);
  1389. if (!subscriber.closed) {
  1390. sub.add(this.schedule());
  1391. }
  1392. }));
  1393. return sub;
  1394. });
  1395. }
  1396. function fromArray(input, scheduler) {
  1397. if (!scheduler) {
  1398. return new Observable(subscribeToArray(input));
  1399. }
  1400. else {
  1401. return scheduleArray(input, scheduler);
  1402. }
  1403. }
  1404. function of() {
  1405. var args = [];
  1406. for (var _i = 0; _i < arguments.length; _i++) {
  1407. args[_i] = arguments[_i];
  1408. }
  1409. var scheduler = args[args.length - 1];
  1410. if (isScheduler(scheduler)) {
  1411. args.pop();
  1412. return scheduleArray(args, scheduler);
  1413. }
  1414. else {
  1415. return fromArray(args);
  1416. }
  1417. }
  1418. function throwError(error, scheduler) {
  1419. if (!scheduler) {
  1420. return new Observable(function (subscriber) { return subscriber.error(error); });
  1421. }
  1422. else {
  1423. return new Observable(function (subscriber) { return scheduler.schedule(dispatch, 0, { error: error, subscriber: subscriber }); });
  1424. }
  1425. }
  1426. function dispatch(_a) {
  1427. var error = _a.error, subscriber = _a.subscriber;
  1428. subscriber.error(error);
  1429. }
  1430. var NotificationKind;
  1431. (function (NotificationKind) {
  1432. NotificationKind["NEXT"] = "N";
  1433. NotificationKind["ERROR"] = "E";
  1434. NotificationKind["COMPLETE"] = "C";
  1435. })(NotificationKind || (NotificationKind = {}));
  1436. var Notification = (function () {
  1437. function Notification(kind, value, error) {
  1438. this.kind = kind;
  1439. this.value = value;
  1440. this.error = error;
  1441. this.hasValue = kind === 'N';
  1442. }
  1443. Notification.prototype.observe = function (observer) {
  1444. switch (this.kind) {
  1445. case 'N':
  1446. return observer.next && observer.next(this.value);
  1447. case 'E':
  1448. return observer.error && observer.error(this.error);
  1449. case 'C':
  1450. return observer.complete && observer.complete();
  1451. }
  1452. };
  1453. Notification.prototype.do = function (next, error, complete) {
  1454. var kind = this.kind;
  1455. switch (kind) {
  1456. case 'N':
  1457. return next && next(this.value);
  1458. case 'E':
  1459. return error && error(this.error);
  1460. case 'C':
  1461. return complete && complete();
  1462. }
  1463. };
  1464. Notification.prototype.accept = function (nextOrObserver, error, complete) {
  1465. if (nextOrObserver && typeof nextOrObserver.next === 'function') {
  1466. return this.observe(nextOrObserver);
  1467. }
  1468. else {
  1469. return this.do(nextOrObserver, error, complete);
  1470. }
  1471. };
  1472. Notification.prototype.toObservable = function () {
  1473. var kind = this.kind;
  1474. switch (kind) {
  1475. case 'N':
  1476. return of(this.value);
  1477. case 'E':
  1478. return throwError(this.error);
  1479. case 'C':
  1480. return empty$1();
  1481. }
  1482. throw new Error('unexpected notification kind value');
  1483. };
  1484. Notification.createNext = function (value) {
  1485. if (typeof value !== 'undefined') {
  1486. return new Notification('N', value);
  1487. }
  1488. return Notification.undefinedValueNotification;
  1489. };
  1490. Notification.createError = function (err) {
  1491. return new Notification('E', undefined, err);
  1492. };
  1493. Notification.createComplete = function () {
  1494. return Notification.completeNotification;
  1495. };
  1496. Notification.completeNotification = new Notification('C');
  1497. Notification.undefinedValueNotification = new Notification('N', undefined);
  1498. return Notification;
  1499. }());
  1500. function observeOn(scheduler, delay) {
  1501. if (delay === void 0) { delay = 0; }
  1502. return function observeOnOperatorFunction(source) {
  1503. return source.lift(new ObserveOnOperator(scheduler, delay));
  1504. };
  1505. }
  1506. var ObserveOnOperator = (function () {
  1507. function ObserveOnOperator(scheduler, delay) {
  1508. if (delay === void 0) { delay = 0; }
  1509. this.scheduler = scheduler;
  1510. this.delay = delay;
  1511. }
  1512. ObserveOnOperator.prototype.call = function (subscriber, source) {
  1513. return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
  1514. };
  1515. return ObserveOnOperator;
  1516. }());
  1517. var ObserveOnSubscriber = (function (_super) {
  1518. __extends(ObserveOnSubscriber, _super);
  1519. function ObserveOnSubscriber(destination, scheduler, delay) {
  1520. if (delay === void 0) { delay = 0; }
  1521. var _this = _super.call(this, destination) || this;
  1522. _this.scheduler = scheduler;
  1523. _this.delay = delay;
  1524. return _this;
  1525. }
  1526. ObserveOnSubscriber.dispatch = function (arg) {
  1527. var notification = arg.notification, destination = arg.destination;
  1528. notification.observe(destination);
  1529. this.unsubscribe();
  1530. };
  1531. ObserveOnSubscriber.prototype.scheduleMessage = function (notification) {
  1532. var destination = this.destination;
  1533. destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
  1534. };
  1535. ObserveOnSubscriber.prototype._next = function (value) {
  1536. this.scheduleMessage(Notification.createNext(value));
  1537. };
  1538. ObserveOnSubscriber.prototype._error = function (err) {
  1539. this.scheduleMessage(Notification.createError(err));
  1540. this.unsubscribe();
  1541. };
  1542. ObserveOnSubscriber.prototype._complete = function () {
  1543. this.scheduleMessage(Notification.createComplete());
  1544. this.unsubscribe();
  1545. };
  1546. return ObserveOnSubscriber;
  1547. }(Subscriber));
  1548. var ObserveOnMessage = (function () {
  1549. function ObserveOnMessage(notification, destination) {
  1550. this.notification = notification;
  1551. this.destination = destination;
  1552. }
  1553. return ObserveOnMessage;
  1554. }());
  1555. var ReplaySubject = (function (_super) {
  1556. __extends(ReplaySubject, _super);
  1557. function ReplaySubject(bufferSize, windowTime, scheduler) {
  1558. if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; }
  1559. if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; }
  1560. var _this = _super.call(this) || this;
  1561. _this.scheduler = scheduler;
  1562. _this._events = [];
  1563. _this._infiniteTimeWindow = false;
  1564. _this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
  1565. _this._windowTime = windowTime < 1 ? 1 : windowTime;
  1566. if (windowTime === Number.POSITIVE_INFINITY) {
  1567. _this._infiniteTimeWindow = true;
  1568. _this.next = _this.nextInfiniteTimeWindow;
  1569. }
  1570. else {
  1571. _this.next = _this.nextTimeWindow;
  1572. }
  1573. return _this;
  1574. }
  1575. ReplaySubject.prototype.nextInfiniteTimeWindow = function (value) {
  1576. var _events = this._events;
  1577. _events.push(value);
  1578. if (_events.length > this._bufferSize) {
  1579. _events.shift();
  1580. }
  1581. _super.prototype.next.call(this, value);
  1582. };
  1583. ReplaySubject.prototype.nextTimeWindow = function (value) {
  1584. this._events.push(new ReplayEvent(this._getNow(), value));
  1585. this._trimBufferThenGetEvents();
  1586. _super.prototype.next.call(this, value);
  1587. };
  1588. ReplaySubject.prototype._subscribe = function (subscriber) {
  1589. var _infiniteTimeWindow = this._infiniteTimeWindow;
  1590. var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
  1591. var scheduler = this.scheduler;
  1592. var len = _events.length;
  1593. var subscription;
  1594. if (this.closed) {
  1595. throw new ObjectUnsubscribedError();
  1596. }
  1597. else if (this.isStopped || this.hasError) {
  1598. subscription = Subscription.EMPTY;
  1599. }
  1600. else {
  1601. this.observers.push(subscriber);
  1602. subscription = new SubjectSubscription(this, subscriber);
  1603. }
  1604. if (scheduler) {
  1605. subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
  1606. }
  1607. if (_infiniteTimeWindow) {
  1608. for (var i = 0; i < len && !subscriber.closed; i++) {
  1609. subscriber.next(_events[i]);
  1610. }
  1611. }
  1612. else {
  1613. for (var i = 0; i < len && !subscriber.closed; i++) {
  1614. subscriber.next(_events[i].value);
  1615. }
  1616. }
  1617. if (this.hasError) {
  1618. subscriber.error(this.thrownError);
  1619. }
  1620. else if (this.isStopped) {
  1621. subscriber.complete();
  1622. }
  1623. return subscription;
  1624. };
  1625. ReplaySubject.prototype._getNow = function () {
  1626. return (this.scheduler || queue).now();
  1627. };
  1628. ReplaySubject.prototype._trimBufferThenGetEvents = function () {
  1629. var now = this._getNow();
  1630. var _bufferSize = this._bufferSize;
  1631. var _windowTime = this._windowTime;
  1632. var _events = this._events;
  1633. var eventsCount = _events.length;
  1634. var spliceCount = 0;
  1635. while (spliceCount < eventsCount) {
  1636. if ((now - _events[spliceCount].time) < _windowTime) {
  1637. break;
  1638. }
  1639. spliceCount++;
  1640. }
  1641. if (eventsCount > _bufferSize) {
  1642. spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
  1643. }
  1644. if (spliceCount > 0) {
  1645. _events.splice(0, spliceCount);
  1646. }
  1647. return _events;
  1648. };
  1649. return ReplaySubject;
  1650. }(Subject));
  1651. var ReplayEvent = (function () {
  1652. function ReplayEvent(time, value) {
  1653. this.time = time;
  1654. this.value = value;
  1655. }
  1656. return ReplayEvent;
  1657. }());
  1658. var AsyncSubject = (function (_super) {
  1659. __extends(AsyncSubject, _super);
  1660. function AsyncSubject() {
  1661. var _this = _super !== null && _super.apply(this, arguments) || this;
  1662. _this.value = null;
  1663. _this.hasNext = false;
  1664. _this.hasCompleted = false;
  1665. return _this;
  1666. }
  1667. AsyncSubject.prototype._subscribe = function (subscriber) {
  1668. if (this.hasError) {
  1669. subscriber.error(this.thrownError);
  1670. return Subscription.EMPTY;
  1671. }
  1672. else if (this.hasCompleted && this.hasNext) {
  1673. subscriber.next(this.value);
  1674. subscriber.complete();
  1675. return Subscription.EMPTY;
  1676. }
  1677. return _super.prototype._subscribe.call(this, subscriber);
  1678. };
  1679. AsyncSubject.prototype.next = function (value) {
  1680. if (!this.hasCompleted) {
  1681. this.value = value;
  1682. this.hasNext = true;
  1683. }
  1684. };
  1685. AsyncSubject.prototype.error = function (error) {
  1686. if (!this.hasCompleted) {
  1687. _super.prototype.error.call(this, error);
  1688. }
  1689. };
  1690. AsyncSubject.prototype.complete = function () {
  1691. this.hasCompleted = true;
  1692. if (this.hasNext) {
  1693. _super.prototype.next.call(this, this.value);
  1694. }
  1695. _super.prototype.complete.call(this);
  1696. };
  1697. return AsyncSubject;
  1698. }(Subject));
  1699. var nextHandle = 1;
  1700. var RESOLVED = (function () { return Promise.resolve(); })();
  1701. var activeHandles = {};
  1702. function findAndClearHandle(handle) {
  1703. if (handle in activeHandles) {
  1704. delete activeHandles[handle];
  1705. return true;
  1706. }
  1707. return false;
  1708. }
  1709. var Immediate = {
  1710. setImmediate: function (cb) {
  1711. var handle = nextHandle++;
  1712. activeHandles[handle] = true;
  1713. RESOLVED.then(function () { return findAndClearHandle(handle) && cb(); });
  1714. return handle;
  1715. },
  1716. clearImmediate: function (handle) {
  1717. findAndClearHandle(handle);
  1718. },
  1719. };
  1720. var AsapAction = (function (_super) {
  1721. __extends(AsapAction, _super);
  1722. function AsapAction(scheduler, work) {
  1723. var _this = _super.call(this, scheduler, work) || this;
  1724. _this.scheduler = scheduler;
  1725. _this.work = work;
  1726. return _this;
  1727. }
  1728. AsapAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1729. if (delay === void 0) { delay = 0; }
  1730. if (delay !== null && delay > 0) {
  1731. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  1732. }
  1733. scheduler.actions.push(this);
  1734. return scheduler.scheduled || (scheduler.scheduled = Immediate.setImmediate(scheduler.flush.bind(scheduler, null)));
  1735. };
  1736. AsapAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1737. if (delay === void 0) { delay = 0; }
  1738. if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
  1739. return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
  1740. }
  1741. if (scheduler.actions.length === 0) {
  1742. Immediate.clearImmediate(id);
  1743. scheduler.scheduled = undefined;
  1744. }
  1745. return undefined;
  1746. };
  1747. return AsapAction;
  1748. }(AsyncAction));
  1749. var AsapScheduler = (function (_super) {
  1750. __extends(AsapScheduler, _super);
  1751. function AsapScheduler() {
  1752. return _super !== null && _super.apply(this, arguments) || this;
  1753. }
  1754. AsapScheduler.prototype.flush = function (action) {
  1755. this.active = true;
  1756. this.scheduled = undefined;
  1757. var actions = this.actions;
  1758. var error;
  1759. var index = -1;
  1760. var count = actions.length;
  1761. action = action || actions.shift();
  1762. do {
  1763. if (error = action.execute(action.state, action.delay)) {
  1764. break;
  1765. }
  1766. } while (++index < count && (action = actions.shift()));
  1767. this.active = false;
  1768. if (error) {
  1769. while (++index < count && (action = actions.shift())) {
  1770. action.unsubscribe();
  1771. }
  1772. throw error;
  1773. }
  1774. };
  1775. return AsapScheduler;
  1776. }(AsyncScheduler));
  1777. var asap = new AsapScheduler(AsapAction);
  1778. var async = new AsyncScheduler(AsyncAction);
  1779. var AnimationFrameAction = (function (_super) {
  1780. __extends(AnimationFrameAction, _super);
  1781. function AnimationFrameAction(scheduler, work) {
  1782. var _this = _super.call(this, scheduler, work) || this;
  1783. _this.scheduler = scheduler;
  1784. _this.work = work;
  1785. return _this;
  1786. }
  1787. AnimationFrameAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1788. if (delay === void 0) { delay = 0; }
  1789. if (delay !== null && delay > 0) {
  1790. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  1791. }
  1792. scheduler.actions.push(this);
  1793. return scheduler.scheduled || (scheduler.scheduled = requestAnimationFrame(function () { return scheduler.flush(null); }));
  1794. };
  1795. AnimationFrameAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1796. if (delay === void 0) { delay = 0; }
  1797. if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
  1798. return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
  1799. }
  1800. if (scheduler.actions.length === 0) {
  1801. cancelAnimationFrame(id);
  1802. scheduler.scheduled = undefined;
  1803. }
  1804. return undefined;
  1805. };
  1806. return AnimationFrameAction;
  1807. }(AsyncAction));
  1808. var AnimationFrameScheduler = (function (_super) {
  1809. __extends(AnimationFrameScheduler, _super);
  1810. function AnimationFrameScheduler() {
  1811. return _super !== null && _super.apply(this, arguments) || this;
  1812. }
  1813. AnimationFrameScheduler.prototype.flush = function (action) {
  1814. this.active = true;
  1815. this.scheduled = undefined;
  1816. var actions = this.actions;
  1817. var error;
  1818. var index = -1;
  1819. var count = actions.length;
  1820. action = action || actions.shift();
  1821. do {
  1822. if (error = action.execute(action.state, action.delay)) {
  1823. break;
  1824. }
  1825. } while (++index < count && (action = actions.shift()));
  1826. this.active = false;
  1827. if (error) {
  1828. while (++index < count && (action = actions.shift())) {
  1829. action.unsubscribe();
  1830. }
  1831. throw error;
  1832. }
  1833. };
  1834. return AnimationFrameScheduler;
  1835. }(AsyncScheduler));
  1836. var animationFrame = new AnimationFrameScheduler(AnimationFrameAction);
  1837. var VirtualTimeScheduler = (function (_super) {
  1838. __extends(VirtualTimeScheduler, _super);
  1839. function VirtualTimeScheduler(SchedulerAction, maxFrames) {
  1840. if (SchedulerAction === void 0) { SchedulerAction = VirtualAction; }
  1841. if (maxFrames === void 0) { maxFrames = Number.POSITIVE_INFINITY; }
  1842. var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
  1843. _this.maxFrames = maxFrames;
  1844. _this.frame = 0;
  1845. _this.index = -1;
  1846. return _this;
  1847. }
  1848. VirtualTimeScheduler.prototype.flush = function () {
  1849. var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
  1850. var error, action;
  1851. while ((action = actions[0]) && action.delay <= maxFrames) {
  1852. actions.shift();
  1853. this.frame = action.delay;
  1854. if (error = action.execute(action.state, action.delay)) {
  1855. break;
  1856. }
  1857. }
  1858. if (error) {
  1859. while (action = actions.shift()) {
  1860. action.unsubscribe();
  1861. }
  1862. throw error;
  1863. }
  1864. };
  1865. VirtualTimeScheduler.frameTimeFactor = 10;
  1866. return VirtualTimeScheduler;
  1867. }(AsyncScheduler));
  1868. var VirtualAction = (function (_super) {
  1869. __extends(VirtualAction, _super);
  1870. function VirtualAction(scheduler, work, index) {
  1871. if (index === void 0) { index = scheduler.index += 1; }
  1872. var _this = _super.call(this, scheduler, work) || this;
  1873. _this.scheduler = scheduler;
  1874. _this.work = work;
  1875. _this.index = index;
  1876. _this.active = true;
  1877. _this.index = scheduler.index = index;
  1878. return _this;
  1879. }
  1880. VirtualAction.prototype.schedule = function (state, delay) {
  1881. if (delay === void 0) { delay = 0; }
  1882. if (!this.id) {
  1883. return _super.prototype.schedule.call(this, state, delay);
  1884. }
  1885. this.active = false;
  1886. var action = new VirtualAction(this.scheduler, this.work);
  1887. this.add(action);
  1888. return action.schedule(state, delay);
  1889. };
  1890. VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1891. if (delay === void 0) { delay = 0; }
  1892. this.delay = scheduler.frame + delay;
  1893. var actions = scheduler.actions;
  1894. actions.push(this);
  1895. actions.sort(VirtualAction.sortActions);
  1896. return true;
  1897. };
  1898. VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1899. if (delay === void 0) { delay = 0; }
  1900. return undefined;
  1901. };
  1902. VirtualAction.prototype._execute = function (state, delay) {
  1903. if (this.active === true) {
  1904. return _super.prototype._execute.call(this, state, delay);
  1905. }
  1906. };
  1907. VirtualAction.sortActions = function (a, b) {
  1908. if (a.delay === b.delay) {
  1909. if (a.index === b.index) {
  1910. return 0;
  1911. }
  1912. else if (a.index > b.index) {
  1913. return 1;
  1914. }
  1915. else {
  1916. return -1;
  1917. }
  1918. }
  1919. else if (a.delay > b.delay) {
  1920. return 1;
  1921. }
  1922. else {
  1923. return -1;
  1924. }
  1925. };
  1926. return VirtualAction;
  1927. }(AsyncAction));
  1928. function identity(x) {
  1929. return x;
  1930. }
  1931. var ArgumentOutOfRangeErrorImpl = (function () {
  1932. function ArgumentOutOfRangeErrorImpl() {
  1933. Error.call(this);
  1934. this.message = 'argument out of range';
  1935. this.name = 'ArgumentOutOfRangeError';
  1936. return this;
  1937. }
  1938. ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);
  1939. return ArgumentOutOfRangeErrorImpl;
  1940. })();
  1941. var ArgumentOutOfRangeError = ArgumentOutOfRangeErrorImpl;
  1942. var EmptyErrorImpl = (function () {
  1943. function EmptyErrorImpl() {
  1944. Error.call(this);
  1945. this.message = 'no elements in sequence';
  1946. this.name = 'EmptyError';
  1947. return this;
  1948. }
  1949. EmptyErrorImpl.prototype = Object.create(Error.prototype);
  1950. return EmptyErrorImpl;
  1951. })();
  1952. var EmptyError = EmptyErrorImpl;
  1953. var TimeoutErrorImpl = (function () {
  1954. function TimeoutErrorImpl() {
  1955. Error.call(this);
  1956. this.message = 'Timeout has occurred';
  1957. this.name = 'TimeoutError';
  1958. return this;
  1959. }
  1960. TimeoutErrorImpl.prototype = Object.create(Error.prototype);
  1961. return TimeoutErrorImpl;
  1962. })();
  1963. var TimeoutError = TimeoutErrorImpl;
  1964. function map(project, thisArg) {
  1965. return function mapOperation(source) {
  1966. if (typeof project !== 'function') {
  1967. throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
  1968. }
  1969. return source.lift(new MapOperator(project, thisArg));
  1970. };
  1971. }
  1972. var MapOperator = (function () {
  1973. function MapOperator(project, thisArg) {
  1974. this.project = project;
  1975. this.thisArg = thisArg;
  1976. }
  1977. MapOperator.prototype.call = function (subscriber, source) {
  1978. return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
  1979. };
  1980. return MapOperator;
  1981. }());
  1982. var MapSubscriber = (function (_super) {
  1983. __extends(MapSubscriber, _super);
  1984. function MapSubscriber(destination, project, thisArg) {
  1985. var _this = _super.call(this, destination) || this;
  1986. _this.project = project;
  1987. _this.count = 0;
  1988. _this.thisArg = thisArg || _this;
  1989. return _this;
  1990. }
  1991. MapSubscriber.prototype._next = function (value) {
  1992. var result;
  1993. try {
  1994. result = this.project.call(this.thisArg, value, this.count++);
  1995. }
  1996. catch (err) {
  1997. this.destination.error(err);
  1998. return;
  1999. }
  2000. this.destination.next(result);
  2001. };
  2002. return MapSubscriber;
  2003. }(Subscriber));
  2004. function bindCallback(callbackFunc, resultSelector, scheduler) {
  2005. if (resultSelector) {
  2006. if (isScheduler(resultSelector)) {
  2007. scheduler = resultSelector;
  2008. }
  2009. else {
  2010. return function () {
  2011. var args = [];
  2012. for (var _i = 0; _i < arguments.length; _i++) {
  2013. args[_i] = arguments[_i];
  2014. }
  2015. return bindCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
  2016. };
  2017. }
  2018. }
  2019. return function () {
  2020. var args = [];
  2021. for (var _i = 0; _i < arguments.length; _i++) {
  2022. args[_i] = arguments[_i];
  2023. }
  2024. var context = this;
  2025. var subject;
  2026. var params = {
  2027. context: context,
  2028. subject: subject,
  2029. callbackFunc: callbackFunc,
  2030. scheduler: scheduler,
  2031. };
  2032. return new Observable(function (subscriber) {
  2033. if (!scheduler) {
  2034. if (!subject) {
  2035. subject = new AsyncSubject();
  2036. var handler = function () {
  2037. var innerArgs = [];
  2038. for (var _i = 0; _i < arguments.length; _i++) {
  2039. innerArgs[_i] = arguments[_i];
  2040. }
  2041. subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
  2042. subject.complete();
  2043. };
  2044. try {
  2045. callbackFunc.apply(context, args.concat([handler]));
  2046. }
  2047. catch (err) {
  2048. if (canReportError(subject)) {
  2049. subject.error(err);
  2050. }
  2051. else {
  2052. console.warn(err);
  2053. }
  2054. }
  2055. }
  2056. return subject.subscribe(subscriber);
  2057. }
  2058. else {
  2059. var state = {
  2060. args: args, subscriber: subscriber, params: params,
  2061. };
  2062. return scheduler.schedule(dispatch$1, 0, state);
  2063. }
  2064. });
  2065. };
  2066. }
  2067. function dispatch$1(state) {
  2068. var _this = this;
  2069. var args = state.args, subscriber = state.subscriber, params = state.params;
  2070. var callbackFunc = params.callbackFunc, context = params.context, scheduler = params.scheduler;
  2071. var subject = params.subject;
  2072. if (!subject) {
  2073. subject = params.subject = new AsyncSubject();
  2074. var handler = function () {
  2075. var innerArgs = [];
  2076. for (var _i = 0; _i < arguments.length; _i++) {
  2077. innerArgs[_i] = arguments[_i];
  2078. }
  2079. var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
  2080. _this.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
  2081. };
  2082. try {
  2083. callbackFunc.apply(context, args.concat([handler]));
  2084. }
  2085. catch (err) {
  2086. subject.error(err);
  2087. }
  2088. }
  2089. this.add(subject.subscribe(subscriber));
  2090. }
  2091. function dispatchNext(state) {
  2092. var value = state.value, subject = state.subject;
  2093. subject.next(value);
  2094. subject.complete();
  2095. }
  2096. function bindNodeCallback(callbackFunc, resultSelector, scheduler) {
  2097. if (resultSelector) {
  2098. if (isScheduler(resultSelector)) {
  2099. scheduler = resultSelector;
  2100. }
  2101. else {
  2102. return function () {
  2103. var args = [];
  2104. for (var _i = 0; _i < arguments.length; _i++) {
  2105. args[_i] = arguments[_i];
  2106. }
  2107. return bindNodeCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
  2108. };
  2109. }
  2110. }
  2111. return function () {
  2112. var args = [];
  2113. for (var _i = 0; _i < arguments.length; _i++) {
  2114. args[_i] = arguments[_i];
  2115. }
  2116. var params = {
  2117. subject: undefined,
  2118. args: args,
  2119. callbackFunc: callbackFunc,
  2120. scheduler: scheduler,
  2121. context: this,
  2122. };
  2123. return new Observable(function (subscriber) {
  2124. var context = params.context;
  2125. var subject = params.subject;
  2126. if (!scheduler) {
  2127. if (!subject) {
  2128. subject = params.subject = new AsyncSubject();
  2129. var handler = function () {
  2130. var innerArgs = [];
  2131. for (var _i = 0; _i < arguments.length; _i++) {
  2132. innerArgs[_i] = arguments[_i];
  2133. }
  2134. var err = innerArgs.shift();
  2135. if (err) {
  2136. subject.error(err);
  2137. return;
  2138. }
  2139. subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
  2140. subject.complete();
  2141. };
  2142. try {
  2143. callbackFunc.apply(context, args.concat([handler]));
  2144. }
  2145. catch (err) {
  2146. if (canReportError(subject)) {
  2147. subject.error(err);
  2148. }
  2149. else {
  2150. console.warn(err);
  2151. }
  2152. }
  2153. }
  2154. return subject.subscribe(subscriber);
  2155. }
  2156. else {
  2157. return scheduler.schedule(dispatch$2, 0, { params: params, subscriber: subscriber, context: context });
  2158. }
  2159. });
  2160. };
  2161. }
  2162. function dispatch$2(state) {
  2163. var _this = this;
  2164. var params = state.params, subscriber = state.subscriber, context = state.context;
  2165. var callbackFunc = params.callbackFunc, args = params.args, scheduler = params.scheduler;
  2166. var subject = params.subject;
  2167. if (!subject) {
  2168. subject = params.subject = new AsyncSubject();
  2169. var handler = function () {
  2170. var innerArgs = [];
  2171. for (var _i = 0; _i < arguments.length; _i++) {
  2172. innerArgs[_i] = arguments[_i];
  2173. }
  2174. var err = innerArgs.shift();
  2175. if (err) {
  2176. _this.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
  2177. }
  2178. else {
  2179. var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
  2180. _this.add(scheduler.schedule(dispatchNext$1, 0, { value: value, subject: subject }));
  2181. }
  2182. };
  2183. try {
  2184. callbackFunc.apply(context, args.concat([handler]));
  2185. }
  2186. catch (err) {
  2187. this.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
  2188. }
  2189. }
  2190. this.add(subject.subscribe(subscriber));
  2191. }
  2192. function dispatchNext$1(arg) {
  2193. var value = arg.value, subject = arg.subject;
  2194. subject.next(value);
  2195. subject.complete();
  2196. }
  2197. function dispatchError$1(arg) {
  2198. var err = arg.err, subject = arg.subject;
  2199. subject.error(err);
  2200. }
  2201. var OuterSubscriber = (function (_super) {
  2202. __extends(OuterSubscriber, _super);
  2203. function OuterSubscriber() {
  2204. return _super !== null && _super.apply(this, arguments) || this;
  2205. }
  2206. OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  2207. this.destination.next(innerValue);
  2208. };
  2209. OuterSubscriber.prototype.notifyError = function (error, innerSub) {
  2210. this.destination.error(error);
  2211. };
  2212. OuterSubscriber.prototype.notifyComplete = function (innerSub) {
  2213. this.destination.complete();
  2214. };
  2215. return OuterSubscriber;
  2216. }(Subscriber));
  2217. var InnerSubscriber = (function (_super) {
  2218. __extends(InnerSubscriber, _super);
  2219. function InnerSubscriber(parent, outerValue, outerIndex) {
  2220. var _this = _super.call(this) || this;
  2221. _this.parent = parent;
  2222. _this.outerValue = outerValue;
  2223. _this.outerIndex = outerIndex;
  2224. _this.index = 0;
  2225. return _this;
  2226. }
  2227. InnerSubscriber.prototype._next = function (value) {
  2228. this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this);
  2229. };
  2230. InnerSubscriber.prototype._error = function (error) {
  2231. this.parent.notifyError(error, this);
  2232. this.unsubscribe();
  2233. };
  2234. InnerSubscriber.prototype._complete = function () {
  2235. this.parent.notifyComplete(this);
  2236. this.unsubscribe();
  2237. };
  2238. return InnerSubscriber;
  2239. }(Subscriber));
  2240. var subscribeToPromise = function (promise) { return function (subscriber) {
  2241. promise.then(function (value) {
  2242. if (!subscriber.closed) {
  2243. subscriber.next(value);
  2244. subscriber.complete();
  2245. }
  2246. }, function (err) { return subscriber.error(err); })
  2247. .then(null, hostReportError);
  2248. return subscriber;
  2249. }; };
  2250. function getSymbolIterator() {
  2251. if (typeof Symbol !== 'function' || !Symbol.iterator) {
  2252. return '@@iterator';
  2253. }
  2254. return Symbol.iterator;
  2255. }
  2256. var iterator = getSymbolIterator();
  2257. var subscribeToIterable = function (iterable) { return function (subscriber) {
  2258. var iterator$$1 = iterable[iterator]();
  2259. do {
  2260. var item = iterator$$1.next();
  2261. if (item.done) {
  2262. subscriber.complete();
  2263. break;
  2264. }
  2265. subscriber.next(item.value);
  2266. if (subscriber.closed) {
  2267. break;
  2268. }
  2269. } while (true);
  2270. if (typeof iterator$$1.return === 'function') {
  2271. subscriber.add(function () {
  2272. if (iterator$$1.return) {
  2273. iterator$$1.return();
  2274. }
  2275. });
  2276. }
  2277. return subscriber;
  2278. }; };
  2279. var subscribeToObservable = function (obj) { return function (subscriber) {
  2280. var obs = obj[observable]();
  2281. if (typeof obs.subscribe !== 'function') {
  2282. throw new TypeError('Provided object does not correctly implement Symbol.observable');
  2283. }
  2284. else {
  2285. return obs.subscribe(subscriber);
  2286. }
  2287. }; };
  2288. var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
  2289. function isPromise(value) {
  2290. return !!value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
  2291. }
  2292. var subscribeTo = function (result) {
  2293. if (!!result && typeof result[observable] === 'function') {
  2294. return subscribeToObservable(result);
  2295. }
  2296. else if (isArrayLike(result)) {
  2297. return subscribeToArray(result);
  2298. }
  2299. else if (isPromise(result)) {
  2300. return subscribeToPromise(result);
  2301. }
  2302. else if (!!result && typeof result[iterator] === 'function') {
  2303. return subscribeToIterable(result);
  2304. }
  2305. else {
  2306. var value = isObject(result) ? 'an invalid object' : "'" + result + "'";
  2307. var msg = "You provided " + value + " where a stream was expected."
  2308. + ' You can provide an Observable, Promise, Array, or Iterable.';
  2309. throw new TypeError(msg);
  2310. }
  2311. };
  2312. function subscribeToResult(outerSubscriber, result, outerValue, outerIndex, innerSubscriber) {
  2313. if (innerSubscriber === void 0) { innerSubscriber = new InnerSubscriber(outerSubscriber, outerValue, outerIndex); }
  2314. if (innerSubscriber.closed) {
  2315. return undefined;
  2316. }
  2317. if (result instanceof Observable) {
  2318. return result.subscribe(innerSubscriber);
  2319. }
  2320. return subscribeTo(result)(innerSubscriber);
  2321. }
  2322. var NONE = {};
  2323. function combineLatest() {
  2324. var observables = [];
  2325. for (var _i = 0; _i < arguments.length; _i++) {
  2326. observables[_i] = arguments[_i];
  2327. }
  2328. var resultSelector = null;
  2329. var scheduler = null;
  2330. if (isScheduler(observables[observables.length - 1])) {
  2331. scheduler = observables.pop();
  2332. }
  2333. if (typeof observables[observables.length - 1] === 'function') {
  2334. resultSelector = observables.pop();
  2335. }
  2336. if (observables.length === 1 && isArray(observables[0])) {
  2337. observables = observables[0];
  2338. }
  2339. return fromArray(observables, scheduler).lift(new CombineLatestOperator(resultSelector));
  2340. }
  2341. var CombineLatestOperator = (function () {
  2342. function CombineLatestOperator(resultSelector) {
  2343. this.resultSelector = resultSelector;
  2344. }
  2345. CombineLatestOperator.prototype.call = function (subscriber, source) {
  2346. return source.subscribe(new CombineLatestSubscriber(subscriber, this.resultSelector));
  2347. };
  2348. return CombineLatestOperator;
  2349. }());
  2350. var CombineLatestSubscriber = (function (_super) {
  2351. __extends(CombineLatestSubscriber, _super);
  2352. function CombineLatestSubscriber(destination, resultSelector) {
  2353. var _this = _super.call(this, destination) || this;
  2354. _this.resultSelector = resultSelector;
  2355. _this.active = 0;
  2356. _this.values = [];
  2357. _this.observables = [];
  2358. return _this;
  2359. }
  2360. CombineLatestSubscriber.prototype._next = function (observable) {
  2361. this.values.push(NONE);
  2362. this.observables.push(observable);
  2363. };
  2364. CombineLatestSubscriber.prototype._complete = function () {
  2365. var observables = this.observables;
  2366. var len = observables.length;
  2367. if (len === 0) {
  2368. this.destination.complete();
  2369. }
  2370. else {
  2371. this.active = len;
  2372. this.toRespond = len;
  2373. for (var i = 0; i < len; i++) {
  2374. var observable = observables[i];
  2375. this.add(subscribeToResult(this, observable, observable, i));
  2376. }
  2377. }
  2378. };
  2379. CombineLatestSubscriber.prototype.notifyComplete = function (unused) {
  2380. if ((this.active -= 1) === 0) {
  2381. this.destination.complete();
  2382. }
  2383. };
  2384. CombineLatestSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  2385. var values = this.values;
  2386. var oldVal = values[outerIndex];
  2387. var toRespond = !this.toRespond
  2388. ? 0
  2389. : oldVal === NONE ? --this.toRespond : this.toRespond;
  2390. values[outerIndex] = innerValue;
  2391. if (toRespond === 0) {
  2392. if (this.resultSelector) {
  2393. this._tryResultSelector(values);
  2394. }
  2395. else {
  2396. this.destination.next(values.slice());
  2397. }
  2398. }
  2399. };
  2400. CombineLatestSubscriber.prototype._tryResultSelector = function (values) {
  2401. var result;
  2402. try {
  2403. result = this.resultSelector.apply(this, values);
  2404. }
  2405. catch (err) {
  2406. this.destination.error(err);
  2407. return;
  2408. }
  2409. this.destination.next(result);
  2410. };
  2411. return CombineLatestSubscriber;
  2412. }(OuterSubscriber));
  2413. function scheduleObservable(input, scheduler) {
  2414. return new Observable(function (subscriber) {
  2415. var sub = new Subscription();
  2416. sub.add(scheduler.schedule(function () {
  2417. var observable$$1 = input[observable]();
  2418. sub.add(observable$$1.subscribe({
  2419. next: function (value) { sub.add(scheduler.schedule(function () { return subscriber.next(value); })); },
  2420. error: function (err) { sub.add(scheduler.schedule(function () { return subscriber.error(err); })); },
  2421. complete: function () { sub.add(scheduler.schedule(function () { return subscriber.complete(); })); },
  2422. }));
  2423. }));
  2424. return sub;
  2425. });
  2426. }
  2427. function schedulePromise(input, scheduler) {
  2428. return new Observable(function (subscriber) {
  2429. var sub = new Subscription();
  2430. sub.add(scheduler.schedule(function () { return input.then(function (value) {
  2431. sub.add(scheduler.schedule(function () {
  2432. subscriber.next(value);
  2433. sub.add(scheduler.schedule(function () { return subscriber.complete(); }));
  2434. }));
  2435. }, function (err) {
  2436. sub.add(scheduler.schedule(function () { return subscriber.error(err); }));
  2437. }); }));
  2438. return sub;
  2439. });
  2440. }
  2441. function scheduleIterable(input, scheduler) {
  2442. if (!input) {
  2443. throw new Error('Iterable cannot be null');
  2444. }
  2445. return new Observable(function (subscriber) {
  2446. var sub = new Subscription();
  2447. var iterator$$1;
  2448. sub.add(function () {
  2449. if (iterator$$1 && typeof iterator$$1.return === 'function') {
  2450. iterator$$1.return();
  2451. }
  2452. });
  2453. sub.add(scheduler.schedule(function () {
  2454. iterator$$1 = input[iterator]();
  2455. sub.add(scheduler.schedule(function () {
  2456. if (subscriber.closed) {
  2457. return;
  2458. }
  2459. var value;
  2460. var done;
  2461. try {
  2462. var result = iterator$$1.next();
  2463. value = result.value;
  2464. done = result.done;
  2465. }
  2466. catch (err) {
  2467. subscriber.error(err);
  2468. return;
  2469. }
  2470. if (done) {
  2471. subscriber.complete();
  2472. }
  2473. else {
  2474. subscriber.next(value);
  2475. this.schedule();
  2476. }
  2477. }));
  2478. }));
  2479. return sub;
  2480. });
  2481. }
  2482. function isInteropObservable(input) {
  2483. return input && typeof input[observable] === 'function';
  2484. }
  2485. function isIterable(input) {
  2486. return input && typeof input[iterator] === 'function';
  2487. }
  2488. function scheduled(input, scheduler) {
  2489. if (input != null) {
  2490. if (isInteropObservable(input)) {
  2491. return scheduleObservable(input, scheduler);
  2492. }
  2493. else if (isPromise(input)) {
  2494. return schedulePromise(input, scheduler);
  2495. }
  2496. else if (isArrayLike(input)) {
  2497. return scheduleArray(input, scheduler);
  2498. }
  2499. else if (isIterable(input) || typeof input === 'string') {
  2500. return scheduleIterable(input, scheduler);
  2501. }
  2502. }
  2503. throw new TypeError((input !== null && typeof input || input) + ' is not observable');
  2504. }
  2505. function from(input, scheduler) {
  2506. if (!scheduler) {
  2507. if (input instanceof Observable) {
  2508. return input;
  2509. }
  2510. return new Observable(subscribeTo(input));
  2511. }
  2512. else {
  2513. return scheduled(input, scheduler);
  2514. }
  2515. }
  2516. function mergeMap(project, resultSelector, concurrent) {
  2517. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  2518. if (typeof resultSelector === 'function') {
  2519. return function (source) { return source.pipe(mergeMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); }, concurrent)); };
  2520. }
  2521. else if (typeof resultSelector === 'number') {
  2522. concurrent = resultSelector;
  2523. }
  2524. return function (source) { return source.lift(new MergeMapOperator(project, concurrent)); };
  2525. }
  2526. var MergeMapOperator = (function () {
  2527. function MergeMapOperator(project, concurrent) {
  2528. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  2529. this.project = project;
  2530. this.concurrent = concurrent;
  2531. }
  2532. MergeMapOperator.prototype.call = function (observer, source) {
  2533. return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent));
  2534. };
  2535. return MergeMapOperator;
  2536. }());
  2537. var MergeMapSubscriber = (function (_super) {
  2538. __extends(MergeMapSubscriber, _super);
  2539. function MergeMapSubscriber(destination, project, concurrent) {
  2540. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  2541. var _this = _super.call(this, destination) || this;
  2542. _this.project = project;
  2543. _this.concurrent = concurrent;
  2544. _this.hasCompleted = false;
  2545. _this.buffer = [];
  2546. _this.active = 0;
  2547. _this.index = 0;
  2548. return _this;
  2549. }
  2550. MergeMapSubscriber.prototype._next = function (value) {
  2551. if (this.active < this.concurrent) {
  2552. this._tryNext(value);
  2553. }
  2554. else {
  2555. this.buffer.push(value);
  2556. }
  2557. };
  2558. MergeMapSubscriber.prototype._tryNext = function (value) {
  2559. var result;
  2560. var index = this.index++;
  2561. try {
  2562. result = this.project(value, index);
  2563. }
  2564. catch (err) {
  2565. this.destination.error(err);
  2566. return;
  2567. }
  2568. this.active++;
  2569. this._innerSub(result, value, index);
  2570. };
  2571. MergeMapSubscriber.prototype._innerSub = function (ish, value, index) {
  2572. var innerSubscriber = new InnerSubscriber(this, value, index);
  2573. var destination = this.destination;
  2574. destination.add(innerSubscriber);
  2575. var innerSubscription = subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
  2576. if (innerSubscription !== innerSubscriber) {
  2577. destination.add(innerSubscription);
  2578. }
  2579. };
  2580. MergeMapSubscriber.prototype._complete = function () {
  2581. this.hasCompleted = true;
  2582. if (this.active === 0 && this.buffer.length === 0) {
  2583. this.destination.complete();
  2584. }
  2585. this.unsubscribe();
  2586. };
  2587. MergeMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  2588. this.destination.next(innerValue);
  2589. };
  2590. MergeMapSubscriber.prototype.notifyComplete = function (innerSub) {
  2591. var buffer = this.buffer;
  2592. this.remove(innerSub);
  2593. this.active--;
  2594. if (buffer.length > 0) {
  2595. this._next(buffer.shift());
  2596. }
  2597. else if (this.active === 0 && this.hasCompleted) {
  2598. this.destination.complete();
  2599. }
  2600. };
  2601. return MergeMapSubscriber;
  2602. }(OuterSubscriber));
  2603. function mergeAll(concurrent) {
  2604. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  2605. return mergeMap(identity, concurrent);
  2606. }
  2607. function concatAll() {
  2608. return mergeAll(1);
  2609. }
  2610. function concat() {
  2611. var observables = [];
  2612. for (var _i = 0; _i < arguments.length; _i++) {
  2613. observables[_i] = arguments[_i];
  2614. }
  2615. return concatAll()(of.apply(void 0, observables));
  2616. }
  2617. function defer(observableFactory) {
  2618. return new Observable(function (subscriber) {
  2619. var input;
  2620. try {
  2621. input = observableFactory();
  2622. }
  2623. catch (err) {
  2624. subscriber.error(err);
  2625. return undefined;
  2626. }
  2627. var source = input ? from(input) : empty$1();
  2628. return source.subscribe(subscriber);
  2629. });
  2630. }
  2631. function forkJoin() {
  2632. var sources = [];
  2633. for (var _i = 0; _i < arguments.length; _i++) {
  2634. sources[_i] = arguments[_i];
  2635. }
  2636. if (sources.length === 1) {
  2637. var first_1 = sources[0];
  2638. if (isArray(first_1)) {
  2639. return forkJoinInternal(first_1, null);
  2640. }
  2641. if (isObject(first_1) && Object.getPrototypeOf(first_1) === Object.prototype) {
  2642. var keys = Object.keys(first_1);
  2643. return forkJoinInternal(keys.map(function (key) { return first_1[key]; }), keys);
  2644. }
  2645. }
  2646. if (typeof sources[sources.length - 1] === 'function') {
  2647. var resultSelector_1 = sources.pop();
  2648. sources = (sources.length === 1 && isArray(sources[0])) ? sources[0] : sources;
  2649. return forkJoinInternal(sources, null).pipe(map(function (args) { return resultSelector_1.apply(void 0, args); }));
  2650. }
  2651. return forkJoinInternal(sources, null);
  2652. }
  2653. function forkJoinInternal(sources, keys) {
  2654. return new Observable(function (subscriber) {
  2655. var len = sources.length;
  2656. if (len === 0) {
  2657. subscriber.complete();
  2658. return;
  2659. }
  2660. var values = new Array(len);
  2661. var completed = 0;
  2662. var emitted = 0;
  2663. var _loop_1 = function (i) {
  2664. var source = from(sources[i]);
  2665. var hasValue = false;
  2666. subscriber.add(source.subscribe({
  2667. next: function (value) {
  2668. if (!hasValue) {
  2669. hasValue = true;
  2670. emitted++;
  2671. }
  2672. values[i] = value;
  2673. },
  2674. error: function (err) { return subscriber.error(err); },
  2675. complete: function () {
  2676. completed++;
  2677. if (completed === len || !hasValue) {
  2678. if (emitted === len) {
  2679. subscriber.next(keys ?
  2680. keys.reduce(function (result, key, i) { return (result[key] = values[i], result); }, {}) :
  2681. values);
  2682. }
  2683. subscriber.complete();
  2684. }
  2685. }
  2686. }));
  2687. };
  2688. for (var i = 0; i < len; i++) {
  2689. _loop_1(i);
  2690. }
  2691. });
  2692. }
  2693. function fromEvent(target, eventName, options, resultSelector) {
  2694. if (isFunction(options)) {
  2695. resultSelector = options;
  2696. options = undefined;
  2697. }
  2698. if (resultSelector) {
  2699. return fromEvent(target, eventName, options).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
  2700. }
  2701. return new Observable(function (subscriber) {
  2702. function handler(e) {
  2703. if (arguments.length > 1) {
  2704. subscriber.next(Array.prototype.slice.call(arguments));
  2705. }
  2706. else {
  2707. subscriber.next(e);
  2708. }
  2709. }
  2710. setupSubscription(target, eventName, handler, subscriber, options);
  2711. });
  2712. }
  2713. function setupSubscription(sourceObj, eventName, handler, subscriber, options) {
  2714. var unsubscribe;
  2715. if (isEventTarget(sourceObj)) {
  2716. var source_1 = sourceObj;
  2717. sourceObj.addEventListener(eventName, handler, options);
  2718. unsubscribe = function () { return source_1.removeEventListener(eventName, handler, options); };
  2719. }
  2720. else if (isJQueryStyleEventEmitter(sourceObj)) {
  2721. var source_2 = sourceObj;
  2722. sourceObj.on(eventName, handler);
  2723. unsubscribe = function () { return source_2.off(eventName, handler); };
  2724. }
  2725. else if (isNodeStyleEventEmitter(sourceObj)) {
  2726. var source_3 = sourceObj;
  2727. sourceObj.addListener(eventName, handler);
  2728. unsubscribe = function () { return source_3.removeListener(eventName, handler); };
  2729. }
  2730. else if (sourceObj && sourceObj.length) {
  2731. for (var i = 0, len = sourceObj.length; i < len; i++) {
  2732. setupSubscription(sourceObj[i], eventName, handler, subscriber, options);
  2733. }
  2734. }
  2735. else {
  2736. throw new TypeError('Invalid event target');
  2737. }
  2738. subscriber.add(unsubscribe);
  2739. }
  2740. function isNodeStyleEventEmitter(sourceObj) {
  2741. return sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function';
  2742. }
  2743. function isJQueryStyleEventEmitter(sourceObj) {
  2744. return sourceObj && typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function';
  2745. }
  2746. function isEventTarget(sourceObj) {
  2747. return sourceObj && typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function';
  2748. }
  2749. function fromEventPattern(addHandler, removeHandler, resultSelector) {
  2750. if (resultSelector) {
  2751. return fromEventPattern(addHandler, removeHandler).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
  2752. }
  2753. return new Observable(function (subscriber) {
  2754. var handler = function () {
  2755. var e = [];
  2756. for (var _i = 0; _i < arguments.length; _i++) {
  2757. e[_i] = arguments[_i];
  2758. }
  2759. return subscriber.next(e.length === 1 ? e[0] : e);
  2760. };
  2761. var retValue;
  2762. try {
  2763. retValue = addHandler(handler);
  2764. }
  2765. catch (err) {
  2766. subscriber.error(err);
  2767. return undefined;
  2768. }
  2769. if (!isFunction(removeHandler)) {
  2770. return undefined;
  2771. }
  2772. return function () { return removeHandler(handler, retValue); };
  2773. });
  2774. }
  2775. function generate(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
  2776. var resultSelector;
  2777. var initialState;
  2778. if (arguments.length == 1) {
  2779. var options = initialStateOrOptions;
  2780. initialState = options.initialState;
  2781. condition = options.condition;
  2782. iterate = options.iterate;
  2783. resultSelector = options.resultSelector || identity;
  2784. scheduler = options.scheduler;
  2785. }
  2786. else if (resultSelectorOrObservable === undefined || isScheduler(resultSelectorOrObservable)) {
  2787. initialState = initialStateOrOptions;
  2788. resultSelector = identity;
  2789. scheduler = resultSelectorOrObservable;
  2790. }
  2791. else {
  2792. initialState = initialStateOrOptions;
  2793. resultSelector = resultSelectorOrObservable;
  2794. }
  2795. return new Observable(function (subscriber) {
  2796. var state = initialState;
  2797. if (scheduler) {
  2798. return scheduler.schedule(dispatch$3, 0, {
  2799. subscriber: subscriber,
  2800. iterate: iterate,
  2801. condition: condition,
  2802. resultSelector: resultSelector,
  2803. state: state
  2804. });
  2805. }
  2806. do {
  2807. if (condition) {
  2808. var conditionResult = void 0;
  2809. try {
  2810. conditionResult = condition(state);
  2811. }
  2812. catch (err) {
  2813. subscriber.error(err);
  2814. return undefined;
  2815. }
  2816. if (!conditionResult) {
  2817. subscriber.complete();
  2818. break;
  2819. }
  2820. }
  2821. var value = void 0;
  2822. try {
  2823. value = resultSelector(state);
  2824. }
  2825. catch (err) {
  2826. subscriber.error(err);
  2827. return undefined;
  2828. }
  2829. subscriber.next(value);
  2830. if (subscriber.closed) {
  2831. break;
  2832. }
  2833. try {
  2834. state = iterate(state);
  2835. }
  2836. catch (err) {
  2837. subscriber.error(err);
  2838. return undefined;
  2839. }
  2840. } while (true);
  2841. return undefined;
  2842. });
  2843. }
  2844. function dispatch$3(state) {
  2845. var subscriber = state.subscriber, condition = state.condition;
  2846. if (subscriber.closed) {
  2847. return undefined;
  2848. }
  2849. if (state.needIterate) {
  2850. try {
  2851. state.state = state.iterate(state.state);
  2852. }
  2853. catch (err) {
  2854. subscriber.error(err);
  2855. return undefined;
  2856. }
  2857. }
  2858. else {
  2859. state.needIterate = true;
  2860. }
  2861. if (condition) {
  2862. var conditionResult = void 0;
  2863. try {
  2864. conditionResult = condition(state.state);
  2865. }
  2866. catch (err) {
  2867. subscriber.error(err);
  2868. return undefined;
  2869. }
  2870. if (!conditionResult) {
  2871. subscriber.complete();
  2872. return undefined;
  2873. }
  2874. if (subscriber.closed) {
  2875. return undefined;
  2876. }
  2877. }
  2878. var value;
  2879. try {
  2880. value = state.resultSelector(state.state);
  2881. }
  2882. catch (err) {
  2883. subscriber.error(err);
  2884. return undefined;
  2885. }
  2886. if (subscriber.closed) {
  2887. return undefined;
  2888. }
  2889. subscriber.next(value);
  2890. if (subscriber.closed) {
  2891. return undefined;
  2892. }
  2893. return this.schedule(state);
  2894. }
  2895. function iif(condition, trueResult, falseResult) {
  2896. if (trueResult === void 0) { trueResult = EMPTY; }
  2897. if (falseResult === void 0) { falseResult = EMPTY; }
  2898. return defer(function () { return condition() ? trueResult : falseResult; });
  2899. }
  2900. function isNumeric(val) {
  2901. return !isArray(val) && (val - parseFloat(val) + 1) >= 0;
  2902. }
  2903. function interval(period, scheduler) {
  2904. if (period === void 0) { period = 0; }
  2905. if (scheduler === void 0) { scheduler = async; }
  2906. if (!isNumeric(period) || period < 0) {
  2907. period = 0;
  2908. }
  2909. if (!scheduler || typeof scheduler.schedule !== 'function') {
  2910. scheduler = async;
  2911. }
  2912. return new Observable(function (subscriber) {
  2913. subscriber.add(scheduler.schedule(dispatch$4, period, { subscriber: subscriber, counter: 0, period: period }));
  2914. return subscriber;
  2915. });
  2916. }
  2917. function dispatch$4(state) {
  2918. var subscriber = state.subscriber, counter = state.counter, period = state.period;
  2919. subscriber.next(counter);
  2920. this.schedule({ subscriber: subscriber, counter: counter + 1, period: period }, period);
  2921. }
  2922. function merge() {
  2923. var observables = [];
  2924. for (var _i = 0; _i < arguments.length; _i++) {
  2925. observables[_i] = arguments[_i];
  2926. }
  2927. var concurrent = Number.POSITIVE_INFINITY;
  2928. var scheduler = null;
  2929. var last = observables[observables.length - 1];
  2930. if (isScheduler(last)) {
  2931. scheduler = observables.pop();
  2932. if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
  2933. concurrent = observables.pop();
  2934. }
  2935. }
  2936. else if (typeof last === 'number') {
  2937. concurrent = observables.pop();
  2938. }
  2939. if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
  2940. return observables[0];
  2941. }
  2942. return mergeAll(concurrent)(fromArray(observables, scheduler));
  2943. }
  2944. var NEVER = new Observable(noop);
  2945. function onErrorResumeNext() {
  2946. var sources = [];
  2947. for (var _i = 0; _i < arguments.length; _i++) {
  2948. sources[_i] = arguments[_i];
  2949. }
  2950. if (sources.length === 0) {
  2951. return EMPTY;
  2952. }
  2953. var first = sources[0], remainder = sources.slice(1);
  2954. if (sources.length === 1 && isArray(first)) {
  2955. return onErrorResumeNext.apply(void 0, first);
  2956. }
  2957. return new Observable(function (subscriber) {
  2958. var subNext = function () { return subscriber.add(onErrorResumeNext.apply(void 0, remainder).subscribe(subscriber)); };
  2959. return from(first).subscribe({
  2960. next: function (value) { subscriber.next(value); },
  2961. error: subNext,
  2962. complete: subNext,
  2963. });
  2964. });
  2965. }
  2966. function pairs(obj, scheduler) {
  2967. if (!scheduler) {
  2968. return new Observable(function (subscriber) {
  2969. var keys = Object.keys(obj);
  2970. for (var i = 0; i < keys.length && !subscriber.closed; i++) {
  2971. var key = keys[i];
  2972. if (obj.hasOwnProperty(key)) {
  2973. subscriber.next([key, obj[key]]);
  2974. }
  2975. }
  2976. subscriber.complete();
  2977. });
  2978. }
  2979. else {
  2980. return new Observable(function (subscriber) {
  2981. var keys = Object.keys(obj);
  2982. var subscription = new Subscription();
  2983. subscription.add(scheduler.schedule(dispatch$5, 0, { keys: keys, index: 0, subscriber: subscriber, subscription: subscription, obj: obj }));
  2984. return subscription;
  2985. });
  2986. }
  2987. }
  2988. function dispatch$5(state) {
  2989. var keys = state.keys, index = state.index, subscriber = state.subscriber, subscription = state.subscription, obj = state.obj;
  2990. if (!subscriber.closed) {
  2991. if (index < keys.length) {
  2992. var key = keys[index];
  2993. subscriber.next([key, obj[key]]);
  2994. subscription.add(this.schedule({ keys: keys, index: index + 1, subscriber: subscriber, subscription: subscription, obj: obj }));
  2995. }
  2996. else {
  2997. subscriber.complete();
  2998. }
  2999. }
  3000. }
  3001. function not(pred, thisArg) {
  3002. function notPred() {
  3003. return !(notPred.pred.apply(notPred.thisArg, arguments));
  3004. }
  3005. notPred.pred = pred;
  3006. notPred.thisArg = thisArg;
  3007. return notPred;
  3008. }
  3009. function filter(predicate, thisArg) {
  3010. return function filterOperatorFunction(source) {
  3011. return source.lift(new FilterOperator(predicate, thisArg));
  3012. };
  3013. }
  3014. var FilterOperator = (function () {
  3015. function FilterOperator(predicate, thisArg) {
  3016. this.predicate = predicate;
  3017. this.thisArg = thisArg;
  3018. }
  3019. FilterOperator.prototype.call = function (subscriber, source) {
  3020. return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
  3021. };
  3022. return FilterOperator;
  3023. }());
  3024. var FilterSubscriber = (function (_super) {
  3025. __extends(FilterSubscriber, _super);
  3026. function FilterSubscriber(destination, predicate, thisArg) {
  3027. var _this = _super.call(this, destination) || this;
  3028. _this.predicate = predicate;
  3029. _this.thisArg = thisArg;
  3030. _this.count = 0;
  3031. return _this;
  3032. }
  3033. FilterSubscriber.prototype._next = function (value) {
  3034. var result;
  3035. try {
  3036. result = this.predicate.call(this.thisArg, value, this.count++);
  3037. }
  3038. catch (err) {
  3039. this.destination.error(err);
  3040. return;
  3041. }
  3042. if (result) {
  3043. this.destination.next(value);
  3044. }
  3045. };
  3046. return FilterSubscriber;
  3047. }(Subscriber));
  3048. function race() {
  3049. var observables = [];
  3050. for (var _i = 0; _i < arguments.length; _i++) {
  3051. observables[_i] = arguments[_i];
  3052. }
  3053. if (observables.length === 1) {
  3054. if (isArray(observables[0])) {
  3055. observables = observables[0];
  3056. }
  3057. else {
  3058. return observables[0];
  3059. }
  3060. }
  3061. return fromArray(observables, undefined).lift(new RaceOperator());
  3062. }
  3063. var RaceOperator = (function () {
  3064. function RaceOperator() {
  3065. }
  3066. RaceOperator.prototype.call = function (subscriber, source) {
  3067. return source.subscribe(new RaceSubscriber(subscriber));
  3068. };
  3069. return RaceOperator;
  3070. }());
  3071. var RaceSubscriber = (function (_super) {
  3072. __extends(RaceSubscriber, _super);
  3073. function RaceSubscriber(destination) {
  3074. var _this = _super.call(this, destination) || this;
  3075. _this.hasFirst = false;
  3076. _this.observables = [];
  3077. _this.subscriptions = [];
  3078. return _this;
  3079. }
  3080. RaceSubscriber.prototype._next = function (observable) {
  3081. this.observables.push(observable);
  3082. };
  3083. RaceSubscriber.prototype._complete = function () {
  3084. var observables = this.observables;
  3085. var len = observables.length;
  3086. if (len === 0) {
  3087. this.destination.complete();
  3088. }
  3089. else {
  3090. for (var i = 0; i < len && !this.hasFirst; i++) {
  3091. var observable = observables[i];
  3092. var subscription = subscribeToResult(this, observable, observable, i);
  3093. if (this.subscriptions) {
  3094. this.subscriptions.push(subscription);
  3095. }
  3096. this.add(subscription);
  3097. }
  3098. this.observables = null;
  3099. }
  3100. };
  3101. RaceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  3102. if (!this.hasFirst) {
  3103. this.hasFirst = true;
  3104. for (var i = 0; i < this.subscriptions.length; i++) {
  3105. if (i !== outerIndex) {
  3106. var subscription = this.subscriptions[i];
  3107. subscription.unsubscribe();
  3108. this.remove(subscription);
  3109. }
  3110. }
  3111. this.subscriptions = null;
  3112. }
  3113. this.destination.next(innerValue);
  3114. };
  3115. return RaceSubscriber;
  3116. }(OuterSubscriber));
  3117. function range(start, count, scheduler) {
  3118. if (start === void 0) { start = 0; }
  3119. return new Observable(function (subscriber) {
  3120. if (count === undefined) {
  3121. count = start;
  3122. start = 0;
  3123. }
  3124. var index = 0;
  3125. var current = start;
  3126. if (scheduler) {
  3127. return scheduler.schedule(dispatch$6, 0, {
  3128. index: index, count: count, start: start, subscriber: subscriber
  3129. });
  3130. }
  3131. else {
  3132. do {
  3133. if (index++ >= count) {
  3134. subscriber.complete();
  3135. break;
  3136. }
  3137. subscriber.next(current++);
  3138. if (subscriber.closed) {
  3139. break;
  3140. }
  3141. } while (true);
  3142. }
  3143. return undefined;
  3144. });
  3145. }
  3146. function dispatch$6(state) {
  3147. var start = state.start, index = state.index, count = state.count, subscriber = state.subscriber;
  3148. if (index >= count) {
  3149. subscriber.complete();
  3150. return;
  3151. }
  3152. subscriber.next(start);
  3153. if (subscriber.closed) {
  3154. return;
  3155. }
  3156. state.index = index + 1;
  3157. state.start = start + 1;
  3158. this.schedule(state);
  3159. }
  3160. function timer(dueTime, periodOrScheduler, scheduler) {
  3161. if (dueTime === void 0) { dueTime = 0; }
  3162. var period = -1;
  3163. if (isNumeric(periodOrScheduler)) {
  3164. period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler);
  3165. }
  3166. else if (isScheduler(periodOrScheduler)) {
  3167. scheduler = periodOrScheduler;
  3168. }
  3169. if (!isScheduler(scheduler)) {
  3170. scheduler = async;
  3171. }
  3172. return new Observable(function (subscriber) {
  3173. var due = isNumeric(dueTime)
  3174. ? dueTime
  3175. : (+dueTime - scheduler.now());
  3176. return scheduler.schedule(dispatch$7, due, {
  3177. index: 0, period: period, subscriber: subscriber
  3178. });
  3179. });
  3180. }
  3181. function dispatch$7(state) {
  3182. var index = state.index, period = state.period, subscriber = state.subscriber;
  3183. subscriber.next(index);
  3184. if (subscriber.closed) {
  3185. return;
  3186. }
  3187. else if (period === -1) {
  3188. return subscriber.complete();
  3189. }
  3190. state.index = index + 1;
  3191. this.schedule(state, period);
  3192. }
  3193. function using(resourceFactory, observableFactory) {
  3194. return new Observable(function (subscriber) {
  3195. var resource;
  3196. try {
  3197. resource = resourceFactory();
  3198. }
  3199. catch (err) {
  3200. subscriber.error(err);
  3201. return undefined;
  3202. }
  3203. var result;
  3204. try {
  3205. result = observableFactory(resource);
  3206. }
  3207. catch (err) {
  3208. subscriber.error(err);
  3209. return undefined;
  3210. }
  3211. var source = result ? from(result) : EMPTY;
  3212. var subscription = source.subscribe(subscriber);
  3213. return function () {
  3214. subscription.unsubscribe();
  3215. if (resource) {
  3216. resource.unsubscribe();
  3217. }
  3218. };
  3219. });
  3220. }
  3221. function zip() {
  3222. var observables = [];
  3223. for (var _i = 0; _i < arguments.length; _i++) {
  3224. observables[_i] = arguments[_i];
  3225. }
  3226. var resultSelector = observables[observables.length - 1];
  3227. if (typeof resultSelector === 'function') {
  3228. observables.pop();
  3229. }
  3230. return fromArray(observables, undefined).lift(new ZipOperator(resultSelector));
  3231. }
  3232. var ZipOperator = (function () {
  3233. function ZipOperator(resultSelector) {
  3234. this.resultSelector = resultSelector;
  3235. }
  3236. ZipOperator.prototype.call = function (subscriber, source) {
  3237. return source.subscribe(new ZipSubscriber(subscriber, this.resultSelector));
  3238. };
  3239. return ZipOperator;
  3240. }());
  3241. var ZipSubscriber = (function (_super) {
  3242. __extends(ZipSubscriber, _super);
  3243. function ZipSubscriber(destination, resultSelector, values) {
  3244. if (values === void 0) { values = Object.create(null); }
  3245. var _this = _super.call(this, destination) || this;
  3246. _this.iterators = [];
  3247. _this.active = 0;
  3248. _this.resultSelector = (typeof resultSelector === 'function') ? resultSelector : null;
  3249. _this.values = values;
  3250. return _this;
  3251. }
  3252. ZipSubscriber.prototype._next = function (value) {
  3253. var iterators = this.iterators;
  3254. if (isArray(value)) {
  3255. iterators.push(new StaticArrayIterator(value));
  3256. }
  3257. else if (typeof value[iterator] === 'function') {
  3258. iterators.push(new StaticIterator(value[iterator]()));
  3259. }
  3260. else {
  3261. iterators.push(new ZipBufferIterator(this.destination, this, value));
  3262. }
  3263. };
  3264. ZipSubscriber.prototype._complete = function () {
  3265. var iterators = this.iterators;
  3266. var len = iterators.length;
  3267. this.unsubscribe();
  3268. if (len === 0) {
  3269. this.destination.complete();
  3270. return;
  3271. }
  3272. this.active = len;
  3273. for (var i = 0; i < len; i++) {
  3274. var iterator$$1 = iterators[i];
  3275. if (iterator$$1.stillUnsubscribed) {
  3276. var destination = this.destination;
  3277. destination.add(iterator$$1.subscribe(iterator$$1, i));
  3278. }
  3279. else {
  3280. this.active--;
  3281. }
  3282. }
  3283. };
  3284. ZipSubscriber.prototype.notifyInactive = function () {
  3285. this.active--;
  3286. if (this.active === 0) {
  3287. this.destination.complete();
  3288. }
  3289. };
  3290. ZipSubscriber.prototype.checkIterators = function () {
  3291. var iterators = this.iterators;
  3292. var len = iterators.length;
  3293. var destination = this.destination;
  3294. for (var i = 0; i < len; i++) {
  3295. var iterator$$1 = iterators[i];
  3296. if (typeof iterator$$1.hasValue === 'function' && !iterator$$1.hasValue()) {
  3297. return;
  3298. }
  3299. }
  3300. var shouldComplete = false;
  3301. var args = [];
  3302. for (var i = 0; i < len; i++) {
  3303. var iterator$$1 = iterators[i];
  3304. var result = iterator$$1.next();
  3305. if (iterator$$1.hasCompleted()) {
  3306. shouldComplete = true;
  3307. }
  3308. if (result.done) {
  3309. destination.complete();
  3310. return;
  3311. }
  3312. args.push(result.value);
  3313. }
  3314. if (this.resultSelector) {
  3315. this._tryresultSelector(args);
  3316. }
  3317. else {
  3318. destination.next(args);
  3319. }
  3320. if (shouldComplete) {
  3321. destination.complete();
  3322. }
  3323. };
  3324. ZipSubscriber.prototype._tryresultSelector = function (args) {
  3325. var result;
  3326. try {
  3327. result = this.resultSelector.apply(this, args);
  3328. }
  3329. catch (err) {
  3330. this.destination.error(err);
  3331. return;
  3332. }
  3333. this.destination.next(result);
  3334. };
  3335. return ZipSubscriber;
  3336. }(Subscriber));
  3337. var StaticIterator = (function () {
  3338. function StaticIterator(iterator$$1) {
  3339. this.iterator = iterator$$1;
  3340. this.nextResult = iterator$$1.next();
  3341. }
  3342. StaticIterator.prototype.hasValue = function () {
  3343. return true;
  3344. };
  3345. StaticIterator.prototype.next = function () {
  3346. var result = this.nextResult;
  3347. this.nextResult = this.iterator.next();
  3348. return result;
  3349. };
  3350. StaticIterator.prototype.hasCompleted = function () {
  3351. var nextResult = this.nextResult;
  3352. return nextResult && nextResult.done;
  3353. };
  3354. return StaticIterator;
  3355. }());
  3356. var StaticArrayIterator = (function () {
  3357. function StaticArrayIterator(array) {
  3358. this.array = array;
  3359. this.index = 0;
  3360. this.length = 0;
  3361. this.length = array.length;
  3362. }
  3363. StaticArrayIterator.prototype[iterator] = function () {
  3364. return this;
  3365. };
  3366. StaticArrayIterator.prototype.next = function (value) {
  3367. var i = this.index++;
  3368. var array = this.array;
  3369. return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
  3370. };
  3371. StaticArrayIterator.prototype.hasValue = function () {
  3372. return this.array.length > this.index;
  3373. };
  3374. StaticArrayIterator.prototype.hasCompleted = function () {
  3375. return this.array.length === this.index;
  3376. };
  3377. return StaticArrayIterator;
  3378. }());
  3379. var ZipBufferIterator = (function (_super) {
  3380. __extends(ZipBufferIterator, _super);
  3381. function ZipBufferIterator(destination, parent, observable) {
  3382. var _this = _super.call(this, destination) || this;
  3383. _this.parent = parent;
  3384. _this.observable = observable;
  3385. _this.stillUnsubscribed = true;
  3386. _this.buffer = [];
  3387. _this.isComplete = false;
  3388. return _this;
  3389. }
  3390. ZipBufferIterator.prototype[iterator] = function () {
  3391. return this;
  3392. };
  3393. ZipBufferIterator.prototype.next = function () {
  3394. var buffer = this.buffer;
  3395. if (buffer.length === 0 && this.isComplete) {
  3396. return { value: null, done: true };
  3397. }
  3398. else {
  3399. return { value: buffer.shift(), done: false };
  3400. }
  3401. };
  3402. ZipBufferIterator.prototype.hasValue = function () {
  3403. return this.buffer.length > 0;
  3404. };
  3405. ZipBufferIterator.prototype.hasCompleted = function () {
  3406. return this.buffer.length === 0 && this.isComplete;
  3407. };
  3408. ZipBufferIterator.prototype.notifyComplete = function () {
  3409. if (this.buffer.length > 0) {
  3410. this.isComplete = true;
  3411. this.parent.notifyInactive();
  3412. }
  3413. else {
  3414. this.destination.complete();
  3415. }
  3416. };
  3417. ZipBufferIterator.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  3418. this.buffer.push(innerValue);
  3419. this.parent.checkIterators();
  3420. };
  3421. ZipBufferIterator.prototype.subscribe = function (value, index) {
  3422. return subscribeToResult(this, this.observable, this, index);
  3423. };
  3424. return ZipBufferIterator;
  3425. }(OuterSubscriber));
  3426. var __window = typeof window !== 'undefined' && window;
  3427. var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
  3428. self instanceof WorkerGlobalScope && self;
  3429. var __global = typeof global !== 'undefined' && global;
  3430. var _root = __window || __global || __self;
  3431. (function () {
  3432. if (!_root) {
  3433. throw new Error('RxJS could not find any global context (window, self, global)');
  3434. }
  3435. })();
  3436. function getCORSRequest() {
  3437. if (_root.XMLHttpRequest) {
  3438. return new _root.XMLHttpRequest();
  3439. }
  3440. else if (!!_root.XDomainRequest) {
  3441. return new _root.XDomainRequest();
  3442. }
  3443. else {
  3444. throw new Error('CORS is not supported by your browser');
  3445. }
  3446. }
  3447. function getXMLHttpRequest() {
  3448. if (_root.XMLHttpRequest) {
  3449. return new _root.XMLHttpRequest();
  3450. }
  3451. else {
  3452. var progId = void 0;
  3453. try {
  3454. var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
  3455. for (var i = 0; i < 3; i++) {
  3456. try {
  3457. progId = progIds[i];
  3458. if (new _root.ActiveXObject(progId)) {
  3459. break;
  3460. }
  3461. }
  3462. catch (e) {
  3463. }
  3464. }
  3465. return new _root.ActiveXObject(progId);
  3466. }
  3467. catch (e) {
  3468. throw new Error('XMLHttpRequest is not supported by your browser');
  3469. }
  3470. }
  3471. }
  3472. function ajaxGet(url, headers) {
  3473. if (headers === void 0) { headers = null; }
  3474. return new AjaxObservable({ method: 'GET', url: url, headers: headers });
  3475. }
  3476. function ajaxPost(url, body, headers) {
  3477. return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers });
  3478. }
  3479. function ajaxDelete(url, headers) {
  3480. return new AjaxObservable({ method: 'DELETE', url: url, headers: headers });
  3481. }
  3482. function ajaxPut(url, body, headers) {
  3483. return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers });
  3484. }
  3485. function ajaxPatch(url, body, headers) {
  3486. return new AjaxObservable({ method: 'PATCH', url: url, body: body, headers: headers });
  3487. }
  3488. var mapResponse = map(function (x, index) { return x.response; });
  3489. function ajaxGetJSON(url, headers) {
  3490. return mapResponse(new AjaxObservable({
  3491. method: 'GET',
  3492. url: url,
  3493. responseType: 'json',
  3494. headers: headers
  3495. }));
  3496. }
  3497. var AjaxObservable = (function (_super) {
  3498. __extends(AjaxObservable, _super);
  3499. function AjaxObservable(urlOrRequest) {
  3500. var _this = _super.call(this) || this;
  3501. var request = {
  3502. async: true,
  3503. createXHR: function () {
  3504. return this.crossDomain ? getCORSRequest() : getXMLHttpRequest();
  3505. },
  3506. crossDomain: true,
  3507. withCredentials: false,
  3508. headers: {},
  3509. method: 'GET',
  3510. responseType: 'json',
  3511. timeout: 0
  3512. };
  3513. if (typeof urlOrRequest === 'string') {
  3514. request.url = urlOrRequest;
  3515. }
  3516. else {
  3517. for (var prop in urlOrRequest) {
  3518. if (urlOrRequest.hasOwnProperty(prop)) {
  3519. request[prop] = urlOrRequest[prop];
  3520. }
  3521. }
  3522. }
  3523. _this.request = request;
  3524. return _this;
  3525. }
  3526. AjaxObservable.prototype._subscribe = function (subscriber) {
  3527. return new AjaxSubscriber(subscriber, this.request);
  3528. };
  3529. AjaxObservable.create = (function () {
  3530. var create = function (urlOrRequest) {
  3531. return new AjaxObservable(urlOrRequest);
  3532. };
  3533. create.get = ajaxGet;
  3534. create.post = ajaxPost;
  3535. create.delete = ajaxDelete;
  3536. create.put = ajaxPut;
  3537. create.patch = ajaxPatch;
  3538. create.getJSON = ajaxGetJSON;
  3539. return create;
  3540. })();
  3541. return AjaxObservable;
  3542. }(Observable));
  3543. var AjaxSubscriber = (function (_super) {
  3544. __extends(AjaxSubscriber, _super);
  3545. function AjaxSubscriber(destination, request) {
  3546. var _this = _super.call(this, destination) || this;
  3547. _this.request = request;
  3548. _this.done = false;
  3549. var headers = request.headers = request.headers || {};
  3550. if (!request.crossDomain && !_this.getHeader(headers, 'X-Requested-With')) {
  3551. headers['X-Requested-With'] = 'XMLHttpRequest';
  3552. }
  3553. var contentTypeHeader = _this.getHeader(headers, 'Content-Type');
  3554. if (!contentTypeHeader && !(_root.FormData && request.body instanceof _root.FormData) && typeof request.body !== 'undefined') {
  3555. headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
  3556. }
  3557. request.body = _this.serializeBody(request.body, _this.getHeader(request.headers, 'Content-Type'));
  3558. _this.send();
  3559. return _this;
  3560. }
  3561. AjaxSubscriber.prototype.next = function (e) {
  3562. this.done = true;
  3563. var _a = this, xhr = _a.xhr, request = _a.request, destination = _a.destination;
  3564. var result;
  3565. try {
  3566. result = new AjaxResponse(e, xhr, request);
  3567. }
  3568. catch (err) {
  3569. return destination.error(err);
  3570. }
  3571. destination.next(result);
  3572. };
  3573. AjaxSubscriber.prototype.send = function () {
  3574. var _a = this, request = _a.request, _b = _a.request, user = _b.user, method = _b.method, url = _b.url, async = _b.async, password = _b.password, headers = _b.headers, body = _b.body;
  3575. try {
  3576. var xhr = this.xhr = request.createXHR();
  3577. this.setupEvents(xhr, request);
  3578. if (user) {
  3579. xhr.open(method, url, async, user, password);
  3580. }
  3581. else {
  3582. xhr.open(method, url, async);
  3583. }
  3584. if (async) {
  3585. xhr.timeout = request.timeout;
  3586. xhr.responseType = request.responseType;
  3587. }
  3588. if ('withCredentials' in xhr) {
  3589. xhr.withCredentials = !!request.withCredentials;
  3590. }
  3591. this.setHeaders(xhr, headers);
  3592. if (body) {
  3593. xhr.send(body);
  3594. }
  3595. else {
  3596. xhr.send();
  3597. }
  3598. }
  3599. catch (err) {
  3600. this.error(err);
  3601. }
  3602. };
  3603. AjaxSubscriber.prototype.serializeBody = function (body, contentType) {
  3604. if (!body || typeof body === 'string') {
  3605. return body;
  3606. }
  3607. else if (_root.FormData && body instanceof _root.FormData) {
  3608. return body;
  3609. }
  3610. if (contentType) {
  3611. var splitIndex = contentType.indexOf(';');
  3612. if (splitIndex !== -1) {
  3613. contentType = contentType.substring(0, splitIndex);
  3614. }
  3615. }
  3616. switch (contentType) {
  3617. case 'application/x-www-form-urlencoded':
  3618. return Object.keys(body).map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(body[key]); }).join('&');
  3619. case 'application/json':
  3620. return JSON.stringify(body);
  3621. default:
  3622. return body;
  3623. }
  3624. };
  3625. AjaxSubscriber.prototype.setHeaders = function (xhr, headers) {
  3626. for (var key in headers) {
  3627. if (headers.hasOwnProperty(key)) {
  3628. xhr.setRequestHeader(key, headers[key]);
  3629. }
  3630. }
  3631. };
  3632. AjaxSubscriber.prototype.getHeader = function (headers, headerName) {
  3633. for (var key in headers) {
  3634. if (key.toLowerCase() === headerName.toLowerCase()) {
  3635. return headers[key];
  3636. }
  3637. }
  3638. return undefined;
  3639. };
  3640. AjaxSubscriber.prototype.setupEvents = function (xhr, request) {
  3641. var progressSubscriber = request.progressSubscriber;
  3642. function xhrTimeout(e) {
  3643. var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
  3644. if (progressSubscriber) {
  3645. progressSubscriber.error(e);
  3646. }
  3647. var error;
  3648. try {
  3649. error = new AjaxTimeoutError(this, request);
  3650. }
  3651. catch (err) {
  3652. error = err;
  3653. }
  3654. subscriber.error(error);
  3655. }
  3656. xhr.ontimeout = xhrTimeout;
  3657. xhrTimeout.request = request;
  3658. xhrTimeout.subscriber = this;
  3659. xhrTimeout.progressSubscriber = progressSubscriber;
  3660. if (xhr.upload && 'withCredentials' in xhr) {
  3661. if (progressSubscriber) {
  3662. var xhrProgress_1;
  3663. xhrProgress_1 = function (e) {
  3664. var progressSubscriber = xhrProgress_1.progressSubscriber;
  3665. progressSubscriber.next(e);
  3666. };
  3667. if (_root.XDomainRequest) {
  3668. xhr.onprogress = xhrProgress_1;
  3669. }
  3670. else {
  3671. xhr.upload.onprogress = xhrProgress_1;
  3672. }
  3673. xhrProgress_1.progressSubscriber = progressSubscriber;
  3674. }
  3675. var xhrError_1;
  3676. xhrError_1 = function (e) {
  3677. var _a = xhrError_1, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request;
  3678. if (progressSubscriber) {
  3679. progressSubscriber.error(e);
  3680. }
  3681. var error;
  3682. try {
  3683. error = new AjaxError('ajax error', this, request);
  3684. }
  3685. catch (err) {
  3686. error = err;
  3687. }
  3688. subscriber.error(error);
  3689. };
  3690. xhr.onerror = xhrError_1;
  3691. xhrError_1.request = request;
  3692. xhrError_1.subscriber = this;
  3693. xhrError_1.progressSubscriber = progressSubscriber;
  3694. }
  3695. function xhrReadyStateChange(e) {
  3696. return;
  3697. }
  3698. xhr.onreadystatechange = xhrReadyStateChange;
  3699. xhrReadyStateChange.subscriber = this;
  3700. xhrReadyStateChange.progressSubscriber = progressSubscriber;
  3701. xhrReadyStateChange.request = request;
  3702. function xhrLoad(e) {
  3703. var _a = xhrLoad, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
  3704. if (this.readyState === 4) {
  3705. var status_1 = this.status === 1223 ? 204 : this.status;
  3706. var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response);
  3707. if (status_1 === 0) {
  3708. status_1 = response ? 200 : 0;
  3709. }
  3710. if (status_1 < 400) {
  3711. if (progressSubscriber) {
  3712. progressSubscriber.complete();
  3713. }
  3714. subscriber.next(e);
  3715. subscriber.complete();
  3716. }
  3717. else {
  3718. if (progressSubscriber) {
  3719. progressSubscriber.error(e);
  3720. }
  3721. var error = void 0;
  3722. try {
  3723. error = new AjaxError('ajax error ' + status_1, this, request);
  3724. }
  3725. catch (err) {
  3726. error = err;
  3727. }
  3728. subscriber.error(error);
  3729. }
  3730. }
  3731. }
  3732. xhr.onload = xhrLoad;
  3733. xhrLoad.subscriber = this;
  3734. xhrLoad.progressSubscriber = progressSubscriber;
  3735. xhrLoad.request = request;
  3736. };
  3737. AjaxSubscriber.prototype.unsubscribe = function () {
  3738. var _a = this, done = _a.done, xhr = _a.xhr;
  3739. if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') {
  3740. xhr.abort();
  3741. }
  3742. _super.prototype.unsubscribe.call(this);
  3743. };
  3744. return AjaxSubscriber;
  3745. }(Subscriber));
  3746. var AjaxResponse = (function () {
  3747. function AjaxResponse(originalEvent, xhr, request) {
  3748. this.originalEvent = originalEvent;
  3749. this.xhr = xhr;
  3750. this.request = request;
  3751. this.status = xhr.status;
  3752. this.responseType = xhr.responseType || request.responseType;
  3753. this.response = parseXhrResponse(this.responseType, xhr);
  3754. }
  3755. return AjaxResponse;
  3756. }());
  3757. var AjaxErrorImpl = (function () {
  3758. function AjaxErrorImpl(message, xhr, request) {
  3759. Error.call(this);
  3760. this.message = message;
  3761. this.name = 'AjaxError';
  3762. this.xhr = xhr;
  3763. this.request = request;
  3764. this.status = xhr.status;
  3765. this.responseType = xhr.responseType || request.responseType;
  3766. this.response = parseXhrResponse(this.responseType, xhr);
  3767. return this;
  3768. }
  3769. AjaxErrorImpl.prototype = Object.create(Error.prototype);
  3770. return AjaxErrorImpl;
  3771. })();
  3772. var AjaxError = AjaxErrorImpl;
  3773. function parseJson(xhr) {
  3774. if ('response' in xhr) {
  3775. return xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
  3776. }
  3777. else {
  3778. return JSON.parse(xhr.responseText || 'null');
  3779. }
  3780. }
  3781. function parseXhrResponse(responseType, xhr) {
  3782. switch (responseType) {
  3783. case 'json':
  3784. return parseJson(xhr);
  3785. case 'xml':
  3786. return xhr.responseXML;
  3787. case 'text':
  3788. default:
  3789. return ('response' in xhr) ? xhr.response : xhr.responseText;
  3790. }
  3791. }
  3792. function AjaxTimeoutErrorImpl(xhr, request) {
  3793. AjaxError.call(this, 'ajax timeout', xhr, request);
  3794. this.name = 'AjaxTimeoutError';
  3795. return this;
  3796. }
  3797. var AjaxTimeoutError = AjaxTimeoutErrorImpl;
  3798. var ajax = (function () { return AjaxObservable.create; })();
  3799. var DEFAULT_WEBSOCKET_CONFIG = {
  3800. url: '',
  3801. deserializer: function (e) { return JSON.parse(e.data); },
  3802. serializer: function (value) { return JSON.stringify(value); },
  3803. };
  3804. var WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT = 'WebSocketSubject.error must be called with an object with an error code, and an optional reason: { code: number, reason: string }';
  3805. var WebSocketSubject = (function (_super) {
  3806. __extends(WebSocketSubject, _super);
  3807. function WebSocketSubject(urlConfigOrSource, destination) {
  3808. var _this = _super.call(this) || this;
  3809. if (urlConfigOrSource instanceof Observable) {
  3810. _this.destination = destination;
  3811. _this.source = urlConfigOrSource;
  3812. }
  3813. else {
  3814. var config = _this._config = __assign({}, DEFAULT_WEBSOCKET_CONFIG);
  3815. _this._output = new Subject();
  3816. if (typeof urlConfigOrSource === 'string') {
  3817. config.url = urlConfigOrSource;
  3818. }
  3819. else {
  3820. for (var key in urlConfigOrSource) {
  3821. if (urlConfigOrSource.hasOwnProperty(key)) {
  3822. config[key] = urlConfigOrSource[key];
  3823. }
  3824. }
  3825. }
  3826. if (!config.WebSocketCtor && WebSocket) {
  3827. config.WebSocketCtor = WebSocket;
  3828. }
  3829. else if (!config.WebSocketCtor) {
  3830. throw new Error('no WebSocket constructor can be found');
  3831. }
  3832. _this.destination = new ReplaySubject();
  3833. }
  3834. return _this;
  3835. }
  3836. WebSocketSubject.prototype.lift = function (operator) {
  3837. var sock = new WebSocketSubject(this._config, this.destination);
  3838. sock.operator = operator;
  3839. sock.source = this;
  3840. return sock;
  3841. };
  3842. WebSocketSubject.prototype._resetState = function () {
  3843. this._socket = null;
  3844. if (!this.source) {
  3845. this.destination = new ReplaySubject();
  3846. }
  3847. this._output = new Subject();
  3848. };
  3849. WebSocketSubject.prototype.multiplex = function (subMsg, unsubMsg, messageFilter) {
  3850. var self = this;
  3851. return new Observable(function (observer) {
  3852. try {
  3853. self.next(subMsg());
  3854. }
  3855. catch (err) {
  3856. observer.error(err);
  3857. }
  3858. var subscription = self.subscribe(function (x) {
  3859. try {
  3860. if (messageFilter(x)) {
  3861. observer.next(x);
  3862. }
  3863. }
  3864. catch (err) {
  3865. observer.error(err);
  3866. }
  3867. }, function (err) { return observer.error(err); }, function () { return observer.complete(); });
  3868. return function () {
  3869. try {
  3870. self.next(unsubMsg());
  3871. }
  3872. catch (err) {
  3873. observer.error(err);
  3874. }
  3875. subscription.unsubscribe();
  3876. };
  3877. });
  3878. };
  3879. WebSocketSubject.prototype._connectSocket = function () {
  3880. var _this = this;
  3881. var _a = this._config, WebSocketCtor = _a.WebSocketCtor, protocol = _a.protocol, url = _a.url, binaryType = _a.binaryType;
  3882. var observer = this._output;
  3883. var socket = null;
  3884. try {
  3885. socket = protocol ?
  3886. new WebSocketCtor(url, protocol) :
  3887. new WebSocketCtor(url);
  3888. this._socket = socket;
  3889. if (binaryType) {
  3890. this._socket.binaryType = binaryType;
  3891. }
  3892. }
  3893. catch (e) {
  3894. observer.error(e);
  3895. return;
  3896. }
  3897. var subscription = new Subscription(function () {
  3898. _this._socket = null;
  3899. if (socket && socket.readyState === 1) {
  3900. socket.close();
  3901. }
  3902. });
  3903. socket.onopen = function (e) {
  3904. var _socket = _this._socket;
  3905. if (!_socket) {
  3906. socket.close();
  3907. _this._resetState();
  3908. return;
  3909. }
  3910. var openObserver = _this._config.openObserver;
  3911. if (openObserver) {
  3912. openObserver.next(e);
  3913. }
  3914. var queue = _this.destination;
  3915. _this.destination = Subscriber.create(function (x) {
  3916. if (socket.readyState === 1) {
  3917. try {
  3918. var serializer = _this._config.serializer;
  3919. socket.send(serializer(x));
  3920. }
  3921. catch (e) {
  3922. _this.destination.error(e);
  3923. }
  3924. }
  3925. }, function (e) {
  3926. var closingObserver = _this._config.closingObserver;
  3927. if (closingObserver) {
  3928. closingObserver.next(undefined);
  3929. }
  3930. if (e && e.code) {
  3931. socket.close(e.code, e.reason);
  3932. }
  3933. else {
  3934. observer.error(new TypeError(WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT));
  3935. }
  3936. _this._resetState();
  3937. }, function () {
  3938. var closingObserver = _this._config.closingObserver;
  3939. if (closingObserver) {
  3940. closingObserver.next(undefined);
  3941. }
  3942. socket.close();
  3943. _this._resetState();
  3944. });
  3945. if (queue && queue instanceof ReplaySubject) {
  3946. subscription.add(queue.subscribe(_this.destination));
  3947. }
  3948. };
  3949. socket.onerror = function (e) {
  3950. _this._resetState();
  3951. observer.error(e);
  3952. };
  3953. socket.onclose = function (e) {
  3954. _this._resetState();
  3955. var closeObserver = _this._config.closeObserver;
  3956. if (closeObserver) {
  3957. closeObserver.next(e);
  3958. }
  3959. if (e.wasClean) {
  3960. observer.complete();
  3961. }
  3962. else {
  3963. observer.error(e);
  3964. }
  3965. };
  3966. socket.onmessage = function (e) {
  3967. try {
  3968. var deserializer = _this._config.deserializer;
  3969. observer.next(deserializer(e));
  3970. }
  3971. catch (err) {
  3972. observer.error(err);
  3973. }
  3974. };
  3975. };
  3976. WebSocketSubject.prototype._subscribe = function (subscriber) {
  3977. var _this = this;
  3978. var source = this.source;
  3979. if (source) {
  3980. return source.subscribe(subscriber);
  3981. }
  3982. if (!this._socket) {
  3983. this._connectSocket();
  3984. }
  3985. this._output.subscribe(subscriber);
  3986. subscriber.add(function () {
  3987. var _socket = _this._socket;
  3988. if (_this._output.observers.length === 0) {
  3989. if (_socket && _socket.readyState === 1) {
  3990. _socket.close();
  3991. }
  3992. _this._resetState();
  3993. }
  3994. });
  3995. return subscriber;
  3996. };
  3997. WebSocketSubject.prototype.unsubscribe = function () {
  3998. var _socket = this._socket;
  3999. if (_socket && _socket.readyState === 1) {
  4000. _socket.close();
  4001. }
  4002. this._resetState();
  4003. _super.prototype.unsubscribe.call(this);
  4004. };
  4005. return WebSocketSubject;
  4006. }(AnonymousSubject));
  4007. function webSocket(urlConfigOrSource) {
  4008. return new WebSocketSubject(urlConfigOrSource);
  4009. }
  4010. var SubscribeOnObservable = (function (_super) {
  4011. __extends(SubscribeOnObservable, _super);
  4012. function SubscribeOnObservable(source, delayTime, scheduler) {
  4013. if (delayTime === void 0) { delayTime = 0; }
  4014. if (scheduler === void 0) { scheduler = asap; }
  4015. var _this = _super.call(this) || this;
  4016. _this.source = source;
  4017. _this.delayTime = delayTime;
  4018. _this.scheduler = scheduler;
  4019. if (!isNumeric(delayTime) || delayTime < 0) {
  4020. _this.delayTime = 0;
  4021. }
  4022. if (!scheduler || typeof scheduler.schedule !== 'function') {
  4023. _this.scheduler = asap;
  4024. }
  4025. return _this;
  4026. }
  4027. SubscribeOnObservable.create = function (source, delay, scheduler) {
  4028. if (delay === void 0) { delay = 0; }
  4029. if (scheduler === void 0) { scheduler = asap; }
  4030. return new SubscribeOnObservable(source, delay, scheduler);
  4031. };
  4032. SubscribeOnObservable.dispatch = function (arg) {
  4033. var source = arg.source, subscriber = arg.subscriber;
  4034. return this.add(source.subscribe(subscriber));
  4035. };
  4036. SubscribeOnObservable.prototype._subscribe = function (subscriber) {
  4037. var delay = this.delayTime;
  4038. var source = this.source;
  4039. var scheduler = this.scheduler;
  4040. return scheduler.schedule(SubscribeOnObservable.dispatch, delay, {
  4041. source: source, subscriber: subscriber
  4042. });
  4043. };
  4044. return SubscribeOnObservable;
  4045. }(Observable));
  4046. function timestamp(scheduler) {
  4047. if (scheduler === void 0) { scheduler = async; }
  4048. return map(function (value) { return new Timestamp(value, scheduler.now()); });
  4049. }
  4050. var Timestamp = (function () {
  4051. function Timestamp(value, timestamp) {
  4052. this.value = value;
  4053. this.timestamp = timestamp;
  4054. }
  4055. return Timestamp;
  4056. }());
  4057. function scan(accumulator, seed) {
  4058. var hasSeed = false;
  4059. if (arguments.length >= 2) {
  4060. hasSeed = true;
  4061. }
  4062. return function scanOperatorFunction(source) {
  4063. return source.lift(new ScanOperator(accumulator, seed, hasSeed));
  4064. };
  4065. }
  4066. var ScanOperator = (function () {
  4067. function ScanOperator(accumulator, seed, hasSeed) {
  4068. if (hasSeed === void 0) { hasSeed = false; }
  4069. this.accumulator = accumulator;
  4070. this.seed = seed;
  4071. this.hasSeed = hasSeed;
  4072. }
  4073. ScanOperator.prototype.call = function (subscriber, source) {
  4074. return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
  4075. };
  4076. return ScanOperator;
  4077. }());
  4078. var ScanSubscriber = (function (_super) {
  4079. __extends(ScanSubscriber, _super);
  4080. function ScanSubscriber(destination, accumulator, _seed, hasSeed) {
  4081. var _this = _super.call(this, destination) || this;
  4082. _this.accumulator = accumulator;
  4083. _this._seed = _seed;
  4084. _this.hasSeed = hasSeed;
  4085. _this.index = 0;
  4086. return _this;
  4087. }
  4088. Object.defineProperty(ScanSubscriber.prototype, "seed", {
  4089. get: function () {
  4090. return this._seed;
  4091. },
  4092. set: function (value) {
  4093. this.hasSeed = true;
  4094. this._seed = value;
  4095. },
  4096. enumerable: true,
  4097. configurable: true
  4098. });
  4099. ScanSubscriber.prototype._next = function (value) {
  4100. if (!this.hasSeed) {
  4101. this.seed = value;
  4102. this.destination.next(value);
  4103. }
  4104. else {
  4105. return this._tryNext(value);
  4106. }
  4107. };
  4108. ScanSubscriber.prototype._tryNext = function (value) {
  4109. var index = this.index++;
  4110. var result;
  4111. try {
  4112. result = this.accumulator(this.seed, value, index);
  4113. }
  4114. catch (err) {
  4115. this.destination.error(err);
  4116. }
  4117. this.seed = result;
  4118. this.destination.next(result);
  4119. };
  4120. return ScanSubscriber;
  4121. }(Subscriber));
  4122. function timeInterval(scheduler) {
  4123. if (scheduler === void 0) { scheduler = async; }
  4124. return function (source) { return defer(function () {
  4125. return source.pipe(scan(function (_a, value) {
  4126. var current = _a.current;
  4127. return ({ value: value, current: scheduler.now(), last: current });
  4128. }, { current: scheduler.now(), value: undefined, last: undefined }), map(function (_a) {
  4129. var current = _a.current, last = _a.last, value = _a.value;
  4130. return new TimeInterval(value, current - last);
  4131. }));
  4132. }); };
  4133. }
  4134. var TimeInterval = (function () {
  4135. function TimeInterval(value, interval) {
  4136. this.value = value;
  4137. this.interval = interval;
  4138. }
  4139. return TimeInterval;
  4140. }());
  4141. var defaultThrottleConfig = {
  4142. leading: true,
  4143. trailing: false
  4144. };
  4145. function throttle(durationSelector, config) {
  4146. if (config === void 0) { config = defaultThrottleConfig; }
  4147. return function (source) { return source.lift(new ThrottleOperator(durationSelector, config.leading, config.trailing)); };
  4148. }
  4149. var ThrottleOperator = (function () {
  4150. function ThrottleOperator(durationSelector, leading, trailing) {
  4151. this.durationSelector = durationSelector;
  4152. this.leading = leading;
  4153. this.trailing = trailing;
  4154. }
  4155. ThrottleOperator.prototype.call = function (subscriber, source) {
  4156. return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
  4157. };
  4158. return ThrottleOperator;
  4159. }());
  4160. var ThrottleSubscriber = (function (_super) {
  4161. __extends(ThrottleSubscriber, _super);
  4162. function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
  4163. var _this = _super.call(this, destination) || this;
  4164. _this.destination = destination;
  4165. _this.durationSelector = durationSelector;
  4166. _this._leading = _leading;
  4167. _this._trailing = _trailing;
  4168. _this._hasValue = false;
  4169. return _this;
  4170. }
  4171. ThrottleSubscriber.prototype._next = function (value) {
  4172. this._hasValue = true;
  4173. this._sendValue = value;
  4174. if (!this._throttled) {
  4175. if (this._leading) {
  4176. this.send();
  4177. }
  4178. else {
  4179. this.throttle(value);
  4180. }
  4181. }
  4182. };
  4183. ThrottleSubscriber.prototype.send = function () {
  4184. var _a = this, _hasValue = _a._hasValue, _sendValue = _a._sendValue;
  4185. if (_hasValue) {
  4186. this.destination.next(_sendValue);
  4187. this.throttle(_sendValue);
  4188. }
  4189. this._hasValue = false;
  4190. this._sendValue = null;
  4191. };
  4192. ThrottleSubscriber.prototype.throttle = function (value) {
  4193. var duration = this.tryDurationSelector(value);
  4194. if (!!duration) {
  4195. this.add(this._throttled = subscribeToResult(this, duration));
  4196. }
  4197. };
  4198. ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
  4199. try {
  4200. return this.durationSelector(value);
  4201. }
  4202. catch (err) {
  4203. this.destination.error(err);
  4204. return null;
  4205. }
  4206. };
  4207. ThrottleSubscriber.prototype.throttlingDone = function () {
  4208. var _a = this, _throttled = _a._throttled, _trailing = _a._trailing;
  4209. if (_throttled) {
  4210. _throttled.unsubscribe();
  4211. }
  4212. this._throttled = null;
  4213. if (_trailing) {
  4214. this.send();
  4215. }
  4216. };
  4217. ThrottleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  4218. this.throttlingDone();
  4219. };
  4220. ThrottleSubscriber.prototype.notifyComplete = function () {
  4221. this.throttlingDone();
  4222. };
  4223. return ThrottleSubscriber;
  4224. }(OuterSubscriber));
  4225. function applyMixins(derivedCtor, baseCtors) {
  4226. for (var i = 0, len = baseCtors.length; i < len; i++) {
  4227. var baseCtor = baseCtors[i];
  4228. var propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
  4229. for (var j = 0, len2 = propertyKeys.length; j < len2; j++) {
  4230. var name_1 = propertyKeys[j];
  4231. derivedCtor.prototype[name_1] = baseCtor.prototype[name_1];
  4232. }
  4233. }
  4234. }
  4235. function isDate(value) {
  4236. return value instanceof Date && !isNaN(+value);
  4237. }
  4238. Observable.bindCallback = bindCallback;
  4239. Observable.bindNodeCallback = bindNodeCallback;
  4240. Observable.combineLatest = combineLatest;
  4241. Observable.concat = concat;
  4242. Observable.defer = defer;
  4243. Observable.empty = empty$1;
  4244. Observable.forkJoin = forkJoin;
  4245. Observable.from = from;
  4246. Observable.fromEvent = fromEvent;
  4247. Observable.fromEventPattern = fromEventPattern;
  4248. Observable.fromPromise = from;
  4249. Observable.generate = generate;
  4250. Observable.if = iif;
  4251. Observable.interval = interval;
  4252. Observable.merge = merge;
  4253. Observable.race = race;
  4254. function staticNever() {
  4255. return NEVER;
  4256. }
  4257. Observable.never = staticNever;
  4258. Observable.of = of;
  4259. Observable.onErrorResumeNext = onErrorResumeNext;
  4260. Observable.pairs = pairs;
  4261. Observable.range = range;
  4262. Observable.using = using;
  4263. Observable.throw = throwError;
  4264. Observable.throwError = throwError;
  4265. Observable.timer = timer;
  4266. Observable.zip = zip;
  4267. var _ajax = /*#__PURE__*/Object.freeze({
  4268. ajax: ajax,
  4269. AjaxResponse: AjaxResponse,
  4270. AjaxError: AjaxError,
  4271. AjaxTimeoutError: AjaxTimeoutError
  4272. });
  4273. Observable.ajax = ajax;
  4274. var _webSocket = /*#__PURE__*/Object.freeze({
  4275. webSocket: webSocket,
  4276. WebSocketSubject: WebSocketSubject
  4277. });
  4278. Observable.webSocket = webSocket;
  4279. function audit(durationSelector) {
  4280. return function auditOperatorFunction(source) {
  4281. return source.lift(new AuditOperator(durationSelector));
  4282. };
  4283. }
  4284. var AuditOperator = (function () {
  4285. function AuditOperator(durationSelector) {
  4286. this.durationSelector = durationSelector;
  4287. }
  4288. AuditOperator.prototype.call = function (subscriber, source) {
  4289. return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
  4290. };
  4291. return AuditOperator;
  4292. }());
  4293. var AuditSubscriber = (function (_super) {
  4294. __extends(AuditSubscriber, _super);
  4295. function AuditSubscriber(destination, durationSelector) {
  4296. var _this = _super.call(this, destination) || this;
  4297. _this.durationSelector = durationSelector;
  4298. _this.hasValue = false;
  4299. return _this;
  4300. }
  4301. AuditSubscriber.prototype._next = function (value) {
  4302. this.value = value;
  4303. this.hasValue = true;
  4304. if (!this.throttled) {
  4305. var duration = void 0;
  4306. try {
  4307. var durationSelector = this.durationSelector;
  4308. duration = durationSelector(value);
  4309. }
  4310. catch (err) {
  4311. return this.destination.error(err);
  4312. }
  4313. var innerSubscription = subscribeToResult(this, duration);
  4314. if (!innerSubscription || innerSubscription.closed) {
  4315. this.clearThrottle();
  4316. }
  4317. else {
  4318. this.add(this.throttled = innerSubscription);
  4319. }
  4320. }
  4321. };
  4322. AuditSubscriber.prototype.clearThrottle = function () {
  4323. var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled;
  4324. if (throttled) {
  4325. this.remove(throttled);
  4326. this.throttled = null;
  4327. throttled.unsubscribe();
  4328. }
  4329. if (hasValue) {
  4330. this.value = null;
  4331. this.hasValue = false;
  4332. this.destination.next(value);
  4333. }
  4334. };
  4335. AuditSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
  4336. this.clearThrottle();
  4337. };
  4338. AuditSubscriber.prototype.notifyComplete = function () {
  4339. this.clearThrottle();
  4340. };
  4341. return AuditSubscriber;
  4342. }(OuterSubscriber));
  4343. function auditTime(duration, scheduler) {
  4344. if (scheduler === void 0) { scheduler = async; }
  4345. return audit(function () { return timer(duration, scheduler); });
  4346. }
  4347. function buffer(closingNotifier) {
  4348. return function bufferOperatorFunction(source) {
  4349. return source.lift(new BufferOperator(closingNotifier));
  4350. };
  4351. }
  4352. var BufferOperator = (function () {
  4353. function BufferOperator(closingNotifier) {
  4354. this.closingNotifier = closingNotifier;
  4355. }
  4356. BufferOperator.prototype.call = function (subscriber, source) {
  4357. return source.subscribe(new BufferSubscriber(subscriber, this.closingNotifier));
  4358. };
  4359. return BufferOperator;
  4360. }());
  4361. var BufferSubscriber = (function (_super) {
  4362. __extends(BufferSubscriber, _super);
  4363. function BufferSubscriber(destination, closingNotifier) {
  4364. var _this = _super.call(this, destination) || this;
  4365. _this.buffer = [];
  4366. _this.add(subscribeToResult(_this, closingNotifier));
  4367. return _this;
  4368. }
  4369. BufferSubscriber.prototype._next = function (value) {
  4370. this.buffer.push(value);
  4371. };
  4372. BufferSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  4373. var buffer = this.buffer;
  4374. this.buffer = [];
  4375. this.destination.next(buffer);
  4376. };
  4377. return BufferSubscriber;
  4378. }(OuterSubscriber));
  4379. function bufferCount(bufferSize, startBufferEvery) {
  4380. if (startBufferEvery === void 0) { startBufferEvery = null; }
  4381. return function bufferCountOperatorFunction(source) {
  4382. return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
  4383. };
  4384. }
  4385. var BufferCountOperator = (function () {
  4386. function BufferCountOperator(bufferSize, startBufferEvery) {
  4387. this.bufferSize = bufferSize;
  4388. this.startBufferEvery = startBufferEvery;
  4389. if (!startBufferEvery || bufferSize === startBufferEvery) {
  4390. this.subscriberClass = BufferCountSubscriber;
  4391. }
  4392. else {
  4393. this.subscriberClass = BufferSkipCountSubscriber;
  4394. }
  4395. }
  4396. BufferCountOperator.prototype.call = function (subscriber, source) {
  4397. return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
  4398. };
  4399. return BufferCountOperator;
  4400. }());
  4401. var BufferCountSubscriber = (function (_super) {
  4402. __extends(BufferCountSubscriber, _super);
  4403. function BufferCountSubscriber(destination, bufferSize) {
  4404. var _this = _super.call(this, destination) || this;
  4405. _this.bufferSize = bufferSize;
  4406. _this.buffer = [];
  4407. return _this;
  4408. }
  4409. BufferCountSubscriber.prototype._next = function (value) {
  4410. var buffer = this.buffer;
  4411. buffer.push(value);
  4412. if (buffer.length == this.bufferSize) {
  4413. this.destination.next(buffer);
  4414. this.buffer = [];
  4415. }
  4416. };
  4417. BufferCountSubscriber.prototype._complete = function () {
  4418. var buffer = this.buffer;
  4419. if (buffer.length > 0) {
  4420. this.destination.next(buffer);
  4421. }
  4422. _super.prototype._complete.call(this);
  4423. };
  4424. return BufferCountSubscriber;
  4425. }(Subscriber));
  4426. var BufferSkipCountSubscriber = (function (_super) {
  4427. __extends(BufferSkipCountSubscriber, _super);
  4428. function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
  4429. var _this = _super.call(this, destination) || this;
  4430. _this.bufferSize = bufferSize;
  4431. _this.startBufferEvery = startBufferEvery;
  4432. _this.buffers = [];
  4433. _this.count = 0;
  4434. return _this;
  4435. }
  4436. BufferSkipCountSubscriber.prototype._next = function (value) {
  4437. var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
  4438. this.count++;
  4439. if (count % startBufferEvery === 0) {
  4440. buffers.push([]);
  4441. }
  4442. for (var i = buffers.length; i--;) {
  4443. var buffer = buffers[i];
  4444. buffer.push(value);
  4445. if (buffer.length === bufferSize) {
  4446. buffers.splice(i, 1);
  4447. this.destination.next(buffer);
  4448. }
  4449. }
  4450. };
  4451. BufferSkipCountSubscriber.prototype._complete = function () {
  4452. var _a = this, buffers = _a.buffers, destination = _a.destination;
  4453. while (buffers.length > 0) {
  4454. var buffer = buffers.shift();
  4455. if (buffer.length > 0) {
  4456. destination.next(buffer);
  4457. }
  4458. }
  4459. _super.prototype._complete.call(this);
  4460. };
  4461. return BufferSkipCountSubscriber;
  4462. }(Subscriber));
  4463. function bufferTime(bufferTimeSpan) {
  4464. var length = arguments.length;
  4465. var scheduler = async;
  4466. if (isScheduler(arguments[arguments.length - 1])) {
  4467. scheduler = arguments[arguments.length - 1];
  4468. length--;
  4469. }
  4470. var bufferCreationInterval = null;
  4471. if (length >= 2) {
  4472. bufferCreationInterval = arguments[1];
  4473. }
  4474. var maxBufferSize = Number.POSITIVE_INFINITY;
  4475. if (length >= 3) {
  4476. maxBufferSize = arguments[2];
  4477. }
  4478. return function bufferTimeOperatorFunction(source) {
  4479. return source.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler));
  4480. };
  4481. }
  4482. var BufferTimeOperator = (function () {
  4483. function BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
  4484. this.bufferTimeSpan = bufferTimeSpan;
  4485. this.bufferCreationInterval = bufferCreationInterval;
  4486. this.maxBufferSize = maxBufferSize;
  4487. this.scheduler = scheduler;
  4488. }
  4489. BufferTimeOperator.prototype.call = function (subscriber, source) {
  4490. return source.subscribe(new BufferTimeSubscriber(subscriber, this.bufferTimeSpan, this.bufferCreationInterval, this.maxBufferSize, this.scheduler));
  4491. };
  4492. return BufferTimeOperator;
  4493. }());
  4494. var Context = (function () {
  4495. function Context() {
  4496. this.buffer = [];
  4497. }
  4498. return Context;
  4499. }());
  4500. var BufferTimeSubscriber = (function (_super) {
  4501. __extends(BufferTimeSubscriber, _super);
  4502. function BufferTimeSubscriber(destination, bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
  4503. var _this = _super.call(this, destination) || this;
  4504. _this.bufferTimeSpan = bufferTimeSpan;
  4505. _this.bufferCreationInterval = bufferCreationInterval;
  4506. _this.maxBufferSize = maxBufferSize;
  4507. _this.scheduler = scheduler;
  4508. _this.contexts = [];
  4509. var context = _this.openContext();
  4510. _this.timespanOnly = bufferCreationInterval == null || bufferCreationInterval < 0;
  4511. if (_this.timespanOnly) {
  4512. var timeSpanOnlyState = { subscriber: _this, context: context, bufferTimeSpan: bufferTimeSpan };
  4513. _this.add(context.closeAction = scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
  4514. }
  4515. else {
  4516. var closeState = { subscriber: _this, context: context };
  4517. var creationState = { bufferTimeSpan: bufferTimeSpan, bufferCreationInterval: bufferCreationInterval, subscriber: _this, scheduler: scheduler };
  4518. _this.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, closeState));
  4519. _this.add(scheduler.schedule(dispatchBufferCreation, bufferCreationInterval, creationState));
  4520. }
  4521. return _this;
  4522. }
  4523. BufferTimeSubscriber.prototype._next = function (value) {
  4524. var contexts = this.contexts;
  4525. var len = contexts.length;
  4526. var filledBufferContext;
  4527. for (var i = 0; i < len; i++) {
  4528. var context_1 = contexts[i];
  4529. var buffer = context_1.buffer;
  4530. buffer.push(value);
  4531. if (buffer.length == this.maxBufferSize) {
  4532. filledBufferContext = context_1;
  4533. }
  4534. }
  4535. if (filledBufferContext) {
  4536. this.onBufferFull(filledBufferContext);
  4537. }
  4538. };
  4539. BufferTimeSubscriber.prototype._error = function (err) {
  4540. this.contexts.length = 0;
  4541. _super.prototype._error.call(this, err);
  4542. };
  4543. BufferTimeSubscriber.prototype._complete = function () {
  4544. var _a = this, contexts = _a.contexts, destination = _a.destination;
  4545. while (contexts.length > 0) {
  4546. var context_2 = contexts.shift();
  4547. destination.next(context_2.buffer);
  4548. }
  4549. _super.prototype._complete.call(this);
  4550. };
  4551. BufferTimeSubscriber.prototype._unsubscribe = function () {
  4552. this.contexts = null;
  4553. };
  4554. BufferTimeSubscriber.prototype.onBufferFull = function (context) {
  4555. this.closeContext(context);
  4556. var closeAction = context.closeAction;
  4557. closeAction.unsubscribe();
  4558. this.remove(closeAction);
  4559. if (!this.closed && this.timespanOnly) {
  4560. context = this.openContext();
  4561. var bufferTimeSpan = this.bufferTimeSpan;
  4562. var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan };
  4563. this.add(context.closeAction = this.scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
  4564. }
  4565. };
  4566. BufferTimeSubscriber.prototype.openContext = function () {
  4567. var context = new Context();
  4568. this.contexts.push(context);
  4569. return context;
  4570. };
  4571. BufferTimeSubscriber.prototype.closeContext = function (context) {
  4572. this.destination.next(context.buffer);
  4573. var contexts = this.contexts;
  4574. var spliceIndex = contexts ? contexts.indexOf(context) : -1;
  4575. if (spliceIndex >= 0) {
  4576. contexts.splice(contexts.indexOf(context), 1);
  4577. }
  4578. };
  4579. return BufferTimeSubscriber;
  4580. }(Subscriber));
  4581. function dispatchBufferTimeSpanOnly(state) {
  4582. var subscriber = state.subscriber;
  4583. var prevContext = state.context;
  4584. if (prevContext) {
  4585. subscriber.closeContext(prevContext);
  4586. }
  4587. if (!subscriber.closed) {
  4588. state.context = subscriber.openContext();
  4589. state.context.closeAction = this.schedule(state, state.bufferTimeSpan);
  4590. }
  4591. }
  4592. function dispatchBufferCreation(state) {
  4593. var bufferCreationInterval = state.bufferCreationInterval, bufferTimeSpan = state.bufferTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler;
  4594. var context = subscriber.openContext();
  4595. var action = this;
  4596. if (!subscriber.closed) {
  4597. subscriber.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, { subscriber: subscriber, context: context }));
  4598. action.schedule(state, bufferCreationInterval);
  4599. }
  4600. }
  4601. function dispatchBufferClose(arg) {
  4602. var subscriber = arg.subscriber, context = arg.context;
  4603. subscriber.closeContext(context);
  4604. }
  4605. function bufferToggle(openings, closingSelector) {
  4606. return function bufferToggleOperatorFunction(source) {
  4607. return source.lift(new BufferToggleOperator(openings, closingSelector));
  4608. };
  4609. }
  4610. var BufferToggleOperator = (function () {
  4611. function BufferToggleOperator(openings, closingSelector) {
  4612. this.openings = openings;
  4613. this.closingSelector = closingSelector;
  4614. }
  4615. BufferToggleOperator.prototype.call = function (subscriber, source) {
  4616. return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));
  4617. };
  4618. return BufferToggleOperator;
  4619. }());
  4620. var BufferToggleSubscriber = (function (_super) {
  4621. __extends(BufferToggleSubscriber, _super);
  4622. function BufferToggleSubscriber(destination, openings, closingSelector) {
  4623. var _this = _super.call(this, destination) || this;
  4624. _this.openings = openings;
  4625. _this.closingSelector = closingSelector;
  4626. _this.contexts = [];
  4627. _this.add(subscribeToResult(_this, openings));
  4628. return _this;
  4629. }
  4630. BufferToggleSubscriber.prototype._next = function (value) {
  4631. var contexts = this.contexts;
  4632. var len = contexts.length;
  4633. for (var i = 0; i < len; i++) {
  4634. contexts[i].buffer.push(value);
  4635. }
  4636. };
  4637. BufferToggleSubscriber.prototype._error = function (err) {
  4638. var contexts = this.contexts;
  4639. while (contexts.length > 0) {
  4640. var context_1 = contexts.shift();
  4641. context_1.subscription.unsubscribe();
  4642. context_1.buffer = null;
  4643. context_1.subscription = null;
  4644. }
  4645. this.contexts = null;
  4646. _super.prototype._error.call(this, err);
  4647. };
  4648. BufferToggleSubscriber.prototype._complete = function () {
  4649. var contexts = this.contexts;
  4650. while (contexts.length > 0) {
  4651. var context_2 = contexts.shift();
  4652. this.destination.next(context_2.buffer);
  4653. context_2.subscription.unsubscribe();
  4654. context_2.buffer = null;
  4655. context_2.subscription = null;
  4656. }
  4657. this.contexts = null;
  4658. _super.prototype._complete.call(this);
  4659. };
  4660. BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  4661. outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);
  4662. };
  4663. BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) {
  4664. this.closeBuffer(innerSub.context);
  4665. };
  4666. BufferToggleSubscriber.prototype.openBuffer = function (value) {
  4667. try {
  4668. var closingSelector = this.closingSelector;
  4669. var closingNotifier = closingSelector.call(this, value);
  4670. if (closingNotifier) {
  4671. this.trySubscribe(closingNotifier);
  4672. }
  4673. }
  4674. catch (err) {
  4675. this._error(err);
  4676. }
  4677. };
  4678. BufferToggleSubscriber.prototype.closeBuffer = function (context) {
  4679. var contexts = this.contexts;
  4680. if (contexts && context) {
  4681. var buffer = context.buffer, subscription = context.subscription;
  4682. this.destination.next(buffer);
  4683. contexts.splice(contexts.indexOf(context), 1);
  4684. this.remove(subscription);
  4685. subscription.unsubscribe();
  4686. }
  4687. };
  4688. BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) {
  4689. var contexts = this.contexts;
  4690. var buffer = [];
  4691. var subscription = new Subscription();
  4692. var context = { buffer: buffer, subscription: subscription };
  4693. contexts.push(context);
  4694. var innerSubscription = subscribeToResult(this, closingNotifier, context);
  4695. if (!innerSubscription || innerSubscription.closed) {
  4696. this.closeBuffer(context);
  4697. }
  4698. else {
  4699. innerSubscription.context = context;
  4700. this.add(innerSubscription);
  4701. subscription.add(innerSubscription);
  4702. }
  4703. };
  4704. return BufferToggleSubscriber;
  4705. }(OuterSubscriber));
  4706. function bufferWhen(closingSelector) {
  4707. return function (source) {
  4708. return source.lift(new BufferWhenOperator(closingSelector));
  4709. };
  4710. }
  4711. var BufferWhenOperator = (function () {
  4712. function BufferWhenOperator(closingSelector) {
  4713. this.closingSelector = closingSelector;
  4714. }
  4715. BufferWhenOperator.prototype.call = function (subscriber, source) {
  4716. return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
  4717. };
  4718. return BufferWhenOperator;
  4719. }());
  4720. var BufferWhenSubscriber = (function (_super) {
  4721. __extends(BufferWhenSubscriber, _super);
  4722. function BufferWhenSubscriber(destination, closingSelector) {
  4723. var _this = _super.call(this, destination) || this;
  4724. _this.closingSelector = closingSelector;
  4725. _this.subscribing = false;
  4726. _this.openBuffer();
  4727. return _this;
  4728. }
  4729. BufferWhenSubscriber.prototype._next = function (value) {
  4730. this.buffer.push(value);
  4731. };
  4732. BufferWhenSubscriber.prototype._complete = function () {
  4733. var buffer = this.buffer;
  4734. if (buffer) {
  4735. this.destination.next(buffer);
  4736. }
  4737. _super.prototype._complete.call(this);
  4738. };
  4739. BufferWhenSubscriber.prototype._unsubscribe = function () {
  4740. this.buffer = null;
  4741. this.subscribing = false;
  4742. };
  4743. BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  4744. this.openBuffer();
  4745. };
  4746. BufferWhenSubscriber.prototype.notifyComplete = function () {
  4747. if (this.subscribing) {
  4748. this.complete();
  4749. }
  4750. else {
  4751. this.openBuffer();
  4752. }
  4753. };
  4754. BufferWhenSubscriber.prototype.openBuffer = function () {
  4755. var closingSubscription = this.closingSubscription;
  4756. if (closingSubscription) {
  4757. this.remove(closingSubscription);
  4758. closingSubscription.unsubscribe();
  4759. }
  4760. var buffer = this.buffer;
  4761. if (this.buffer) {
  4762. this.destination.next(buffer);
  4763. }
  4764. this.buffer = [];
  4765. var closingNotifier;
  4766. try {
  4767. var closingSelector = this.closingSelector;
  4768. closingNotifier = closingSelector();
  4769. }
  4770. catch (err) {
  4771. return this.error(err);
  4772. }
  4773. closingSubscription = new Subscription();
  4774. this.closingSubscription = closingSubscription;
  4775. this.add(closingSubscription);
  4776. this.subscribing = true;
  4777. closingSubscription.add(subscribeToResult(this, closingNotifier));
  4778. this.subscribing = false;
  4779. };
  4780. return BufferWhenSubscriber;
  4781. }(OuterSubscriber));
  4782. function catchError(selector) {
  4783. return function catchErrorOperatorFunction(source) {
  4784. var operator = new CatchOperator(selector);
  4785. var caught = source.lift(operator);
  4786. return (operator.caught = caught);
  4787. };
  4788. }
  4789. var CatchOperator = (function () {
  4790. function CatchOperator(selector) {
  4791. this.selector = selector;
  4792. }
  4793. CatchOperator.prototype.call = function (subscriber, source) {
  4794. return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught));
  4795. };
  4796. return CatchOperator;
  4797. }());
  4798. var CatchSubscriber = (function (_super) {
  4799. __extends(CatchSubscriber, _super);
  4800. function CatchSubscriber(destination, selector, caught) {
  4801. var _this = _super.call(this, destination) || this;
  4802. _this.selector = selector;
  4803. _this.caught = caught;
  4804. return _this;
  4805. }
  4806. CatchSubscriber.prototype.error = function (err) {
  4807. if (!this.isStopped) {
  4808. var result = void 0;
  4809. try {
  4810. result = this.selector(err, this.caught);
  4811. }
  4812. catch (err2) {
  4813. _super.prototype.error.call(this, err2);
  4814. return;
  4815. }
  4816. this._unsubscribeAndRecycle();
  4817. var innerSubscriber = new InnerSubscriber(this, undefined, undefined);
  4818. this.add(innerSubscriber);
  4819. var innerSubscription = subscribeToResult(this, result, undefined, undefined, innerSubscriber);
  4820. if (innerSubscription !== innerSubscriber) {
  4821. this.add(innerSubscription);
  4822. }
  4823. }
  4824. };
  4825. return CatchSubscriber;
  4826. }(OuterSubscriber));
  4827. function combineAll(project) {
  4828. return function (source) { return source.lift(new CombineLatestOperator(project)); };
  4829. }
  4830. function combineLatest$1() {
  4831. var observables = [];
  4832. for (var _i = 0; _i < arguments.length; _i++) {
  4833. observables[_i] = arguments[_i];
  4834. }
  4835. var project = null;
  4836. if (typeof observables[observables.length - 1] === 'function') {
  4837. project = observables.pop();
  4838. }
  4839. if (observables.length === 1 && isArray(observables[0])) {
  4840. observables = observables[0].slice();
  4841. }
  4842. return function (source) { return source.lift.call(from([source].concat(observables)), new CombineLatestOperator(project)); };
  4843. }
  4844. function concat$1() {
  4845. var observables = [];
  4846. for (var _i = 0; _i < arguments.length; _i++) {
  4847. observables[_i] = arguments[_i];
  4848. }
  4849. return function (source) { return source.lift.call(concat.apply(void 0, [source].concat(observables))); };
  4850. }
  4851. function concatMap(project, resultSelector) {
  4852. return mergeMap(project, resultSelector, 1);
  4853. }
  4854. function concatMapTo(innerObservable, resultSelector) {
  4855. return concatMap(function () { return innerObservable; }, resultSelector);
  4856. }
  4857. function count(predicate) {
  4858. return function (source) { return source.lift(new CountOperator(predicate, source)); };
  4859. }
  4860. var CountOperator = (function () {
  4861. function CountOperator(predicate, source) {
  4862. this.predicate = predicate;
  4863. this.source = source;
  4864. }
  4865. CountOperator.prototype.call = function (subscriber, source) {
  4866. return source.subscribe(new CountSubscriber(subscriber, this.predicate, this.source));
  4867. };
  4868. return CountOperator;
  4869. }());
  4870. var CountSubscriber = (function (_super) {
  4871. __extends(CountSubscriber, _super);
  4872. function CountSubscriber(destination, predicate, source) {
  4873. var _this = _super.call(this, destination) || this;
  4874. _this.predicate = predicate;
  4875. _this.source = source;
  4876. _this.count = 0;
  4877. _this.index = 0;
  4878. return _this;
  4879. }
  4880. CountSubscriber.prototype._next = function (value) {
  4881. if (this.predicate) {
  4882. this._tryPredicate(value);
  4883. }
  4884. else {
  4885. this.count++;
  4886. }
  4887. };
  4888. CountSubscriber.prototype._tryPredicate = function (value) {
  4889. var result;
  4890. try {
  4891. result = this.predicate(value, this.index++, this.source);
  4892. }
  4893. catch (err) {
  4894. this.destination.error(err);
  4895. return;
  4896. }
  4897. if (result) {
  4898. this.count++;
  4899. }
  4900. };
  4901. CountSubscriber.prototype._complete = function () {
  4902. this.destination.next(this.count);
  4903. this.destination.complete();
  4904. };
  4905. return CountSubscriber;
  4906. }(Subscriber));
  4907. function debounce(durationSelector) {
  4908. return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
  4909. }
  4910. var DebounceOperator = (function () {
  4911. function DebounceOperator(durationSelector) {
  4912. this.durationSelector = durationSelector;
  4913. }
  4914. DebounceOperator.prototype.call = function (subscriber, source) {
  4915. return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
  4916. };
  4917. return DebounceOperator;
  4918. }());
  4919. var DebounceSubscriber = (function (_super) {
  4920. __extends(DebounceSubscriber, _super);
  4921. function DebounceSubscriber(destination, durationSelector) {
  4922. var _this = _super.call(this, destination) || this;
  4923. _this.durationSelector = durationSelector;
  4924. _this.hasValue = false;
  4925. _this.durationSubscription = null;
  4926. return _this;
  4927. }
  4928. DebounceSubscriber.prototype._next = function (value) {
  4929. try {
  4930. var result = this.durationSelector.call(this, value);
  4931. if (result) {
  4932. this._tryNext(value, result);
  4933. }
  4934. }
  4935. catch (err) {
  4936. this.destination.error(err);
  4937. }
  4938. };
  4939. DebounceSubscriber.prototype._complete = function () {
  4940. this.emitValue();
  4941. this.destination.complete();
  4942. };
  4943. DebounceSubscriber.prototype._tryNext = function (value, duration) {
  4944. var subscription = this.durationSubscription;
  4945. this.value = value;
  4946. this.hasValue = true;
  4947. if (subscription) {
  4948. subscription.unsubscribe();
  4949. this.remove(subscription);
  4950. }
  4951. subscription = subscribeToResult(this, duration);
  4952. if (subscription && !subscription.closed) {
  4953. this.add(this.durationSubscription = subscription);
  4954. }
  4955. };
  4956. DebounceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  4957. this.emitValue();
  4958. };
  4959. DebounceSubscriber.prototype.notifyComplete = function () {
  4960. this.emitValue();
  4961. };
  4962. DebounceSubscriber.prototype.emitValue = function () {
  4963. if (this.hasValue) {
  4964. var value = this.value;
  4965. var subscription = this.durationSubscription;
  4966. if (subscription) {
  4967. this.durationSubscription = null;
  4968. subscription.unsubscribe();
  4969. this.remove(subscription);
  4970. }
  4971. this.value = null;
  4972. this.hasValue = false;
  4973. _super.prototype._next.call(this, value);
  4974. }
  4975. };
  4976. return DebounceSubscriber;
  4977. }(OuterSubscriber));
  4978. function debounceTime(dueTime, scheduler) {
  4979. if (scheduler === void 0) { scheduler = async; }
  4980. return function (source) { return source.lift(new DebounceTimeOperator(dueTime, scheduler)); };
  4981. }
  4982. var DebounceTimeOperator = (function () {
  4983. function DebounceTimeOperator(dueTime, scheduler) {
  4984. this.dueTime = dueTime;
  4985. this.scheduler = scheduler;
  4986. }
  4987. DebounceTimeOperator.prototype.call = function (subscriber, source) {
  4988. return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
  4989. };
  4990. return DebounceTimeOperator;
  4991. }());
  4992. var DebounceTimeSubscriber = (function (_super) {
  4993. __extends(DebounceTimeSubscriber, _super);
  4994. function DebounceTimeSubscriber(destination, dueTime, scheduler) {
  4995. var _this = _super.call(this, destination) || this;
  4996. _this.dueTime = dueTime;
  4997. _this.scheduler = scheduler;
  4998. _this.debouncedSubscription = null;
  4999. _this.lastValue = null;
  5000. _this.hasValue = false;
  5001. return _this;
  5002. }
  5003. DebounceTimeSubscriber.prototype._next = function (value) {
  5004. this.clearDebounce();
  5005. this.lastValue = value;
  5006. this.hasValue = true;
  5007. this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext$2, this.dueTime, this));
  5008. };
  5009. DebounceTimeSubscriber.prototype._complete = function () {
  5010. this.debouncedNext();
  5011. this.destination.complete();
  5012. };
  5013. DebounceTimeSubscriber.prototype.debouncedNext = function () {
  5014. this.clearDebounce();
  5015. if (this.hasValue) {
  5016. var lastValue = this.lastValue;
  5017. this.lastValue = null;
  5018. this.hasValue = false;
  5019. this.destination.next(lastValue);
  5020. }
  5021. };
  5022. DebounceTimeSubscriber.prototype.clearDebounce = function () {
  5023. var debouncedSubscription = this.debouncedSubscription;
  5024. if (debouncedSubscription !== null) {
  5025. this.remove(debouncedSubscription);
  5026. debouncedSubscription.unsubscribe();
  5027. this.debouncedSubscription = null;
  5028. }
  5029. };
  5030. return DebounceTimeSubscriber;
  5031. }(Subscriber));
  5032. function dispatchNext$2(subscriber) {
  5033. subscriber.debouncedNext();
  5034. }
  5035. function defaultIfEmpty(defaultValue) {
  5036. if (defaultValue === void 0) { defaultValue = null; }
  5037. return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
  5038. }
  5039. var DefaultIfEmptyOperator = (function () {
  5040. function DefaultIfEmptyOperator(defaultValue) {
  5041. this.defaultValue = defaultValue;
  5042. }
  5043. DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
  5044. return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
  5045. };
  5046. return DefaultIfEmptyOperator;
  5047. }());
  5048. var DefaultIfEmptySubscriber = (function (_super) {
  5049. __extends(DefaultIfEmptySubscriber, _super);
  5050. function DefaultIfEmptySubscriber(destination, defaultValue) {
  5051. var _this = _super.call(this, destination) || this;
  5052. _this.defaultValue = defaultValue;
  5053. _this.isEmpty = true;
  5054. return _this;
  5055. }
  5056. DefaultIfEmptySubscriber.prototype._next = function (value) {
  5057. this.isEmpty = false;
  5058. this.destination.next(value);
  5059. };
  5060. DefaultIfEmptySubscriber.prototype._complete = function () {
  5061. if (this.isEmpty) {
  5062. this.destination.next(this.defaultValue);
  5063. }
  5064. this.destination.complete();
  5065. };
  5066. return DefaultIfEmptySubscriber;
  5067. }(Subscriber));
  5068. function delay(delay, scheduler) {
  5069. if (scheduler === void 0) { scheduler = async; }
  5070. var absoluteDelay = isDate(delay);
  5071. var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
  5072. return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
  5073. }
  5074. var DelayOperator = (function () {
  5075. function DelayOperator(delay, scheduler) {
  5076. this.delay = delay;
  5077. this.scheduler = scheduler;
  5078. }
  5079. DelayOperator.prototype.call = function (subscriber, source) {
  5080. return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
  5081. };
  5082. return DelayOperator;
  5083. }());
  5084. var DelaySubscriber = (function (_super) {
  5085. __extends(DelaySubscriber, _super);
  5086. function DelaySubscriber(destination, delay, scheduler) {
  5087. var _this = _super.call(this, destination) || this;
  5088. _this.delay = delay;
  5089. _this.scheduler = scheduler;
  5090. _this.queue = [];
  5091. _this.active = false;
  5092. _this.errored = false;
  5093. return _this;
  5094. }
  5095. DelaySubscriber.dispatch = function (state) {
  5096. var source = state.source;
  5097. var queue = source.queue;
  5098. var scheduler = state.scheduler;
  5099. var destination = state.destination;
  5100. while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
  5101. queue.shift().notification.observe(destination);
  5102. }
  5103. if (queue.length > 0) {
  5104. var delay_1 = Math.max(0, queue[0].time - scheduler.now());
  5105. this.schedule(state, delay_1);
  5106. }
  5107. else {
  5108. this.unsubscribe();
  5109. source.active = false;
  5110. }
  5111. };
  5112. DelaySubscriber.prototype._schedule = function (scheduler) {
  5113. this.active = true;
  5114. var destination = this.destination;
  5115. destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
  5116. source: this, destination: this.destination, scheduler: scheduler
  5117. }));
  5118. };
  5119. DelaySubscriber.prototype.scheduleNotification = function (notification) {
  5120. if (this.errored === true) {
  5121. return;
  5122. }
  5123. var scheduler = this.scheduler;
  5124. var message = new DelayMessage(scheduler.now() + this.delay, notification);
  5125. this.queue.push(message);
  5126. if (this.active === false) {
  5127. this._schedule(scheduler);
  5128. }
  5129. };
  5130. DelaySubscriber.prototype._next = function (value) {
  5131. this.scheduleNotification(Notification.createNext(value));
  5132. };
  5133. DelaySubscriber.prototype._error = function (err) {
  5134. this.errored = true;
  5135. this.queue = [];
  5136. this.destination.error(err);
  5137. this.unsubscribe();
  5138. };
  5139. DelaySubscriber.prototype._complete = function () {
  5140. this.scheduleNotification(Notification.createComplete());
  5141. this.unsubscribe();
  5142. };
  5143. return DelaySubscriber;
  5144. }(Subscriber));
  5145. var DelayMessage = (function () {
  5146. function DelayMessage(time, notification) {
  5147. this.time = time;
  5148. this.notification = notification;
  5149. }
  5150. return DelayMessage;
  5151. }());
  5152. function delayWhen(delayDurationSelector, subscriptionDelay) {
  5153. if (subscriptionDelay) {
  5154. return function (source) {
  5155. return new SubscriptionDelayObservable(source, subscriptionDelay)
  5156. .lift(new DelayWhenOperator(delayDurationSelector));
  5157. };
  5158. }
  5159. return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
  5160. }
  5161. var DelayWhenOperator = (function () {
  5162. function DelayWhenOperator(delayDurationSelector) {
  5163. this.delayDurationSelector = delayDurationSelector;
  5164. }
  5165. DelayWhenOperator.prototype.call = function (subscriber, source) {
  5166. return source.subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
  5167. };
  5168. return DelayWhenOperator;
  5169. }());
  5170. var DelayWhenSubscriber = (function (_super) {
  5171. __extends(DelayWhenSubscriber, _super);
  5172. function DelayWhenSubscriber(destination, delayDurationSelector) {
  5173. var _this = _super.call(this, destination) || this;
  5174. _this.delayDurationSelector = delayDurationSelector;
  5175. _this.completed = false;
  5176. _this.delayNotifierSubscriptions = [];
  5177. _this.index = 0;
  5178. return _this;
  5179. }
  5180. DelayWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  5181. this.destination.next(outerValue);
  5182. this.removeSubscription(innerSub);
  5183. this.tryComplete();
  5184. };
  5185. DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) {
  5186. this._error(error);
  5187. };
  5188. DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) {
  5189. var value = this.removeSubscription(innerSub);
  5190. if (value) {
  5191. this.destination.next(value);
  5192. }
  5193. this.tryComplete();
  5194. };
  5195. DelayWhenSubscriber.prototype._next = function (value) {
  5196. var index = this.index++;
  5197. try {
  5198. var delayNotifier = this.delayDurationSelector(value, index);
  5199. if (delayNotifier) {
  5200. this.tryDelay(delayNotifier, value);
  5201. }
  5202. }
  5203. catch (err) {
  5204. this.destination.error(err);
  5205. }
  5206. };
  5207. DelayWhenSubscriber.prototype._complete = function () {
  5208. this.completed = true;
  5209. this.tryComplete();
  5210. this.unsubscribe();
  5211. };
  5212. DelayWhenSubscriber.prototype.removeSubscription = function (subscription) {
  5213. subscription.unsubscribe();
  5214. var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription);
  5215. if (subscriptionIdx !== -1) {
  5216. this.delayNotifierSubscriptions.splice(subscriptionIdx, 1);
  5217. }
  5218. return subscription.outerValue;
  5219. };
  5220. DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) {
  5221. var notifierSubscription = subscribeToResult(this, delayNotifier, value);
  5222. if (notifierSubscription && !notifierSubscription.closed) {
  5223. var destination = this.destination;
  5224. destination.add(notifierSubscription);
  5225. this.delayNotifierSubscriptions.push(notifierSubscription);
  5226. }
  5227. };
  5228. DelayWhenSubscriber.prototype.tryComplete = function () {
  5229. if (this.completed && this.delayNotifierSubscriptions.length === 0) {
  5230. this.destination.complete();
  5231. }
  5232. };
  5233. return DelayWhenSubscriber;
  5234. }(OuterSubscriber));
  5235. var SubscriptionDelayObservable = (function (_super) {
  5236. __extends(SubscriptionDelayObservable, _super);
  5237. function SubscriptionDelayObservable(source, subscriptionDelay) {
  5238. var _this = _super.call(this) || this;
  5239. _this.source = source;
  5240. _this.subscriptionDelay = subscriptionDelay;
  5241. return _this;
  5242. }
  5243. SubscriptionDelayObservable.prototype._subscribe = function (subscriber) {
  5244. this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source));
  5245. };
  5246. return SubscriptionDelayObservable;
  5247. }(Observable));
  5248. var SubscriptionDelaySubscriber = (function (_super) {
  5249. __extends(SubscriptionDelaySubscriber, _super);
  5250. function SubscriptionDelaySubscriber(parent, source) {
  5251. var _this = _super.call(this) || this;
  5252. _this.parent = parent;
  5253. _this.source = source;
  5254. _this.sourceSubscribed = false;
  5255. return _this;
  5256. }
  5257. SubscriptionDelaySubscriber.prototype._next = function (unused) {
  5258. this.subscribeToSource();
  5259. };
  5260. SubscriptionDelaySubscriber.prototype._error = function (err) {
  5261. this.unsubscribe();
  5262. this.parent.error(err);
  5263. };
  5264. SubscriptionDelaySubscriber.prototype._complete = function () {
  5265. this.unsubscribe();
  5266. this.subscribeToSource();
  5267. };
  5268. SubscriptionDelaySubscriber.prototype.subscribeToSource = function () {
  5269. if (!this.sourceSubscribed) {
  5270. this.sourceSubscribed = true;
  5271. this.unsubscribe();
  5272. this.source.subscribe(this.parent);
  5273. }
  5274. };
  5275. return SubscriptionDelaySubscriber;
  5276. }(Subscriber));
  5277. function dematerialize() {
  5278. return function dematerializeOperatorFunction(source) {
  5279. return source.lift(new DeMaterializeOperator());
  5280. };
  5281. }
  5282. var DeMaterializeOperator = (function () {
  5283. function DeMaterializeOperator() {
  5284. }
  5285. DeMaterializeOperator.prototype.call = function (subscriber, source) {
  5286. return source.subscribe(new DeMaterializeSubscriber(subscriber));
  5287. };
  5288. return DeMaterializeOperator;
  5289. }());
  5290. var DeMaterializeSubscriber = (function (_super) {
  5291. __extends(DeMaterializeSubscriber, _super);
  5292. function DeMaterializeSubscriber(destination) {
  5293. return _super.call(this, destination) || this;
  5294. }
  5295. DeMaterializeSubscriber.prototype._next = function (value) {
  5296. value.observe(this.destination);
  5297. };
  5298. return DeMaterializeSubscriber;
  5299. }(Subscriber));
  5300. function distinct(keySelector, flushes) {
  5301. return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
  5302. }
  5303. var DistinctOperator = (function () {
  5304. function DistinctOperator(keySelector, flushes) {
  5305. this.keySelector = keySelector;
  5306. this.flushes = flushes;
  5307. }
  5308. DistinctOperator.prototype.call = function (subscriber, source) {
  5309. return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
  5310. };
  5311. return DistinctOperator;
  5312. }());
  5313. var DistinctSubscriber = (function (_super) {
  5314. __extends(DistinctSubscriber, _super);
  5315. function DistinctSubscriber(destination, keySelector, flushes) {
  5316. var _this = _super.call(this, destination) || this;
  5317. _this.keySelector = keySelector;
  5318. _this.values = new Set();
  5319. if (flushes) {
  5320. _this.add(subscribeToResult(_this, flushes));
  5321. }
  5322. return _this;
  5323. }
  5324. DistinctSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  5325. this.values.clear();
  5326. };
  5327. DistinctSubscriber.prototype.notifyError = function (error, innerSub) {
  5328. this._error(error);
  5329. };
  5330. DistinctSubscriber.prototype._next = function (value) {
  5331. if (this.keySelector) {
  5332. this._useKeySelector(value);
  5333. }
  5334. else {
  5335. this._finalizeNext(value, value);
  5336. }
  5337. };
  5338. DistinctSubscriber.prototype._useKeySelector = function (value) {
  5339. var key;
  5340. var destination = this.destination;
  5341. try {
  5342. key = this.keySelector(value);
  5343. }
  5344. catch (err) {
  5345. destination.error(err);
  5346. return;
  5347. }
  5348. this._finalizeNext(key, value);
  5349. };
  5350. DistinctSubscriber.prototype._finalizeNext = function (key, value) {
  5351. var values = this.values;
  5352. if (!values.has(key)) {
  5353. values.add(key);
  5354. this.destination.next(value);
  5355. }
  5356. };
  5357. return DistinctSubscriber;
  5358. }(OuterSubscriber));
  5359. function distinctUntilChanged(compare, keySelector) {
  5360. return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
  5361. }
  5362. var DistinctUntilChangedOperator = (function () {
  5363. function DistinctUntilChangedOperator(compare, keySelector) {
  5364. this.compare = compare;
  5365. this.keySelector = keySelector;
  5366. }
  5367. DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
  5368. return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
  5369. };
  5370. return DistinctUntilChangedOperator;
  5371. }());
  5372. var DistinctUntilChangedSubscriber = (function (_super) {
  5373. __extends(DistinctUntilChangedSubscriber, _super);
  5374. function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
  5375. var _this = _super.call(this, destination) || this;
  5376. _this.keySelector = keySelector;
  5377. _this.hasKey = false;
  5378. if (typeof compare === 'function') {
  5379. _this.compare = compare;
  5380. }
  5381. return _this;
  5382. }
  5383. DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
  5384. return x === y;
  5385. };
  5386. DistinctUntilChangedSubscriber.prototype._next = function (value) {
  5387. var key;
  5388. try {
  5389. var keySelector = this.keySelector;
  5390. key = keySelector ? keySelector(value) : value;
  5391. }
  5392. catch (err) {
  5393. return this.destination.error(err);
  5394. }
  5395. var result = false;
  5396. if (this.hasKey) {
  5397. try {
  5398. var compare = this.compare;
  5399. result = compare(this.key, key);
  5400. }
  5401. catch (err) {
  5402. return this.destination.error(err);
  5403. }
  5404. }
  5405. else {
  5406. this.hasKey = true;
  5407. }
  5408. if (!result) {
  5409. this.key = key;
  5410. this.destination.next(value);
  5411. }
  5412. };
  5413. return DistinctUntilChangedSubscriber;
  5414. }(Subscriber));
  5415. function distinctUntilKeyChanged(key, compare) {
  5416. return distinctUntilChanged(function (x, y) { return compare ? compare(x[key], y[key]) : x[key] === y[key]; });
  5417. }
  5418. function throwIfEmpty(errorFactory) {
  5419. if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
  5420. return function (source) {
  5421. return source.lift(new ThrowIfEmptyOperator(errorFactory));
  5422. };
  5423. }
  5424. var ThrowIfEmptyOperator = (function () {
  5425. function ThrowIfEmptyOperator(errorFactory) {
  5426. this.errorFactory = errorFactory;
  5427. }
  5428. ThrowIfEmptyOperator.prototype.call = function (subscriber, source) {
  5429. return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));
  5430. };
  5431. return ThrowIfEmptyOperator;
  5432. }());
  5433. var ThrowIfEmptySubscriber = (function (_super) {
  5434. __extends(ThrowIfEmptySubscriber, _super);
  5435. function ThrowIfEmptySubscriber(destination, errorFactory) {
  5436. var _this = _super.call(this, destination) || this;
  5437. _this.errorFactory = errorFactory;
  5438. _this.hasValue = false;
  5439. return _this;
  5440. }
  5441. ThrowIfEmptySubscriber.prototype._next = function (value) {
  5442. this.hasValue = true;
  5443. this.destination.next(value);
  5444. };
  5445. ThrowIfEmptySubscriber.prototype._complete = function () {
  5446. if (!this.hasValue) {
  5447. var err = void 0;
  5448. try {
  5449. err = this.errorFactory();
  5450. }
  5451. catch (e) {
  5452. err = e;
  5453. }
  5454. this.destination.error(err);
  5455. }
  5456. else {
  5457. return this.destination.complete();
  5458. }
  5459. };
  5460. return ThrowIfEmptySubscriber;
  5461. }(Subscriber));
  5462. function defaultErrorFactory() {
  5463. return new EmptyError();
  5464. }
  5465. function take(count) {
  5466. return function (source) {
  5467. if (count === 0) {
  5468. return empty$1();
  5469. }
  5470. else {
  5471. return source.lift(new TakeOperator(count));
  5472. }
  5473. };
  5474. }
  5475. var TakeOperator = (function () {
  5476. function TakeOperator(total) {
  5477. this.total = total;
  5478. if (this.total < 0) {
  5479. throw new ArgumentOutOfRangeError;
  5480. }
  5481. }
  5482. TakeOperator.prototype.call = function (subscriber, source) {
  5483. return source.subscribe(new TakeSubscriber(subscriber, this.total));
  5484. };
  5485. return TakeOperator;
  5486. }());
  5487. var TakeSubscriber = (function (_super) {
  5488. __extends(TakeSubscriber, _super);
  5489. function TakeSubscriber(destination, total) {
  5490. var _this = _super.call(this, destination) || this;
  5491. _this.total = total;
  5492. _this.count = 0;
  5493. return _this;
  5494. }
  5495. TakeSubscriber.prototype._next = function (value) {
  5496. var total = this.total;
  5497. var count = ++this.count;
  5498. if (count <= total) {
  5499. this.destination.next(value);
  5500. if (count === total) {
  5501. this.destination.complete();
  5502. this.unsubscribe();
  5503. }
  5504. }
  5505. };
  5506. return TakeSubscriber;
  5507. }(Subscriber));
  5508. function elementAt(index, defaultValue) {
  5509. if (index < 0) {
  5510. throw new ArgumentOutOfRangeError();
  5511. }
  5512. var hasDefaultValue = arguments.length >= 2;
  5513. return function (source) { return source.pipe(filter(function (v, i) { return i === index; }), take(1), hasDefaultValue
  5514. ? defaultIfEmpty(defaultValue)
  5515. : throwIfEmpty(function () { return new ArgumentOutOfRangeError(); })); };
  5516. }
  5517. function endWith() {
  5518. var array = [];
  5519. for (var _i = 0; _i < arguments.length; _i++) {
  5520. array[_i] = arguments[_i];
  5521. }
  5522. return function (source) { return concat(source, of.apply(void 0, array)); };
  5523. }
  5524. function every(predicate, thisArg) {
  5525. return function (source) { return source.lift(new EveryOperator(predicate, thisArg, source)); };
  5526. }
  5527. var EveryOperator = (function () {
  5528. function EveryOperator(predicate, thisArg, source) {
  5529. this.predicate = predicate;
  5530. this.thisArg = thisArg;
  5531. this.source = source;
  5532. }
  5533. EveryOperator.prototype.call = function (observer, source) {
  5534. return source.subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source));
  5535. };
  5536. return EveryOperator;
  5537. }());
  5538. var EverySubscriber = (function (_super) {
  5539. __extends(EverySubscriber, _super);
  5540. function EverySubscriber(destination, predicate, thisArg, source) {
  5541. var _this = _super.call(this, destination) || this;
  5542. _this.predicate = predicate;
  5543. _this.thisArg = thisArg;
  5544. _this.source = source;
  5545. _this.index = 0;
  5546. _this.thisArg = thisArg || _this;
  5547. return _this;
  5548. }
  5549. EverySubscriber.prototype.notifyComplete = function (everyValueMatch) {
  5550. this.destination.next(everyValueMatch);
  5551. this.destination.complete();
  5552. };
  5553. EverySubscriber.prototype._next = function (value) {
  5554. var result = false;
  5555. try {
  5556. result = this.predicate.call(this.thisArg, value, this.index++, this.source);
  5557. }
  5558. catch (err) {
  5559. this.destination.error(err);
  5560. return;
  5561. }
  5562. if (!result) {
  5563. this.notifyComplete(false);
  5564. }
  5565. };
  5566. EverySubscriber.prototype._complete = function () {
  5567. this.notifyComplete(true);
  5568. };
  5569. return EverySubscriber;
  5570. }(Subscriber));
  5571. function exhaust() {
  5572. return function (source) { return source.lift(new SwitchFirstOperator()); };
  5573. }
  5574. var SwitchFirstOperator = (function () {
  5575. function SwitchFirstOperator() {
  5576. }
  5577. SwitchFirstOperator.prototype.call = function (subscriber, source) {
  5578. return source.subscribe(new SwitchFirstSubscriber(subscriber));
  5579. };
  5580. return SwitchFirstOperator;
  5581. }());
  5582. var SwitchFirstSubscriber = (function (_super) {
  5583. __extends(SwitchFirstSubscriber, _super);
  5584. function SwitchFirstSubscriber(destination) {
  5585. var _this = _super.call(this, destination) || this;
  5586. _this.hasCompleted = false;
  5587. _this.hasSubscription = false;
  5588. return _this;
  5589. }
  5590. SwitchFirstSubscriber.prototype._next = function (value) {
  5591. if (!this.hasSubscription) {
  5592. this.hasSubscription = true;
  5593. this.add(subscribeToResult(this, value));
  5594. }
  5595. };
  5596. SwitchFirstSubscriber.prototype._complete = function () {
  5597. this.hasCompleted = true;
  5598. if (!this.hasSubscription) {
  5599. this.destination.complete();
  5600. }
  5601. };
  5602. SwitchFirstSubscriber.prototype.notifyComplete = function (innerSub) {
  5603. this.remove(innerSub);
  5604. this.hasSubscription = false;
  5605. if (this.hasCompleted) {
  5606. this.destination.complete();
  5607. }
  5608. };
  5609. return SwitchFirstSubscriber;
  5610. }(OuterSubscriber));
  5611. function exhaustMap(project, resultSelector) {
  5612. if (resultSelector) {
  5613. return function (source) { return source.pipe(exhaustMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
  5614. }
  5615. return function (source) {
  5616. return source.lift(new ExhaustMapOperator(project));
  5617. };
  5618. }
  5619. var ExhaustMapOperator = (function () {
  5620. function ExhaustMapOperator(project) {
  5621. this.project = project;
  5622. }
  5623. ExhaustMapOperator.prototype.call = function (subscriber, source) {
  5624. return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
  5625. };
  5626. return ExhaustMapOperator;
  5627. }());
  5628. var ExhaustMapSubscriber = (function (_super) {
  5629. __extends(ExhaustMapSubscriber, _super);
  5630. function ExhaustMapSubscriber(destination, project) {
  5631. var _this = _super.call(this, destination) || this;
  5632. _this.project = project;
  5633. _this.hasSubscription = false;
  5634. _this.hasCompleted = false;
  5635. _this.index = 0;
  5636. return _this;
  5637. }
  5638. ExhaustMapSubscriber.prototype._next = function (value) {
  5639. if (!this.hasSubscription) {
  5640. this.tryNext(value);
  5641. }
  5642. };
  5643. ExhaustMapSubscriber.prototype.tryNext = function (value) {
  5644. var result;
  5645. var index = this.index++;
  5646. try {
  5647. result = this.project(value, index);
  5648. }
  5649. catch (err) {
  5650. this.destination.error(err);
  5651. return;
  5652. }
  5653. this.hasSubscription = true;
  5654. this._innerSub(result, value, index);
  5655. };
  5656. ExhaustMapSubscriber.prototype._innerSub = function (result, value, index) {
  5657. var innerSubscriber = new InnerSubscriber(this, value, index);
  5658. var destination = this.destination;
  5659. destination.add(innerSubscriber);
  5660. var innerSubscription = subscribeToResult(this, result, undefined, undefined, innerSubscriber);
  5661. if (innerSubscription !== innerSubscriber) {
  5662. destination.add(innerSubscription);
  5663. }
  5664. };
  5665. ExhaustMapSubscriber.prototype._complete = function () {
  5666. this.hasCompleted = true;
  5667. if (!this.hasSubscription) {
  5668. this.destination.complete();
  5669. }
  5670. this.unsubscribe();
  5671. };
  5672. ExhaustMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  5673. this.destination.next(innerValue);
  5674. };
  5675. ExhaustMapSubscriber.prototype.notifyError = function (err) {
  5676. this.destination.error(err);
  5677. };
  5678. ExhaustMapSubscriber.prototype.notifyComplete = function (innerSub) {
  5679. var destination = this.destination;
  5680. destination.remove(innerSub);
  5681. this.hasSubscription = false;
  5682. if (this.hasCompleted) {
  5683. this.destination.complete();
  5684. }
  5685. };
  5686. return ExhaustMapSubscriber;
  5687. }(OuterSubscriber));
  5688. function expand(project, concurrent, scheduler) {
  5689. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  5690. if (scheduler === void 0) { scheduler = undefined; }
  5691. concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
  5692. return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
  5693. }
  5694. var ExpandOperator = (function () {
  5695. function ExpandOperator(project, concurrent, scheduler) {
  5696. this.project = project;
  5697. this.concurrent = concurrent;
  5698. this.scheduler = scheduler;
  5699. }
  5700. ExpandOperator.prototype.call = function (subscriber, source) {
  5701. return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
  5702. };
  5703. return ExpandOperator;
  5704. }());
  5705. var ExpandSubscriber = (function (_super) {
  5706. __extends(ExpandSubscriber, _super);
  5707. function ExpandSubscriber(destination, project, concurrent, scheduler) {
  5708. var _this = _super.call(this, destination) || this;
  5709. _this.project = project;
  5710. _this.concurrent = concurrent;
  5711. _this.scheduler = scheduler;
  5712. _this.index = 0;
  5713. _this.active = 0;
  5714. _this.hasCompleted = false;
  5715. if (concurrent < Number.POSITIVE_INFINITY) {
  5716. _this.buffer = [];
  5717. }
  5718. return _this;
  5719. }
  5720. ExpandSubscriber.dispatch = function (arg) {
  5721. var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
  5722. subscriber.subscribeToProjection(result, value, index);
  5723. };
  5724. ExpandSubscriber.prototype._next = function (value) {
  5725. var destination = this.destination;
  5726. if (destination.closed) {
  5727. this._complete();
  5728. return;
  5729. }
  5730. var index = this.index++;
  5731. if (this.active < this.concurrent) {
  5732. destination.next(value);
  5733. try {
  5734. var project = this.project;
  5735. var result = project(value, index);
  5736. if (!this.scheduler) {
  5737. this.subscribeToProjection(result, value, index);
  5738. }
  5739. else {
  5740. var state = { subscriber: this, result: result, value: value, index: index };
  5741. var destination_1 = this.destination;
  5742. destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
  5743. }
  5744. }
  5745. catch (e) {
  5746. destination.error(e);
  5747. }
  5748. }
  5749. else {
  5750. this.buffer.push(value);
  5751. }
  5752. };
  5753. ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
  5754. this.active++;
  5755. var destination = this.destination;
  5756. destination.add(subscribeToResult(this, result, value, index));
  5757. };
  5758. ExpandSubscriber.prototype._complete = function () {
  5759. this.hasCompleted = true;
  5760. if (this.hasCompleted && this.active === 0) {
  5761. this.destination.complete();
  5762. }
  5763. this.unsubscribe();
  5764. };
  5765. ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  5766. this._next(innerValue);
  5767. };
  5768. ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
  5769. var buffer = this.buffer;
  5770. var destination = this.destination;
  5771. destination.remove(innerSub);
  5772. this.active--;
  5773. if (buffer && buffer.length > 0) {
  5774. this._next(buffer.shift());
  5775. }
  5776. if (this.hasCompleted && this.active === 0) {
  5777. this.destination.complete();
  5778. }
  5779. };
  5780. return ExpandSubscriber;
  5781. }(OuterSubscriber));
  5782. function finalize(callback) {
  5783. return function (source) { return source.lift(new FinallyOperator(callback)); };
  5784. }
  5785. var FinallyOperator = (function () {
  5786. function FinallyOperator(callback) {
  5787. this.callback = callback;
  5788. }
  5789. FinallyOperator.prototype.call = function (subscriber, source) {
  5790. return source.subscribe(new FinallySubscriber(subscriber, this.callback));
  5791. };
  5792. return FinallyOperator;
  5793. }());
  5794. var FinallySubscriber = (function (_super) {
  5795. __extends(FinallySubscriber, _super);
  5796. function FinallySubscriber(destination, callback) {
  5797. var _this = _super.call(this, destination) || this;
  5798. _this.add(new Subscription(callback));
  5799. return _this;
  5800. }
  5801. return FinallySubscriber;
  5802. }(Subscriber));
  5803. function find(predicate, thisArg) {
  5804. if (typeof predicate !== 'function') {
  5805. throw new TypeError('predicate is not a function');
  5806. }
  5807. return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
  5808. }
  5809. var FindValueOperator = (function () {
  5810. function FindValueOperator(predicate, source, yieldIndex, thisArg) {
  5811. this.predicate = predicate;
  5812. this.source = source;
  5813. this.yieldIndex = yieldIndex;
  5814. this.thisArg = thisArg;
  5815. }
  5816. FindValueOperator.prototype.call = function (observer, source) {
  5817. return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
  5818. };
  5819. return FindValueOperator;
  5820. }());
  5821. var FindValueSubscriber = (function (_super) {
  5822. __extends(FindValueSubscriber, _super);
  5823. function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
  5824. var _this = _super.call(this, destination) || this;
  5825. _this.predicate = predicate;
  5826. _this.source = source;
  5827. _this.yieldIndex = yieldIndex;
  5828. _this.thisArg = thisArg;
  5829. _this.index = 0;
  5830. return _this;
  5831. }
  5832. FindValueSubscriber.prototype.notifyComplete = function (value) {
  5833. var destination = this.destination;
  5834. destination.next(value);
  5835. destination.complete();
  5836. this.unsubscribe();
  5837. };
  5838. FindValueSubscriber.prototype._next = function (value) {
  5839. var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
  5840. var index = this.index++;
  5841. try {
  5842. var result = predicate.call(thisArg || this, value, index, this.source);
  5843. if (result) {
  5844. this.notifyComplete(this.yieldIndex ? index : value);
  5845. }
  5846. }
  5847. catch (err) {
  5848. this.destination.error(err);
  5849. }
  5850. };
  5851. FindValueSubscriber.prototype._complete = function () {
  5852. this.notifyComplete(this.yieldIndex ? -1 : undefined);
  5853. };
  5854. return FindValueSubscriber;
  5855. }(Subscriber));
  5856. function findIndex(predicate, thisArg) {
  5857. return function (source) { return source.lift(new FindValueOperator(predicate, source, true, thisArg)); };
  5858. }
  5859. function first(predicate, defaultValue) {
  5860. var hasDefaultValue = arguments.length >= 2;
  5861. return function (source) { return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); })); };
  5862. }
  5863. function ignoreElements() {
  5864. return function ignoreElementsOperatorFunction(source) {
  5865. return source.lift(new IgnoreElementsOperator());
  5866. };
  5867. }
  5868. var IgnoreElementsOperator = (function () {
  5869. function IgnoreElementsOperator() {
  5870. }
  5871. IgnoreElementsOperator.prototype.call = function (subscriber, source) {
  5872. return source.subscribe(new IgnoreElementsSubscriber(subscriber));
  5873. };
  5874. return IgnoreElementsOperator;
  5875. }());
  5876. var IgnoreElementsSubscriber = (function (_super) {
  5877. __extends(IgnoreElementsSubscriber, _super);
  5878. function IgnoreElementsSubscriber() {
  5879. return _super !== null && _super.apply(this, arguments) || this;
  5880. }
  5881. IgnoreElementsSubscriber.prototype._next = function (unused) {
  5882. };
  5883. return IgnoreElementsSubscriber;
  5884. }(Subscriber));
  5885. function isEmpty() {
  5886. return function (source) { return source.lift(new IsEmptyOperator()); };
  5887. }
  5888. var IsEmptyOperator = (function () {
  5889. function IsEmptyOperator() {
  5890. }
  5891. IsEmptyOperator.prototype.call = function (observer, source) {
  5892. return source.subscribe(new IsEmptySubscriber(observer));
  5893. };
  5894. return IsEmptyOperator;
  5895. }());
  5896. var IsEmptySubscriber = (function (_super) {
  5897. __extends(IsEmptySubscriber, _super);
  5898. function IsEmptySubscriber(destination) {
  5899. return _super.call(this, destination) || this;
  5900. }
  5901. IsEmptySubscriber.prototype.notifyComplete = function (isEmpty) {
  5902. var destination = this.destination;
  5903. destination.next(isEmpty);
  5904. destination.complete();
  5905. };
  5906. IsEmptySubscriber.prototype._next = function (value) {
  5907. this.notifyComplete(false);
  5908. };
  5909. IsEmptySubscriber.prototype._complete = function () {
  5910. this.notifyComplete(true);
  5911. };
  5912. return IsEmptySubscriber;
  5913. }(Subscriber));
  5914. function takeLast(count) {
  5915. return function takeLastOperatorFunction(source) {
  5916. if (count === 0) {
  5917. return empty$1();
  5918. }
  5919. else {
  5920. return source.lift(new TakeLastOperator(count));
  5921. }
  5922. };
  5923. }
  5924. var TakeLastOperator = (function () {
  5925. function TakeLastOperator(total) {
  5926. this.total = total;
  5927. if (this.total < 0) {
  5928. throw new ArgumentOutOfRangeError;
  5929. }
  5930. }
  5931. TakeLastOperator.prototype.call = function (subscriber, source) {
  5932. return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
  5933. };
  5934. return TakeLastOperator;
  5935. }());
  5936. var TakeLastSubscriber = (function (_super) {
  5937. __extends(TakeLastSubscriber, _super);
  5938. function TakeLastSubscriber(destination, total) {
  5939. var _this = _super.call(this, destination) || this;
  5940. _this.total = total;
  5941. _this.ring = new Array();
  5942. _this.count = 0;
  5943. return _this;
  5944. }
  5945. TakeLastSubscriber.prototype._next = function (value) {
  5946. var ring = this.ring;
  5947. var total = this.total;
  5948. var count = this.count++;
  5949. if (ring.length < total) {
  5950. ring.push(value);
  5951. }
  5952. else {
  5953. var index = count % total;
  5954. ring[index] = value;
  5955. }
  5956. };
  5957. TakeLastSubscriber.prototype._complete = function () {
  5958. var destination = this.destination;
  5959. var count = this.count;
  5960. if (count > 0) {
  5961. var total = this.count >= this.total ? this.total : this.count;
  5962. var ring = this.ring;
  5963. for (var i = 0; i < total; i++) {
  5964. var idx = (count++) % total;
  5965. destination.next(ring[idx]);
  5966. }
  5967. }
  5968. destination.complete();
  5969. };
  5970. return TakeLastSubscriber;
  5971. }(Subscriber));
  5972. function last(predicate, defaultValue) {
  5973. var hasDefaultValue = arguments.length >= 2;
  5974. return function (source) { return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, takeLast(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); })); };
  5975. }
  5976. function mapTo(value) {
  5977. return function (source) { return source.lift(new MapToOperator(value)); };
  5978. }
  5979. var MapToOperator = (function () {
  5980. function MapToOperator(value) {
  5981. this.value = value;
  5982. }
  5983. MapToOperator.prototype.call = function (subscriber, source) {
  5984. return source.subscribe(new MapToSubscriber(subscriber, this.value));
  5985. };
  5986. return MapToOperator;
  5987. }());
  5988. var MapToSubscriber = (function (_super) {
  5989. __extends(MapToSubscriber, _super);
  5990. function MapToSubscriber(destination, value) {
  5991. var _this = _super.call(this, destination) || this;
  5992. _this.value = value;
  5993. return _this;
  5994. }
  5995. MapToSubscriber.prototype._next = function (x) {
  5996. this.destination.next(this.value);
  5997. };
  5998. return MapToSubscriber;
  5999. }(Subscriber));
  6000. function materialize() {
  6001. return function materializeOperatorFunction(source) {
  6002. return source.lift(new MaterializeOperator());
  6003. };
  6004. }
  6005. var MaterializeOperator = (function () {
  6006. function MaterializeOperator() {
  6007. }
  6008. MaterializeOperator.prototype.call = function (subscriber, source) {
  6009. return source.subscribe(new MaterializeSubscriber(subscriber));
  6010. };
  6011. return MaterializeOperator;
  6012. }());
  6013. var MaterializeSubscriber = (function (_super) {
  6014. __extends(MaterializeSubscriber, _super);
  6015. function MaterializeSubscriber(destination) {
  6016. return _super.call(this, destination) || this;
  6017. }
  6018. MaterializeSubscriber.prototype._next = function (value) {
  6019. this.destination.next(Notification.createNext(value));
  6020. };
  6021. MaterializeSubscriber.prototype._error = function (err) {
  6022. var destination = this.destination;
  6023. destination.next(Notification.createError(err));
  6024. destination.complete();
  6025. };
  6026. MaterializeSubscriber.prototype._complete = function () {
  6027. var destination = this.destination;
  6028. destination.next(Notification.createComplete());
  6029. destination.complete();
  6030. };
  6031. return MaterializeSubscriber;
  6032. }(Subscriber));
  6033. function reduce(accumulator, seed) {
  6034. if (arguments.length >= 2) {
  6035. return function reduceOperatorFunctionWithSeed(source) {
  6036. return pipe(scan(accumulator, seed), takeLast(1), defaultIfEmpty(seed))(source);
  6037. };
  6038. }
  6039. return function reduceOperatorFunction(source) {
  6040. return pipe(scan(function (acc, value, index) { return accumulator(acc, value, index + 1); }), takeLast(1))(source);
  6041. };
  6042. }
  6043. function max(comparer) {
  6044. var max = (typeof comparer === 'function')
  6045. ? function (x, y) { return comparer(x, y) > 0 ? x : y; }
  6046. : function (x, y) { return x > y ? x : y; };
  6047. return reduce(max);
  6048. }
  6049. function merge$1() {
  6050. var observables = [];
  6051. for (var _i = 0; _i < arguments.length; _i++) {
  6052. observables[_i] = arguments[_i];
  6053. }
  6054. return function (source) { return source.lift.call(merge.apply(void 0, [source].concat(observables))); };
  6055. }
  6056. function mergeMapTo(innerObservable, resultSelector, concurrent) {
  6057. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  6058. if (typeof resultSelector === 'function') {
  6059. return mergeMap(function () { return innerObservable; }, resultSelector, concurrent);
  6060. }
  6061. if (typeof resultSelector === 'number') {
  6062. concurrent = resultSelector;
  6063. }
  6064. return mergeMap(function () { return innerObservable; }, concurrent);
  6065. }
  6066. function mergeScan(accumulator, seed, concurrent) {
  6067. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  6068. return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
  6069. }
  6070. var MergeScanOperator = (function () {
  6071. function MergeScanOperator(accumulator, seed, concurrent) {
  6072. this.accumulator = accumulator;
  6073. this.seed = seed;
  6074. this.concurrent = concurrent;
  6075. }
  6076. MergeScanOperator.prototype.call = function (subscriber, source) {
  6077. return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
  6078. };
  6079. return MergeScanOperator;
  6080. }());
  6081. var MergeScanSubscriber = (function (_super) {
  6082. __extends(MergeScanSubscriber, _super);
  6083. function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
  6084. var _this = _super.call(this, destination) || this;
  6085. _this.accumulator = accumulator;
  6086. _this.acc = acc;
  6087. _this.concurrent = concurrent;
  6088. _this.hasValue = false;
  6089. _this.hasCompleted = false;
  6090. _this.buffer = [];
  6091. _this.active = 0;
  6092. _this.index = 0;
  6093. return _this;
  6094. }
  6095. MergeScanSubscriber.prototype._next = function (value) {
  6096. if (this.active < this.concurrent) {
  6097. var index = this.index++;
  6098. var destination = this.destination;
  6099. var ish = void 0;
  6100. try {
  6101. var accumulator = this.accumulator;
  6102. ish = accumulator(this.acc, value, index);
  6103. }
  6104. catch (e) {
  6105. return destination.error(e);
  6106. }
  6107. this.active++;
  6108. this._innerSub(ish, value, index);
  6109. }
  6110. else {
  6111. this.buffer.push(value);
  6112. }
  6113. };
  6114. MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
  6115. var innerSubscriber = new InnerSubscriber(this, value, index);
  6116. var destination = this.destination;
  6117. destination.add(innerSubscriber);
  6118. var innerSubscription = subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
  6119. if (innerSubscription !== innerSubscriber) {
  6120. destination.add(innerSubscription);
  6121. }
  6122. };
  6123. MergeScanSubscriber.prototype._complete = function () {
  6124. this.hasCompleted = true;
  6125. if (this.active === 0 && this.buffer.length === 0) {
  6126. if (this.hasValue === false) {
  6127. this.destination.next(this.acc);
  6128. }
  6129. this.destination.complete();
  6130. }
  6131. this.unsubscribe();
  6132. };
  6133. MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  6134. var destination = this.destination;
  6135. this.acc = innerValue;
  6136. this.hasValue = true;
  6137. destination.next(innerValue);
  6138. };
  6139. MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
  6140. var buffer = this.buffer;
  6141. var destination = this.destination;
  6142. destination.remove(innerSub);
  6143. this.active--;
  6144. if (buffer.length > 0) {
  6145. this._next(buffer.shift());
  6146. }
  6147. else if (this.active === 0 && this.hasCompleted) {
  6148. if (this.hasValue === false) {
  6149. this.destination.next(this.acc);
  6150. }
  6151. this.destination.complete();
  6152. }
  6153. };
  6154. return MergeScanSubscriber;
  6155. }(OuterSubscriber));
  6156. function min(comparer) {
  6157. var min = (typeof comparer === 'function')
  6158. ? function (x, y) { return comparer(x, y) < 0 ? x : y; }
  6159. : function (x, y) { return x < y ? x : y; };
  6160. return reduce(min);
  6161. }
  6162. function multicast(subjectOrSubjectFactory, selector) {
  6163. return function multicastOperatorFunction(source) {
  6164. var subjectFactory;
  6165. if (typeof subjectOrSubjectFactory === 'function') {
  6166. subjectFactory = subjectOrSubjectFactory;
  6167. }
  6168. else {
  6169. subjectFactory = function subjectFactory() {
  6170. return subjectOrSubjectFactory;
  6171. };
  6172. }
  6173. if (typeof selector === 'function') {
  6174. return source.lift(new MulticastOperator(subjectFactory, selector));
  6175. }
  6176. var connectable = Object.create(source, connectableObservableDescriptor);
  6177. connectable.source = source;
  6178. connectable.subjectFactory = subjectFactory;
  6179. return connectable;
  6180. };
  6181. }
  6182. var MulticastOperator = (function () {
  6183. function MulticastOperator(subjectFactory, selector) {
  6184. this.subjectFactory = subjectFactory;
  6185. this.selector = selector;
  6186. }
  6187. MulticastOperator.prototype.call = function (subscriber, source) {
  6188. var selector = this.selector;
  6189. var subject = this.subjectFactory();
  6190. var subscription = selector(subject).subscribe(subscriber);
  6191. subscription.add(source.subscribe(subject));
  6192. return subscription;
  6193. };
  6194. return MulticastOperator;
  6195. }());
  6196. function onErrorResumeNext$1() {
  6197. var nextSources = [];
  6198. for (var _i = 0; _i < arguments.length; _i++) {
  6199. nextSources[_i] = arguments[_i];
  6200. }
  6201. if (nextSources.length === 1 && isArray(nextSources[0])) {
  6202. nextSources = nextSources[0];
  6203. }
  6204. return function (source) { return source.lift(new OnErrorResumeNextOperator(nextSources)); };
  6205. }
  6206. var OnErrorResumeNextOperator = (function () {
  6207. function OnErrorResumeNextOperator(nextSources) {
  6208. this.nextSources = nextSources;
  6209. }
  6210. OnErrorResumeNextOperator.prototype.call = function (subscriber, source) {
  6211. return source.subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources));
  6212. };
  6213. return OnErrorResumeNextOperator;
  6214. }());
  6215. var OnErrorResumeNextSubscriber = (function (_super) {
  6216. __extends(OnErrorResumeNextSubscriber, _super);
  6217. function OnErrorResumeNextSubscriber(destination, nextSources) {
  6218. var _this = _super.call(this, destination) || this;
  6219. _this.destination = destination;
  6220. _this.nextSources = nextSources;
  6221. return _this;
  6222. }
  6223. OnErrorResumeNextSubscriber.prototype.notifyError = function (error, innerSub) {
  6224. this.subscribeToNextSource();
  6225. };
  6226. OnErrorResumeNextSubscriber.prototype.notifyComplete = function (innerSub) {
  6227. this.subscribeToNextSource();
  6228. };
  6229. OnErrorResumeNextSubscriber.prototype._error = function (err) {
  6230. this.subscribeToNextSource();
  6231. this.unsubscribe();
  6232. };
  6233. OnErrorResumeNextSubscriber.prototype._complete = function () {
  6234. this.subscribeToNextSource();
  6235. this.unsubscribe();
  6236. };
  6237. OnErrorResumeNextSubscriber.prototype.subscribeToNextSource = function () {
  6238. var next = this.nextSources.shift();
  6239. if (!!next) {
  6240. var innerSubscriber = new InnerSubscriber(this, undefined, undefined);
  6241. var destination = this.destination;
  6242. destination.add(innerSubscriber);
  6243. var innerSubscription = subscribeToResult(this, next, undefined, undefined, innerSubscriber);
  6244. if (innerSubscription !== innerSubscriber) {
  6245. destination.add(innerSubscription);
  6246. }
  6247. }
  6248. else {
  6249. this.destination.complete();
  6250. }
  6251. };
  6252. return OnErrorResumeNextSubscriber;
  6253. }(OuterSubscriber));
  6254. function pairwise() {
  6255. return function (source) { return source.lift(new PairwiseOperator()); };
  6256. }
  6257. var PairwiseOperator = (function () {
  6258. function PairwiseOperator() {
  6259. }
  6260. PairwiseOperator.prototype.call = function (subscriber, source) {
  6261. return source.subscribe(new PairwiseSubscriber(subscriber));
  6262. };
  6263. return PairwiseOperator;
  6264. }());
  6265. var PairwiseSubscriber = (function (_super) {
  6266. __extends(PairwiseSubscriber, _super);
  6267. function PairwiseSubscriber(destination) {
  6268. var _this = _super.call(this, destination) || this;
  6269. _this.hasPrev = false;
  6270. return _this;
  6271. }
  6272. PairwiseSubscriber.prototype._next = function (value) {
  6273. var pair;
  6274. if (this.hasPrev) {
  6275. pair = [this.prev, value];
  6276. }
  6277. else {
  6278. this.hasPrev = true;
  6279. }
  6280. this.prev = value;
  6281. if (pair) {
  6282. this.destination.next(pair);
  6283. }
  6284. };
  6285. return PairwiseSubscriber;
  6286. }(Subscriber));
  6287. function partition$1(predicate, thisArg) {
  6288. return function (source) { return [
  6289. filter(predicate, thisArg)(source),
  6290. filter(not(predicate, thisArg))(source)
  6291. ]; };
  6292. }
  6293. function pluck() {
  6294. var properties = [];
  6295. for (var _i = 0; _i < arguments.length; _i++) {
  6296. properties[_i] = arguments[_i];
  6297. }
  6298. var length = properties.length;
  6299. if (length === 0) {
  6300. throw new Error('list of properties cannot be empty.');
  6301. }
  6302. return function (source) { return map(plucker(properties, length))(source); };
  6303. }
  6304. function plucker(props, length) {
  6305. var mapper = function (x) {
  6306. var currentProp = x;
  6307. for (var i = 0; i < length; i++) {
  6308. var p = currentProp[props[i]];
  6309. if (typeof p !== 'undefined') {
  6310. currentProp = p;
  6311. }
  6312. else {
  6313. return undefined;
  6314. }
  6315. }
  6316. return currentProp;
  6317. };
  6318. return mapper;
  6319. }
  6320. function publish(selector) {
  6321. return selector ?
  6322. multicast(function () { return new Subject(); }, selector) :
  6323. multicast(new Subject());
  6324. }
  6325. function publishBehavior(value) {
  6326. return function (source) { return multicast(new BehaviorSubject(value))(source); };
  6327. }
  6328. function publishLast() {
  6329. return function (source) { return multicast(new AsyncSubject())(source); };
  6330. }
  6331. function publishReplay(bufferSize, windowTime, selectorOrScheduler, scheduler) {
  6332. if (selectorOrScheduler && typeof selectorOrScheduler !== 'function') {
  6333. scheduler = selectorOrScheduler;
  6334. }
  6335. var selector = typeof selectorOrScheduler === 'function' ? selectorOrScheduler : undefined;
  6336. var subject = new ReplaySubject(bufferSize, windowTime, scheduler);
  6337. return function (source) { return multicast(function () { return subject; }, selector)(source); };
  6338. }
  6339. function race$1() {
  6340. var observables = [];
  6341. for (var _i = 0; _i < arguments.length; _i++) {
  6342. observables[_i] = arguments[_i];
  6343. }
  6344. return function raceOperatorFunction(source) {
  6345. if (observables.length === 1 && isArray(observables[0])) {
  6346. observables = observables[0];
  6347. }
  6348. return source.lift.call(race.apply(void 0, [source].concat(observables)));
  6349. };
  6350. }
  6351. function repeat(count) {
  6352. if (count === void 0) { count = -1; }
  6353. return function (source) {
  6354. if (count === 0) {
  6355. return empty$1();
  6356. }
  6357. else if (count < 0) {
  6358. return source.lift(new RepeatOperator(-1, source));
  6359. }
  6360. else {
  6361. return source.lift(new RepeatOperator(count - 1, source));
  6362. }
  6363. };
  6364. }
  6365. var RepeatOperator = (function () {
  6366. function RepeatOperator(count, source) {
  6367. this.count = count;
  6368. this.source = source;
  6369. }
  6370. RepeatOperator.prototype.call = function (subscriber, source) {
  6371. return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
  6372. };
  6373. return RepeatOperator;
  6374. }());
  6375. var RepeatSubscriber = (function (_super) {
  6376. __extends(RepeatSubscriber, _super);
  6377. function RepeatSubscriber(destination, count, source) {
  6378. var _this = _super.call(this, destination) || this;
  6379. _this.count = count;
  6380. _this.source = source;
  6381. return _this;
  6382. }
  6383. RepeatSubscriber.prototype.complete = function () {
  6384. if (!this.isStopped) {
  6385. var _a = this, source = _a.source, count = _a.count;
  6386. if (count === 0) {
  6387. return _super.prototype.complete.call(this);
  6388. }
  6389. else if (count > -1) {
  6390. this.count = count - 1;
  6391. }
  6392. source.subscribe(this._unsubscribeAndRecycle());
  6393. }
  6394. };
  6395. return RepeatSubscriber;
  6396. }(Subscriber));
  6397. function repeatWhen(notifier) {
  6398. return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
  6399. }
  6400. var RepeatWhenOperator = (function () {
  6401. function RepeatWhenOperator(notifier) {
  6402. this.notifier = notifier;
  6403. }
  6404. RepeatWhenOperator.prototype.call = function (subscriber, source) {
  6405. return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
  6406. };
  6407. return RepeatWhenOperator;
  6408. }());
  6409. var RepeatWhenSubscriber = (function (_super) {
  6410. __extends(RepeatWhenSubscriber, _super);
  6411. function RepeatWhenSubscriber(destination, notifier, source) {
  6412. var _this = _super.call(this, destination) || this;
  6413. _this.notifier = notifier;
  6414. _this.source = source;
  6415. _this.sourceIsBeingSubscribedTo = true;
  6416. return _this;
  6417. }
  6418. RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  6419. this.sourceIsBeingSubscribedTo = true;
  6420. this.source.subscribe(this);
  6421. };
  6422. RepeatWhenSubscriber.prototype.notifyComplete = function (innerSub) {
  6423. if (this.sourceIsBeingSubscribedTo === false) {
  6424. return _super.prototype.complete.call(this);
  6425. }
  6426. };
  6427. RepeatWhenSubscriber.prototype.complete = function () {
  6428. this.sourceIsBeingSubscribedTo = false;
  6429. if (!this.isStopped) {
  6430. if (!this.retries) {
  6431. this.subscribeToRetries();
  6432. }
  6433. if (!this.retriesSubscription || this.retriesSubscription.closed) {
  6434. return _super.prototype.complete.call(this);
  6435. }
  6436. this._unsubscribeAndRecycle();
  6437. this.notifications.next();
  6438. }
  6439. };
  6440. RepeatWhenSubscriber.prototype._unsubscribe = function () {
  6441. var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
  6442. if (notifications) {
  6443. notifications.unsubscribe();
  6444. this.notifications = null;
  6445. }
  6446. if (retriesSubscription) {
  6447. retriesSubscription.unsubscribe();
  6448. this.retriesSubscription = null;
  6449. }
  6450. this.retries = null;
  6451. };
  6452. RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
  6453. var _unsubscribe = this._unsubscribe;
  6454. this._unsubscribe = null;
  6455. _super.prototype._unsubscribeAndRecycle.call(this);
  6456. this._unsubscribe = _unsubscribe;
  6457. return this;
  6458. };
  6459. RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
  6460. this.notifications = new Subject();
  6461. var retries;
  6462. try {
  6463. var notifier = this.notifier;
  6464. retries = notifier(this.notifications);
  6465. }
  6466. catch (e) {
  6467. return _super.prototype.complete.call(this);
  6468. }
  6469. this.retries = retries;
  6470. this.retriesSubscription = subscribeToResult(this, retries);
  6471. };
  6472. return RepeatWhenSubscriber;
  6473. }(OuterSubscriber));
  6474. function retry(count) {
  6475. if (count === void 0) { count = -1; }
  6476. return function (source) { return source.lift(new RetryOperator(count, source)); };
  6477. }
  6478. var RetryOperator = (function () {
  6479. function RetryOperator(count, source) {
  6480. this.count = count;
  6481. this.source = source;
  6482. }
  6483. RetryOperator.prototype.call = function (subscriber, source) {
  6484. return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
  6485. };
  6486. return RetryOperator;
  6487. }());
  6488. var RetrySubscriber = (function (_super) {
  6489. __extends(RetrySubscriber, _super);
  6490. function RetrySubscriber(destination, count, source) {
  6491. var _this = _super.call(this, destination) || this;
  6492. _this.count = count;
  6493. _this.source = source;
  6494. return _this;
  6495. }
  6496. RetrySubscriber.prototype.error = function (err) {
  6497. if (!this.isStopped) {
  6498. var _a = this, source = _a.source, count = _a.count;
  6499. if (count === 0) {
  6500. return _super.prototype.error.call(this, err);
  6501. }
  6502. else if (count > -1) {
  6503. this.count = count - 1;
  6504. }
  6505. source.subscribe(this._unsubscribeAndRecycle());
  6506. }
  6507. };
  6508. return RetrySubscriber;
  6509. }(Subscriber));
  6510. function retryWhen(notifier) {
  6511. return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
  6512. }
  6513. var RetryWhenOperator = (function () {
  6514. function RetryWhenOperator(notifier, source) {
  6515. this.notifier = notifier;
  6516. this.source = source;
  6517. }
  6518. RetryWhenOperator.prototype.call = function (subscriber, source) {
  6519. return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
  6520. };
  6521. return RetryWhenOperator;
  6522. }());
  6523. var RetryWhenSubscriber = (function (_super) {
  6524. __extends(RetryWhenSubscriber, _super);
  6525. function RetryWhenSubscriber(destination, notifier, source) {
  6526. var _this = _super.call(this, destination) || this;
  6527. _this.notifier = notifier;
  6528. _this.source = source;
  6529. return _this;
  6530. }
  6531. RetryWhenSubscriber.prototype.error = function (err) {
  6532. if (!this.isStopped) {
  6533. var errors = this.errors;
  6534. var retries = this.retries;
  6535. var retriesSubscription = this.retriesSubscription;
  6536. if (!retries) {
  6537. errors = new Subject();
  6538. try {
  6539. var notifier = this.notifier;
  6540. retries = notifier(errors);
  6541. }
  6542. catch (e) {
  6543. return _super.prototype.error.call(this, e);
  6544. }
  6545. retriesSubscription = subscribeToResult(this, retries);
  6546. }
  6547. else {
  6548. this.errors = null;
  6549. this.retriesSubscription = null;
  6550. }
  6551. this._unsubscribeAndRecycle();
  6552. this.errors = errors;
  6553. this.retries = retries;
  6554. this.retriesSubscription = retriesSubscription;
  6555. errors.next(err);
  6556. }
  6557. };
  6558. RetryWhenSubscriber.prototype._unsubscribe = function () {
  6559. var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
  6560. if (errors) {
  6561. errors.unsubscribe();
  6562. this.errors = null;
  6563. }
  6564. if (retriesSubscription) {
  6565. retriesSubscription.unsubscribe();
  6566. this.retriesSubscription = null;
  6567. }
  6568. this.retries = null;
  6569. };
  6570. RetryWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  6571. var _unsubscribe = this._unsubscribe;
  6572. this._unsubscribe = null;
  6573. this._unsubscribeAndRecycle();
  6574. this._unsubscribe = _unsubscribe;
  6575. this.source.subscribe(this);
  6576. };
  6577. return RetryWhenSubscriber;
  6578. }(OuterSubscriber));
  6579. function sample(notifier) {
  6580. return function (source) { return source.lift(new SampleOperator(notifier)); };
  6581. }
  6582. var SampleOperator = (function () {
  6583. function SampleOperator(notifier) {
  6584. this.notifier = notifier;
  6585. }
  6586. SampleOperator.prototype.call = function (subscriber, source) {
  6587. var sampleSubscriber = new SampleSubscriber(subscriber);
  6588. var subscription = source.subscribe(sampleSubscriber);
  6589. subscription.add(subscribeToResult(sampleSubscriber, this.notifier));
  6590. return subscription;
  6591. };
  6592. return SampleOperator;
  6593. }());
  6594. var SampleSubscriber = (function (_super) {
  6595. __extends(SampleSubscriber, _super);
  6596. function SampleSubscriber() {
  6597. var _this = _super !== null && _super.apply(this, arguments) || this;
  6598. _this.hasValue = false;
  6599. return _this;
  6600. }
  6601. SampleSubscriber.prototype._next = function (value) {
  6602. this.value = value;
  6603. this.hasValue = true;
  6604. };
  6605. SampleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  6606. this.emitValue();
  6607. };
  6608. SampleSubscriber.prototype.notifyComplete = function () {
  6609. this.emitValue();
  6610. };
  6611. SampleSubscriber.prototype.emitValue = function () {
  6612. if (this.hasValue) {
  6613. this.hasValue = false;
  6614. this.destination.next(this.value);
  6615. }
  6616. };
  6617. return SampleSubscriber;
  6618. }(OuterSubscriber));
  6619. function sampleTime(period, scheduler) {
  6620. if (scheduler === void 0) { scheduler = async; }
  6621. return function (source) { return source.lift(new SampleTimeOperator(period, scheduler)); };
  6622. }
  6623. var SampleTimeOperator = (function () {
  6624. function SampleTimeOperator(period, scheduler) {
  6625. this.period = period;
  6626. this.scheduler = scheduler;
  6627. }
  6628. SampleTimeOperator.prototype.call = function (subscriber, source) {
  6629. return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
  6630. };
  6631. return SampleTimeOperator;
  6632. }());
  6633. var SampleTimeSubscriber = (function (_super) {
  6634. __extends(SampleTimeSubscriber, _super);
  6635. function SampleTimeSubscriber(destination, period, scheduler) {
  6636. var _this = _super.call(this, destination) || this;
  6637. _this.period = period;
  6638. _this.scheduler = scheduler;
  6639. _this.hasValue = false;
  6640. _this.add(scheduler.schedule(dispatchNotification, period, { subscriber: _this, period: period }));
  6641. return _this;
  6642. }
  6643. SampleTimeSubscriber.prototype._next = function (value) {
  6644. this.lastValue = value;
  6645. this.hasValue = true;
  6646. };
  6647. SampleTimeSubscriber.prototype.notifyNext = function () {
  6648. if (this.hasValue) {
  6649. this.hasValue = false;
  6650. this.destination.next(this.lastValue);
  6651. }
  6652. };
  6653. return SampleTimeSubscriber;
  6654. }(Subscriber));
  6655. function dispatchNotification(state) {
  6656. var subscriber = state.subscriber, period = state.period;
  6657. subscriber.notifyNext();
  6658. this.schedule(state, period);
  6659. }
  6660. function sequenceEqual(compareTo, comparator) {
  6661. return function (source) { return source.lift(new SequenceEqualOperator(compareTo, comparator)); };
  6662. }
  6663. var SequenceEqualOperator = (function () {
  6664. function SequenceEqualOperator(compareTo, comparator) {
  6665. this.compareTo = compareTo;
  6666. this.comparator = comparator;
  6667. }
  6668. SequenceEqualOperator.prototype.call = function (subscriber, source) {
  6669. return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparator));
  6670. };
  6671. return SequenceEqualOperator;
  6672. }());
  6673. var SequenceEqualSubscriber = (function (_super) {
  6674. __extends(SequenceEqualSubscriber, _super);
  6675. function SequenceEqualSubscriber(destination, compareTo, comparator) {
  6676. var _this = _super.call(this, destination) || this;
  6677. _this.compareTo = compareTo;
  6678. _this.comparator = comparator;
  6679. _this._a = [];
  6680. _this._b = [];
  6681. _this._oneComplete = false;
  6682. _this.destination.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, _this)));
  6683. return _this;
  6684. }
  6685. SequenceEqualSubscriber.prototype._next = function (value) {
  6686. if (this._oneComplete && this._b.length === 0) {
  6687. this.emit(false);
  6688. }
  6689. else {
  6690. this._a.push(value);
  6691. this.checkValues();
  6692. }
  6693. };
  6694. SequenceEqualSubscriber.prototype._complete = function () {
  6695. if (this._oneComplete) {
  6696. this.emit(this._a.length === 0 && this._b.length === 0);
  6697. }
  6698. else {
  6699. this._oneComplete = true;
  6700. }
  6701. this.unsubscribe();
  6702. };
  6703. SequenceEqualSubscriber.prototype.checkValues = function () {
  6704. var _c = this, _a = _c._a, _b = _c._b, comparator = _c.comparator;
  6705. while (_a.length > 0 && _b.length > 0) {
  6706. var a = _a.shift();
  6707. var b = _b.shift();
  6708. var areEqual = false;
  6709. try {
  6710. areEqual = comparator ? comparator(a, b) : a === b;
  6711. }
  6712. catch (e) {
  6713. this.destination.error(e);
  6714. }
  6715. if (!areEqual) {
  6716. this.emit(false);
  6717. }
  6718. }
  6719. };
  6720. SequenceEqualSubscriber.prototype.emit = function (value) {
  6721. var destination = this.destination;
  6722. destination.next(value);
  6723. destination.complete();
  6724. };
  6725. SequenceEqualSubscriber.prototype.nextB = function (value) {
  6726. if (this._oneComplete && this._a.length === 0) {
  6727. this.emit(false);
  6728. }
  6729. else {
  6730. this._b.push(value);
  6731. this.checkValues();
  6732. }
  6733. };
  6734. SequenceEqualSubscriber.prototype.completeB = function () {
  6735. if (this._oneComplete) {
  6736. this.emit(this._a.length === 0 && this._b.length === 0);
  6737. }
  6738. else {
  6739. this._oneComplete = true;
  6740. }
  6741. };
  6742. return SequenceEqualSubscriber;
  6743. }(Subscriber));
  6744. var SequenceEqualCompareToSubscriber = (function (_super) {
  6745. __extends(SequenceEqualCompareToSubscriber, _super);
  6746. function SequenceEqualCompareToSubscriber(destination, parent) {
  6747. var _this = _super.call(this, destination) || this;
  6748. _this.parent = parent;
  6749. return _this;
  6750. }
  6751. SequenceEqualCompareToSubscriber.prototype._next = function (value) {
  6752. this.parent.nextB(value);
  6753. };
  6754. SequenceEqualCompareToSubscriber.prototype._error = function (err) {
  6755. this.parent.error(err);
  6756. this.unsubscribe();
  6757. };
  6758. SequenceEqualCompareToSubscriber.prototype._complete = function () {
  6759. this.parent.completeB();
  6760. this.unsubscribe();
  6761. };
  6762. return SequenceEqualCompareToSubscriber;
  6763. }(Subscriber));
  6764. function shareSubjectFactory() {
  6765. return new Subject();
  6766. }
  6767. function share() {
  6768. return function (source) { return refCount()(multicast(shareSubjectFactory)(source)); };
  6769. }
  6770. function shareReplay(configOrBufferSize, windowTime, scheduler) {
  6771. var config;
  6772. if (configOrBufferSize && typeof configOrBufferSize === 'object') {
  6773. config = configOrBufferSize;
  6774. }
  6775. else {
  6776. config = {
  6777. bufferSize: configOrBufferSize,
  6778. windowTime: windowTime,
  6779. refCount: false,
  6780. scheduler: scheduler
  6781. };
  6782. }
  6783. return function (source) { return source.lift(shareReplayOperator(config)); };
  6784. }
  6785. function shareReplayOperator(_a) {
  6786. var _b = _a.bufferSize, bufferSize = _b === void 0 ? Number.POSITIVE_INFINITY : _b, _c = _a.windowTime, windowTime = _c === void 0 ? Number.POSITIVE_INFINITY : _c, useRefCount = _a.refCount, scheduler = _a.scheduler;
  6787. var subject;
  6788. var refCount = 0;
  6789. var subscription;
  6790. var hasError = false;
  6791. var isComplete = false;
  6792. return function shareReplayOperation(source) {
  6793. refCount++;
  6794. if (!subject || hasError) {
  6795. hasError = false;
  6796. subject = new ReplaySubject(bufferSize, windowTime, scheduler);
  6797. subscription = source.subscribe({
  6798. next: function (value) { subject.next(value); },
  6799. error: function (err) {
  6800. hasError = true;
  6801. subject.error(err);
  6802. },
  6803. complete: function () {
  6804. isComplete = true;
  6805. subscription = undefined;
  6806. subject.complete();
  6807. },
  6808. });
  6809. }
  6810. var innerSub = subject.subscribe(this);
  6811. this.add(function () {
  6812. refCount--;
  6813. innerSub.unsubscribe();
  6814. if (subscription && !isComplete && useRefCount && refCount === 0) {
  6815. subscription.unsubscribe();
  6816. subscription = undefined;
  6817. subject = undefined;
  6818. }
  6819. });
  6820. };
  6821. }
  6822. function single(predicate) {
  6823. return function (source) { return source.lift(new SingleOperator(predicate, source)); };
  6824. }
  6825. var SingleOperator = (function () {
  6826. function SingleOperator(predicate, source) {
  6827. this.predicate = predicate;
  6828. this.source = source;
  6829. }
  6830. SingleOperator.prototype.call = function (subscriber, source) {
  6831. return source.subscribe(new SingleSubscriber(subscriber, this.predicate, this.source));
  6832. };
  6833. return SingleOperator;
  6834. }());
  6835. var SingleSubscriber = (function (_super) {
  6836. __extends(SingleSubscriber, _super);
  6837. function SingleSubscriber(destination, predicate, source) {
  6838. var _this = _super.call(this, destination) || this;
  6839. _this.predicate = predicate;
  6840. _this.source = source;
  6841. _this.seenValue = false;
  6842. _this.index = 0;
  6843. return _this;
  6844. }
  6845. SingleSubscriber.prototype.applySingleValue = function (value) {
  6846. if (this.seenValue) {
  6847. this.destination.error('Sequence contains more than one element');
  6848. }
  6849. else {
  6850. this.seenValue = true;
  6851. this.singleValue = value;
  6852. }
  6853. };
  6854. SingleSubscriber.prototype._next = function (value) {
  6855. var index = this.index++;
  6856. if (this.predicate) {
  6857. this.tryNext(value, index);
  6858. }
  6859. else {
  6860. this.applySingleValue(value);
  6861. }
  6862. };
  6863. SingleSubscriber.prototype.tryNext = function (value, index) {
  6864. try {
  6865. if (this.predicate(value, index, this.source)) {
  6866. this.applySingleValue(value);
  6867. }
  6868. }
  6869. catch (err) {
  6870. this.destination.error(err);
  6871. }
  6872. };
  6873. SingleSubscriber.prototype._complete = function () {
  6874. var destination = this.destination;
  6875. if (this.index > 0) {
  6876. destination.next(this.seenValue ? this.singleValue : undefined);
  6877. destination.complete();
  6878. }
  6879. else {
  6880. destination.error(new EmptyError);
  6881. }
  6882. };
  6883. return SingleSubscriber;
  6884. }(Subscriber));
  6885. function skip(count) {
  6886. return function (source) { return source.lift(new SkipOperator(count)); };
  6887. }
  6888. var SkipOperator = (function () {
  6889. function SkipOperator(total) {
  6890. this.total = total;
  6891. }
  6892. SkipOperator.prototype.call = function (subscriber, source) {
  6893. return source.subscribe(new SkipSubscriber(subscriber, this.total));
  6894. };
  6895. return SkipOperator;
  6896. }());
  6897. var SkipSubscriber = (function (_super) {
  6898. __extends(SkipSubscriber, _super);
  6899. function SkipSubscriber(destination, total) {
  6900. var _this = _super.call(this, destination) || this;
  6901. _this.total = total;
  6902. _this.count = 0;
  6903. return _this;
  6904. }
  6905. SkipSubscriber.prototype._next = function (x) {
  6906. if (++this.count > this.total) {
  6907. this.destination.next(x);
  6908. }
  6909. };
  6910. return SkipSubscriber;
  6911. }(Subscriber));
  6912. function skipLast(count) {
  6913. return function (source) { return source.lift(new SkipLastOperator(count)); };
  6914. }
  6915. var SkipLastOperator = (function () {
  6916. function SkipLastOperator(_skipCount) {
  6917. this._skipCount = _skipCount;
  6918. if (this._skipCount < 0) {
  6919. throw new ArgumentOutOfRangeError;
  6920. }
  6921. }
  6922. SkipLastOperator.prototype.call = function (subscriber, source) {
  6923. if (this._skipCount === 0) {
  6924. return source.subscribe(new Subscriber(subscriber));
  6925. }
  6926. else {
  6927. return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
  6928. }
  6929. };
  6930. return SkipLastOperator;
  6931. }());
  6932. var SkipLastSubscriber = (function (_super) {
  6933. __extends(SkipLastSubscriber, _super);
  6934. function SkipLastSubscriber(destination, _skipCount) {
  6935. var _this = _super.call(this, destination) || this;
  6936. _this._skipCount = _skipCount;
  6937. _this._count = 0;
  6938. _this._ring = new Array(_skipCount);
  6939. return _this;
  6940. }
  6941. SkipLastSubscriber.prototype._next = function (value) {
  6942. var skipCount = this._skipCount;
  6943. var count = this._count++;
  6944. if (count < skipCount) {
  6945. this._ring[count] = value;
  6946. }
  6947. else {
  6948. var currentIndex = count % skipCount;
  6949. var ring = this._ring;
  6950. var oldValue = ring[currentIndex];
  6951. ring[currentIndex] = value;
  6952. this.destination.next(oldValue);
  6953. }
  6954. };
  6955. return SkipLastSubscriber;
  6956. }(Subscriber));
  6957. function skipUntil(notifier) {
  6958. return function (source) { return source.lift(new SkipUntilOperator(notifier)); };
  6959. }
  6960. var SkipUntilOperator = (function () {
  6961. function SkipUntilOperator(notifier) {
  6962. this.notifier = notifier;
  6963. }
  6964. SkipUntilOperator.prototype.call = function (destination, source) {
  6965. return source.subscribe(new SkipUntilSubscriber(destination, this.notifier));
  6966. };
  6967. return SkipUntilOperator;
  6968. }());
  6969. var SkipUntilSubscriber = (function (_super) {
  6970. __extends(SkipUntilSubscriber, _super);
  6971. function SkipUntilSubscriber(destination, notifier) {
  6972. var _this = _super.call(this, destination) || this;
  6973. _this.hasValue = false;
  6974. var innerSubscriber = new InnerSubscriber(_this, undefined, undefined);
  6975. _this.add(innerSubscriber);
  6976. _this.innerSubscription = innerSubscriber;
  6977. var innerSubscription = subscribeToResult(_this, notifier, undefined, undefined, innerSubscriber);
  6978. if (innerSubscription !== innerSubscriber) {
  6979. _this.add(innerSubscription);
  6980. _this.innerSubscription = innerSubscription;
  6981. }
  6982. return _this;
  6983. }
  6984. SkipUntilSubscriber.prototype._next = function (value) {
  6985. if (this.hasValue) {
  6986. _super.prototype._next.call(this, value);
  6987. }
  6988. };
  6989. SkipUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  6990. this.hasValue = true;
  6991. if (this.innerSubscription) {
  6992. this.innerSubscription.unsubscribe();
  6993. }
  6994. };
  6995. SkipUntilSubscriber.prototype.notifyComplete = function () {
  6996. };
  6997. return SkipUntilSubscriber;
  6998. }(OuterSubscriber));
  6999. function skipWhile(predicate) {
  7000. return function (source) { return source.lift(new SkipWhileOperator(predicate)); };
  7001. }
  7002. var SkipWhileOperator = (function () {
  7003. function SkipWhileOperator(predicate) {
  7004. this.predicate = predicate;
  7005. }
  7006. SkipWhileOperator.prototype.call = function (subscriber, source) {
  7007. return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
  7008. };
  7009. return SkipWhileOperator;
  7010. }());
  7011. var SkipWhileSubscriber = (function (_super) {
  7012. __extends(SkipWhileSubscriber, _super);
  7013. function SkipWhileSubscriber(destination, predicate) {
  7014. var _this = _super.call(this, destination) || this;
  7015. _this.predicate = predicate;
  7016. _this.skipping = true;
  7017. _this.index = 0;
  7018. return _this;
  7019. }
  7020. SkipWhileSubscriber.prototype._next = function (value) {
  7021. var destination = this.destination;
  7022. if (this.skipping) {
  7023. this.tryCallPredicate(value);
  7024. }
  7025. if (!this.skipping) {
  7026. destination.next(value);
  7027. }
  7028. };
  7029. SkipWhileSubscriber.prototype.tryCallPredicate = function (value) {
  7030. try {
  7031. var result = this.predicate(value, this.index++);
  7032. this.skipping = Boolean(result);
  7033. }
  7034. catch (err) {
  7035. this.destination.error(err);
  7036. }
  7037. };
  7038. return SkipWhileSubscriber;
  7039. }(Subscriber));
  7040. function startWith() {
  7041. var array = [];
  7042. for (var _i = 0; _i < arguments.length; _i++) {
  7043. array[_i] = arguments[_i];
  7044. }
  7045. var scheduler = array[array.length - 1];
  7046. if (isScheduler(scheduler)) {
  7047. array.pop();
  7048. return function (source) { return concat(array, source, scheduler); };
  7049. }
  7050. else {
  7051. return function (source) { return concat(array, source); };
  7052. }
  7053. }
  7054. function subscribeOn(scheduler, delay) {
  7055. if (delay === void 0) { delay = 0; }
  7056. return function subscribeOnOperatorFunction(source) {
  7057. return source.lift(new SubscribeOnOperator(scheduler, delay));
  7058. };
  7059. }
  7060. var SubscribeOnOperator = (function () {
  7061. function SubscribeOnOperator(scheduler, delay) {
  7062. this.scheduler = scheduler;
  7063. this.delay = delay;
  7064. }
  7065. SubscribeOnOperator.prototype.call = function (subscriber, source) {
  7066. return new SubscribeOnObservable(source, this.delay, this.scheduler).subscribe(subscriber);
  7067. };
  7068. return SubscribeOnOperator;
  7069. }());
  7070. function switchMap(project, resultSelector) {
  7071. if (typeof resultSelector === 'function') {
  7072. return function (source) { return source.pipe(switchMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
  7073. }
  7074. return function (source) { return source.lift(new SwitchMapOperator(project)); };
  7075. }
  7076. var SwitchMapOperator = (function () {
  7077. function SwitchMapOperator(project) {
  7078. this.project = project;
  7079. }
  7080. SwitchMapOperator.prototype.call = function (subscriber, source) {
  7081. return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
  7082. };
  7083. return SwitchMapOperator;
  7084. }());
  7085. var SwitchMapSubscriber = (function (_super) {
  7086. __extends(SwitchMapSubscriber, _super);
  7087. function SwitchMapSubscriber(destination, project) {
  7088. var _this = _super.call(this, destination) || this;
  7089. _this.project = project;
  7090. _this.index = 0;
  7091. return _this;
  7092. }
  7093. SwitchMapSubscriber.prototype._next = function (value) {
  7094. var result;
  7095. var index = this.index++;
  7096. try {
  7097. result = this.project(value, index);
  7098. }
  7099. catch (error) {
  7100. this.destination.error(error);
  7101. return;
  7102. }
  7103. this._innerSub(result, value, index);
  7104. };
  7105. SwitchMapSubscriber.prototype._innerSub = function (result, value, index) {
  7106. var innerSubscription = this.innerSubscription;
  7107. if (innerSubscription) {
  7108. innerSubscription.unsubscribe();
  7109. }
  7110. var innerSubscriber = new InnerSubscriber(this, value, index);
  7111. var destination = this.destination;
  7112. destination.add(innerSubscriber);
  7113. this.innerSubscription = subscribeToResult(this, result, undefined, undefined, innerSubscriber);
  7114. if (this.innerSubscription !== innerSubscriber) {
  7115. destination.add(this.innerSubscription);
  7116. }
  7117. };
  7118. SwitchMapSubscriber.prototype._complete = function () {
  7119. var innerSubscription = this.innerSubscription;
  7120. if (!innerSubscription || innerSubscription.closed) {
  7121. _super.prototype._complete.call(this);
  7122. }
  7123. this.unsubscribe();
  7124. };
  7125. SwitchMapSubscriber.prototype._unsubscribe = function () {
  7126. this.innerSubscription = null;
  7127. };
  7128. SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) {
  7129. var destination = this.destination;
  7130. destination.remove(innerSub);
  7131. this.innerSubscription = null;
  7132. if (this.isStopped) {
  7133. _super.prototype._complete.call(this);
  7134. }
  7135. };
  7136. SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  7137. this.destination.next(innerValue);
  7138. };
  7139. return SwitchMapSubscriber;
  7140. }(OuterSubscriber));
  7141. function switchAll() {
  7142. return switchMap(identity);
  7143. }
  7144. function switchMapTo(innerObservable, resultSelector) {
  7145. return resultSelector ? switchMap(function () { return innerObservable; }, resultSelector) : switchMap(function () { return innerObservable; });
  7146. }
  7147. function takeUntil(notifier) {
  7148. return function (source) { return source.lift(new TakeUntilOperator(notifier)); };
  7149. }
  7150. var TakeUntilOperator = (function () {
  7151. function TakeUntilOperator(notifier) {
  7152. this.notifier = notifier;
  7153. }
  7154. TakeUntilOperator.prototype.call = function (subscriber, source) {
  7155. var takeUntilSubscriber = new TakeUntilSubscriber(subscriber);
  7156. var notifierSubscription = subscribeToResult(takeUntilSubscriber, this.notifier);
  7157. if (notifierSubscription && !takeUntilSubscriber.seenValue) {
  7158. takeUntilSubscriber.add(notifierSubscription);
  7159. return source.subscribe(takeUntilSubscriber);
  7160. }
  7161. return takeUntilSubscriber;
  7162. };
  7163. return TakeUntilOperator;
  7164. }());
  7165. var TakeUntilSubscriber = (function (_super) {
  7166. __extends(TakeUntilSubscriber, _super);
  7167. function TakeUntilSubscriber(destination) {
  7168. var _this = _super.call(this, destination) || this;
  7169. _this.seenValue = false;
  7170. return _this;
  7171. }
  7172. TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  7173. this.seenValue = true;
  7174. this.complete();
  7175. };
  7176. TakeUntilSubscriber.prototype.notifyComplete = function () {
  7177. };
  7178. return TakeUntilSubscriber;
  7179. }(OuterSubscriber));
  7180. function takeWhile(predicate, inclusive) {
  7181. if (inclusive === void 0) { inclusive = false; }
  7182. return function (source) {
  7183. return source.lift(new TakeWhileOperator(predicate, inclusive));
  7184. };
  7185. }
  7186. var TakeWhileOperator = (function () {
  7187. function TakeWhileOperator(predicate, inclusive) {
  7188. this.predicate = predicate;
  7189. this.inclusive = inclusive;
  7190. }
  7191. TakeWhileOperator.prototype.call = function (subscriber, source) {
  7192. return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));
  7193. };
  7194. return TakeWhileOperator;
  7195. }());
  7196. var TakeWhileSubscriber = (function (_super) {
  7197. __extends(TakeWhileSubscriber, _super);
  7198. function TakeWhileSubscriber(destination, predicate, inclusive) {
  7199. var _this = _super.call(this, destination) || this;
  7200. _this.predicate = predicate;
  7201. _this.inclusive = inclusive;
  7202. _this.index = 0;
  7203. return _this;
  7204. }
  7205. TakeWhileSubscriber.prototype._next = function (value) {
  7206. var destination = this.destination;
  7207. var result;
  7208. try {
  7209. result = this.predicate(value, this.index++);
  7210. }
  7211. catch (err) {
  7212. destination.error(err);
  7213. return;
  7214. }
  7215. this.nextOrComplete(value, result);
  7216. };
  7217. TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {
  7218. var destination = this.destination;
  7219. if (Boolean(predicateResult)) {
  7220. destination.next(value);
  7221. }
  7222. else {
  7223. if (this.inclusive) {
  7224. destination.next(value);
  7225. }
  7226. destination.complete();
  7227. }
  7228. };
  7229. return TakeWhileSubscriber;
  7230. }(Subscriber));
  7231. function tap(nextOrObserver, error, complete) {
  7232. return function tapOperatorFunction(source) {
  7233. return source.lift(new DoOperator(nextOrObserver, error, complete));
  7234. };
  7235. }
  7236. var DoOperator = (function () {
  7237. function DoOperator(nextOrObserver, error, complete) {
  7238. this.nextOrObserver = nextOrObserver;
  7239. this.error = error;
  7240. this.complete = complete;
  7241. }
  7242. DoOperator.prototype.call = function (subscriber, source) {
  7243. return source.subscribe(new TapSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
  7244. };
  7245. return DoOperator;
  7246. }());
  7247. var TapSubscriber = (function (_super) {
  7248. __extends(TapSubscriber, _super);
  7249. function TapSubscriber(destination, observerOrNext, error, complete) {
  7250. var _this = _super.call(this, destination) || this;
  7251. _this._tapNext = noop;
  7252. _this._tapError = noop;
  7253. _this._tapComplete = noop;
  7254. _this._tapError = error || noop;
  7255. _this._tapComplete = complete || noop;
  7256. if (isFunction(observerOrNext)) {
  7257. _this._context = _this;
  7258. _this._tapNext = observerOrNext;
  7259. }
  7260. else if (observerOrNext) {
  7261. _this._context = observerOrNext;
  7262. _this._tapNext = observerOrNext.next || noop;
  7263. _this._tapError = observerOrNext.error || noop;
  7264. _this._tapComplete = observerOrNext.complete || noop;
  7265. }
  7266. return _this;
  7267. }
  7268. TapSubscriber.prototype._next = function (value) {
  7269. try {
  7270. this._tapNext.call(this._context, value);
  7271. }
  7272. catch (err) {
  7273. this.destination.error(err);
  7274. return;
  7275. }
  7276. this.destination.next(value);
  7277. };
  7278. TapSubscriber.prototype._error = function (err) {
  7279. try {
  7280. this._tapError.call(this._context, err);
  7281. }
  7282. catch (err) {
  7283. this.destination.error(err);
  7284. return;
  7285. }
  7286. this.destination.error(err);
  7287. };
  7288. TapSubscriber.prototype._complete = function () {
  7289. try {
  7290. this._tapComplete.call(this._context);
  7291. }
  7292. catch (err) {
  7293. this.destination.error(err);
  7294. return;
  7295. }
  7296. return this.destination.complete();
  7297. };
  7298. return TapSubscriber;
  7299. }(Subscriber));
  7300. function throttleTime(duration, scheduler, config) {
  7301. if (scheduler === void 0) { scheduler = async; }
  7302. if (config === void 0) { config = defaultThrottleConfig; }
  7303. return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
  7304. }
  7305. var ThrottleTimeOperator = (function () {
  7306. function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
  7307. this.duration = duration;
  7308. this.scheduler = scheduler;
  7309. this.leading = leading;
  7310. this.trailing = trailing;
  7311. }
  7312. ThrottleTimeOperator.prototype.call = function (subscriber, source) {
  7313. return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
  7314. };
  7315. return ThrottleTimeOperator;
  7316. }());
  7317. var ThrottleTimeSubscriber = (function (_super) {
  7318. __extends(ThrottleTimeSubscriber, _super);
  7319. function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
  7320. var _this = _super.call(this, destination) || this;
  7321. _this.duration = duration;
  7322. _this.scheduler = scheduler;
  7323. _this.leading = leading;
  7324. _this.trailing = trailing;
  7325. _this._hasTrailingValue = false;
  7326. _this._trailingValue = null;
  7327. return _this;
  7328. }
  7329. ThrottleTimeSubscriber.prototype._next = function (value) {
  7330. if (this.throttled) {
  7331. if (this.trailing) {
  7332. this._trailingValue = value;
  7333. this._hasTrailingValue = true;
  7334. }
  7335. }
  7336. else {
  7337. this.add(this.throttled = this.scheduler.schedule(dispatchNext$3, this.duration, { subscriber: this }));
  7338. if (this.leading) {
  7339. this.destination.next(value);
  7340. }
  7341. else if (this.trailing) {
  7342. this._trailingValue = value;
  7343. this._hasTrailingValue = true;
  7344. }
  7345. }
  7346. };
  7347. ThrottleTimeSubscriber.prototype._complete = function () {
  7348. if (this._hasTrailingValue) {
  7349. this.destination.next(this._trailingValue);
  7350. this.destination.complete();
  7351. }
  7352. else {
  7353. this.destination.complete();
  7354. }
  7355. };
  7356. ThrottleTimeSubscriber.prototype.clearThrottle = function () {
  7357. var throttled = this.throttled;
  7358. if (throttled) {
  7359. if (this.trailing && this._hasTrailingValue) {
  7360. this.destination.next(this._trailingValue);
  7361. this._trailingValue = null;
  7362. this._hasTrailingValue = false;
  7363. }
  7364. throttled.unsubscribe();
  7365. this.remove(throttled);
  7366. this.throttled = null;
  7367. }
  7368. };
  7369. return ThrottleTimeSubscriber;
  7370. }(Subscriber));
  7371. function dispatchNext$3(arg) {
  7372. var subscriber = arg.subscriber;
  7373. subscriber.clearThrottle();
  7374. }
  7375. function timeoutWith(due, withObservable, scheduler) {
  7376. if (scheduler === void 0) { scheduler = async; }
  7377. return function (source) {
  7378. var absoluteTimeout = isDate(due);
  7379. var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
  7380. return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
  7381. };
  7382. }
  7383. var TimeoutWithOperator = (function () {
  7384. function TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler) {
  7385. this.waitFor = waitFor;
  7386. this.absoluteTimeout = absoluteTimeout;
  7387. this.withObservable = withObservable;
  7388. this.scheduler = scheduler;
  7389. }
  7390. TimeoutWithOperator.prototype.call = function (subscriber, source) {
  7391. return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
  7392. };
  7393. return TimeoutWithOperator;
  7394. }());
  7395. var TimeoutWithSubscriber = (function (_super) {
  7396. __extends(TimeoutWithSubscriber, _super);
  7397. function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
  7398. var _this = _super.call(this, destination) || this;
  7399. _this.absoluteTimeout = absoluteTimeout;
  7400. _this.waitFor = waitFor;
  7401. _this.withObservable = withObservable;
  7402. _this.scheduler = scheduler;
  7403. _this.action = null;
  7404. _this.scheduleTimeout();
  7405. return _this;
  7406. }
  7407. TimeoutWithSubscriber.dispatchTimeout = function (subscriber) {
  7408. var withObservable = subscriber.withObservable;
  7409. subscriber._unsubscribeAndRecycle();
  7410. subscriber.add(subscribeToResult(subscriber, withObservable));
  7411. };
  7412. TimeoutWithSubscriber.prototype.scheduleTimeout = function () {
  7413. var action = this.action;
  7414. if (action) {
  7415. this.action = action.schedule(this, this.waitFor);
  7416. }
  7417. else {
  7418. this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
  7419. }
  7420. };
  7421. TimeoutWithSubscriber.prototype._next = function (value) {
  7422. if (!this.absoluteTimeout) {
  7423. this.scheduleTimeout();
  7424. }
  7425. _super.prototype._next.call(this, value);
  7426. };
  7427. TimeoutWithSubscriber.prototype._unsubscribe = function () {
  7428. this.action = null;
  7429. this.scheduler = null;
  7430. this.withObservable = null;
  7431. };
  7432. return TimeoutWithSubscriber;
  7433. }(OuterSubscriber));
  7434. function timeout(due, scheduler) {
  7435. if (scheduler === void 0) { scheduler = async; }
  7436. return timeoutWith(due, throwError(new TimeoutError()), scheduler);
  7437. }
  7438. function toArrayReducer(arr, item, index) {
  7439. if (index === 0) {
  7440. return [item];
  7441. }
  7442. arr.push(item);
  7443. return arr;
  7444. }
  7445. function toArray() {
  7446. return reduce(toArrayReducer, []);
  7447. }
  7448. function window$1(windowBoundaries) {
  7449. return function windowOperatorFunction(source) {
  7450. return source.lift(new WindowOperator(windowBoundaries));
  7451. };
  7452. }
  7453. var WindowOperator = (function () {
  7454. function WindowOperator(windowBoundaries) {
  7455. this.windowBoundaries = windowBoundaries;
  7456. }
  7457. WindowOperator.prototype.call = function (subscriber, source) {
  7458. var windowSubscriber = new WindowSubscriber(subscriber);
  7459. var sourceSubscription = source.subscribe(windowSubscriber);
  7460. if (!sourceSubscription.closed) {
  7461. windowSubscriber.add(subscribeToResult(windowSubscriber, this.windowBoundaries));
  7462. }
  7463. return sourceSubscription;
  7464. };
  7465. return WindowOperator;
  7466. }());
  7467. var WindowSubscriber = (function (_super) {
  7468. __extends(WindowSubscriber, _super);
  7469. function WindowSubscriber(destination) {
  7470. var _this = _super.call(this, destination) || this;
  7471. _this.window = new Subject();
  7472. destination.next(_this.window);
  7473. return _this;
  7474. }
  7475. WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  7476. this.openWindow();
  7477. };
  7478. WindowSubscriber.prototype.notifyError = function (error, innerSub) {
  7479. this._error(error);
  7480. };
  7481. WindowSubscriber.prototype.notifyComplete = function (innerSub) {
  7482. this._complete();
  7483. };
  7484. WindowSubscriber.prototype._next = function (value) {
  7485. this.window.next(value);
  7486. };
  7487. WindowSubscriber.prototype._error = function (err) {
  7488. this.window.error(err);
  7489. this.destination.error(err);
  7490. };
  7491. WindowSubscriber.prototype._complete = function () {
  7492. this.window.complete();
  7493. this.destination.complete();
  7494. };
  7495. WindowSubscriber.prototype._unsubscribe = function () {
  7496. this.window = null;
  7497. };
  7498. WindowSubscriber.prototype.openWindow = function () {
  7499. var prevWindow = this.window;
  7500. if (prevWindow) {
  7501. prevWindow.complete();
  7502. }
  7503. var destination = this.destination;
  7504. var newWindow = this.window = new Subject();
  7505. destination.next(newWindow);
  7506. };
  7507. return WindowSubscriber;
  7508. }(OuterSubscriber));
  7509. function windowCount(windowSize, startWindowEvery) {
  7510. if (startWindowEvery === void 0) { startWindowEvery = 0; }
  7511. return function windowCountOperatorFunction(source) {
  7512. return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
  7513. };
  7514. }
  7515. var WindowCountOperator = (function () {
  7516. function WindowCountOperator(windowSize, startWindowEvery) {
  7517. this.windowSize = windowSize;
  7518. this.startWindowEvery = startWindowEvery;
  7519. }
  7520. WindowCountOperator.prototype.call = function (subscriber, source) {
  7521. return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
  7522. };
  7523. return WindowCountOperator;
  7524. }());
  7525. var WindowCountSubscriber = (function (_super) {
  7526. __extends(WindowCountSubscriber, _super);
  7527. function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
  7528. var _this = _super.call(this, destination) || this;
  7529. _this.destination = destination;
  7530. _this.windowSize = windowSize;
  7531. _this.startWindowEvery = startWindowEvery;
  7532. _this.windows = [new Subject()];
  7533. _this.count = 0;
  7534. destination.next(_this.windows[0]);
  7535. return _this;
  7536. }
  7537. WindowCountSubscriber.prototype._next = function (value) {
  7538. var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
  7539. var destination = this.destination;
  7540. var windowSize = this.windowSize;
  7541. var windows = this.windows;
  7542. var len = windows.length;
  7543. for (var i = 0; i < len && !this.closed; i++) {
  7544. windows[i].next(value);
  7545. }
  7546. var c = this.count - windowSize + 1;
  7547. if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
  7548. windows.shift().complete();
  7549. }
  7550. if (++this.count % startWindowEvery === 0 && !this.closed) {
  7551. var window_1 = new Subject();
  7552. windows.push(window_1);
  7553. destination.next(window_1);
  7554. }
  7555. };
  7556. WindowCountSubscriber.prototype._error = function (err) {
  7557. var windows = this.windows;
  7558. if (windows) {
  7559. while (windows.length > 0 && !this.closed) {
  7560. windows.shift().error(err);
  7561. }
  7562. }
  7563. this.destination.error(err);
  7564. };
  7565. WindowCountSubscriber.prototype._complete = function () {
  7566. var windows = this.windows;
  7567. if (windows) {
  7568. while (windows.length > 0 && !this.closed) {
  7569. windows.shift().complete();
  7570. }
  7571. }
  7572. this.destination.complete();
  7573. };
  7574. WindowCountSubscriber.prototype._unsubscribe = function () {
  7575. this.count = 0;
  7576. this.windows = null;
  7577. };
  7578. return WindowCountSubscriber;
  7579. }(Subscriber));
  7580. function windowTime(windowTimeSpan) {
  7581. var scheduler = async;
  7582. var windowCreationInterval = null;
  7583. var maxWindowSize = Number.POSITIVE_INFINITY;
  7584. if (isScheduler(arguments[3])) {
  7585. scheduler = arguments[3];
  7586. }
  7587. if (isScheduler(arguments[2])) {
  7588. scheduler = arguments[2];
  7589. }
  7590. else if (isNumeric(arguments[2])) {
  7591. maxWindowSize = arguments[2];
  7592. }
  7593. if (isScheduler(arguments[1])) {
  7594. scheduler = arguments[1];
  7595. }
  7596. else if (isNumeric(arguments[1])) {
  7597. windowCreationInterval = arguments[1];
  7598. }
  7599. return function windowTimeOperatorFunction(source) {
  7600. return source.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler));
  7601. };
  7602. }
  7603. var WindowTimeOperator = (function () {
  7604. function WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
  7605. this.windowTimeSpan = windowTimeSpan;
  7606. this.windowCreationInterval = windowCreationInterval;
  7607. this.maxWindowSize = maxWindowSize;
  7608. this.scheduler = scheduler;
  7609. }
  7610. WindowTimeOperator.prototype.call = function (subscriber, source) {
  7611. return source.subscribe(new WindowTimeSubscriber(subscriber, this.windowTimeSpan, this.windowCreationInterval, this.maxWindowSize, this.scheduler));
  7612. };
  7613. return WindowTimeOperator;
  7614. }());
  7615. var CountedSubject = (function (_super) {
  7616. __extends(CountedSubject, _super);
  7617. function CountedSubject() {
  7618. var _this = _super !== null && _super.apply(this, arguments) || this;
  7619. _this._numberOfNextedValues = 0;
  7620. return _this;
  7621. }
  7622. CountedSubject.prototype.next = function (value) {
  7623. this._numberOfNextedValues++;
  7624. _super.prototype.next.call(this, value);
  7625. };
  7626. Object.defineProperty(CountedSubject.prototype, "numberOfNextedValues", {
  7627. get: function () {
  7628. return this._numberOfNextedValues;
  7629. },
  7630. enumerable: true,
  7631. configurable: true
  7632. });
  7633. return CountedSubject;
  7634. }(Subject));
  7635. var WindowTimeSubscriber = (function (_super) {
  7636. __extends(WindowTimeSubscriber, _super);
  7637. function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
  7638. var _this = _super.call(this, destination) || this;
  7639. _this.destination = destination;
  7640. _this.windowTimeSpan = windowTimeSpan;
  7641. _this.windowCreationInterval = windowCreationInterval;
  7642. _this.maxWindowSize = maxWindowSize;
  7643. _this.scheduler = scheduler;
  7644. _this.windows = [];
  7645. var window = _this.openWindow();
  7646. if (windowCreationInterval !== null && windowCreationInterval >= 0) {
  7647. var closeState = { subscriber: _this, window: window, context: null };
  7648. var creationState = { windowTimeSpan: windowTimeSpan, windowCreationInterval: windowCreationInterval, subscriber: _this, scheduler: scheduler };
  7649. _this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState));
  7650. _this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState));
  7651. }
  7652. else {
  7653. var timeSpanOnlyState = { subscriber: _this, window: window, windowTimeSpan: windowTimeSpan };
  7654. _this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState));
  7655. }
  7656. return _this;
  7657. }
  7658. WindowTimeSubscriber.prototype._next = function (value) {
  7659. var windows = this.windows;
  7660. var len = windows.length;
  7661. for (var i = 0; i < len; i++) {
  7662. var window_1 = windows[i];
  7663. if (!window_1.closed) {
  7664. window_1.next(value);
  7665. if (window_1.numberOfNextedValues >= this.maxWindowSize) {
  7666. this.closeWindow(window_1);
  7667. }
  7668. }
  7669. }
  7670. };
  7671. WindowTimeSubscriber.prototype._error = function (err) {
  7672. var windows = this.windows;
  7673. while (windows.length > 0) {
  7674. windows.shift().error(err);
  7675. }
  7676. this.destination.error(err);
  7677. };
  7678. WindowTimeSubscriber.prototype._complete = function () {
  7679. var windows = this.windows;
  7680. while (windows.length > 0) {
  7681. var window_2 = windows.shift();
  7682. if (!window_2.closed) {
  7683. window_2.complete();
  7684. }
  7685. }
  7686. this.destination.complete();
  7687. };
  7688. WindowTimeSubscriber.prototype.openWindow = function () {
  7689. var window = new CountedSubject();
  7690. this.windows.push(window);
  7691. var destination = this.destination;
  7692. destination.next(window);
  7693. return window;
  7694. };
  7695. WindowTimeSubscriber.prototype.closeWindow = function (window) {
  7696. window.complete();
  7697. var windows = this.windows;
  7698. windows.splice(windows.indexOf(window), 1);
  7699. };
  7700. return WindowTimeSubscriber;
  7701. }(Subscriber));
  7702. function dispatchWindowTimeSpanOnly(state) {
  7703. var subscriber = state.subscriber, windowTimeSpan = state.windowTimeSpan, window = state.window;
  7704. if (window) {
  7705. subscriber.closeWindow(window);
  7706. }
  7707. state.window = subscriber.openWindow();
  7708. this.schedule(state, windowTimeSpan);
  7709. }
  7710. function dispatchWindowCreation(state) {
  7711. var windowTimeSpan = state.windowTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler, windowCreationInterval = state.windowCreationInterval;
  7712. var window = subscriber.openWindow();
  7713. var action = this;
  7714. var context = { action: action, subscription: null };
  7715. var timeSpanState = { subscriber: subscriber, window: window, context: context };
  7716. context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState);
  7717. action.add(context.subscription);
  7718. action.schedule(state, windowCreationInterval);
  7719. }
  7720. function dispatchWindowClose(state) {
  7721. var subscriber = state.subscriber, window = state.window, context = state.context;
  7722. if (context && context.action && context.subscription) {
  7723. context.action.remove(context.subscription);
  7724. }
  7725. subscriber.closeWindow(window);
  7726. }
  7727. function windowToggle(openings, closingSelector) {
  7728. return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
  7729. }
  7730. var WindowToggleOperator = (function () {
  7731. function WindowToggleOperator(openings, closingSelector) {
  7732. this.openings = openings;
  7733. this.closingSelector = closingSelector;
  7734. }
  7735. WindowToggleOperator.prototype.call = function (subscriber, source) {
  7736. return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
  7737. };
  7738. return WindowToggleOperator;
  7739. }());
  7740. var WindowToggleSubscriber = (function (_super) {
  7741. __extends(WindowToggleSubscriber, _super);
  7742. function WindowToggleSubscriber(destination, openings, closingSelector) {
  7743. var _this = _super.call(this, destination) || this;
  7744. _this.openings = openings;
  7745. _this.closingSelector = closingSelector;
  7746. _this.contexts = [];
  7747. _this.add(_this.openSubscription = subscribeToResult(_this, openings, openings));
  7748. return _this;
  7749. }
  7750. WindowToggleSubscriber.prototype._next = function (value) {
  7751. var contexts = this.contexts;
  7752. if (contexts) {
  7753. var len = contexts.length;
  7754. for (var i = 0; i < len; i++) {
  7755. contexts[i].window.next(value);
  7756. }
  7757. }
  7758. };
  7759. WindowToggleSubscriber.prototype._error = function (err) {
  7760. var contexts = this.contexts;
  7761. this.contexts = null;
  7762. if (contexts) {
  7763. var len = contexts.length;
  7764. var index = -1;
  7765. while (++index < len) {
  7766. var context_1 = contexts[index];
  7767. context_1.window.error(err);
  7768. context_1.subscription.unsubscribe();
  7769. }
  7770. }
  7771. _super.prototype._error.call(this, err);
  7772. };
  7773. WindowToggleSubscriber.prototype._complete = function () {
  7774. var contexts = this.contexts;
  7775. this.contexts = null;
  7776. if (contexts) {
  7777. var len = contexts.length;
  7778. var index = -1;
  7779. while (++index < len) {
  7780. var context_2 = contexts[index];
  7781. context_2.window.complete();
  7782. context_2.subscription.unsubscribe();
  7783. }
  7784. }
  7785. _super.prototype._complete.call(this);
  7786. };
  7787. WindowToggleSubscriber.prototype._unsubscribe = function () {
  7788. var contexts = this.contexts;
  7789. this.contexts = null;
  7790. if (contexts) {
  7791. var len = contexts.length;
  7792. var index = -1;
  7793. while (++index < len) {
  7794. var context_3 = contexts[index];
  7795. context_3.window.unsubscribe();
  7796. context_3.subscription.unsubscribe();
  7797. }
  7798. }
  7799. };
  7800. WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  7801. if (outerValue === this.openings) {
  7802. var closingNotifier = void 0;
  7803. try {
  7804. var closingSelector = this.closingSelector;
  7805. closingNotifier = closingSelector(innerValue);
  7806. }
  7807. catch (e) {
  7808. return this.error(e);
  7809. }
  7810. var window_1 = new Subject();
  7811. var subscription = new Subscription();
  7812. var context_4 = { window: window_1, subscription: subscription };
  7813. this.contexts.push(context_4);
  7814. var innerSubscription = subscribeToResult(this, closingNotifier, context_4);
  7815. if (innerSubscription.closed) {
  7816. this.closeWindow(this.contexts.length - 1);
  7817. }
  7818. else {
  7819. innerSubscription.context = context_4;
  7820. subscription.add(innerSubscription);
  7821. }
  7822. this.destination.next(window_1);
  7823. }
  7824. else {
  7825. this.closeWindow(this.contexts.indexOf(outerValue));
  7826. }
  7827. };
  7828. WindowToggleSubscriber.prototype.notifyError = function (err) {
  7829. this.error(err);
  7830. };
  7831. WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
  7832. if (inner !== this.openSubscription) {
  7833. this.closeWindow(this.contexts.indexOf(inner.context));
  7834. }
  7835. };
  7836. WindowToggleSubscriber.prototype.closeWindow = function (index) {
  7837. if (index === -1) {
  7838. return;
  7839. }
  7840. var contexts = this.contexts;
  7841. var context = contexts[index];
  7842. var window = context.window, subscription = context.subscription;
  7843. contexts.splice(index, 1);
  7844. window.complete();
  7845. subscription.unsubscribe();
  7846. };
  7847. return WindowToggleSubscriber;
  7848. }(OuterSubscriber));
  7849. function windowWhen(closingSelector) {
  7850. return function windowWhenOperatorFunction(source) {
  7851. return source.lift(new WindowOperator$1(closingSelector));
  7852. };
  7853. }
  7854. var WindowOperator$1 = (function () {
  7855. function WindowOperator(closingSelector) {
  7856. this.closingSelector = closingSelector;
  7857. }
  7858. WindowOperator.prototype.call = function (subscriber, source) {
  7859. return source.subscribe(new WindowSubscriber$1(subscriber, this.closingSelector));
  7860. };
  7861. return WindowOperator;
  7862. }());
  7863. var WindowSubscriber$1 = (function (_super) {
  7864. __extends(WindowSubscriber, _super);
  7865. function WindowSubscriber(destination, closingSelector) {
  7866. var _this = _super.call(this, destination) || this;
  7867. _this.destination = destination;
  7868. _this.closingSelector = closingSelector;
  7869. _this.openWindow();
  7870. return _this;
  7871. }
  7872. WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  7873. this.openWindow(innerSub);
  7874. };
  7875. WindowSubscriber.prototype.notifyError = function (error, innerSub) {
  7876. this._error(error);
  7877. };
  7878. WindowSubscriber.prototype.notifyComplete = function (innerSub) {
  7879. this.openWindow(innerSub);
  7880. };
  7881. WindowSubscriber.prototype._next = function (value) {
  7882. this.window.next(value);
  7883. };
  7884. WindowSubscriber.prototype._error = function (err) {
  7885. this.window.error(err);
  7886. this.destination.error(err);
  7887. this.unsubscribeClosingNotification();
  7888. };
  7889. WindowSubscriber.prototype._complete = function () {
  7890. this.window.complete();
  7891. this.destination.complete();
  7892. this.unsubscribeClosingNotification();
  7893. };
  7894. WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
  7895. if (this.closingNotification) {
  7896. this.closingNotification.unsubscribe();
  7897. }
  7898. };
  7899. WindowSubscriber.prototype.openWindow = function (innerSub) {
  7900. if (innerSub === void 0) { innerSub = null; }
  7901. if (innerSub) {
  7902. this.remove(innerSub);
  7903. innerSub.unsubscribe();
  7904. }
  7905. var prevWindow = this.window;
  7906. if (prevWindow) {
  7907. prevWindow.complete();
  7908. }
  7909. var window = this.window = new Subject();
  7910. this.destination.next(window);
  7911. var closingNotifier;
  7912. try {
  7913. var closingSelector = this.closingSelector;
  7914. closingNotifier = closingSelector();
  7915. }
  7916. catch (e) {
  7917. this.destination.error(e);
  7918. this.window.error(e);
  7919. return;
  7920. }
  7921. this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
  7922. };
  7923. return WindowSubscriber;
  7924. }(OuterSubscriber));
  7925. function withLatestFrom() {
  7926. var args = [];
  7927. for (var _i = 0; _i < arguments.length; _i++) {
  7928. args[_i] = arguments[_i];
  7929. }
  7930. return function (source) {
  7931. var project;
  7932. if (typeof args[args.length - 1] === 'function') {
  7933. project = args.pop();
  7934. }
  7935. var observables = args;
  7936. return source.lift(new WithLatestFromOperator(observables, project));
  7937. };
  7938. }
  7939. var WithLatestFromOperator = (function () {
  7940. function WithLatestFromOperator(observables, project) {
  7941. this.observables = observables;
  7942. this.project = project;
  7943. }
  7944. WithLatestFromOperator.prototype.call = function (subscriber, source) {
  7945. return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
  7946. };
  7947. return WithLatestFromOperator;
  7948. }());
  7949. var WithLatestFromSubscriber = (function (_super) {
  7950. __extends(WithLatestFromSubscriber, _super);
  7951. function WithLatestFromSubscriber(destination, observables, project) {
  7952. var _this = _super.call(this, destination) || this;
  7953. _this.observables = observables;
  7954. _this.project = project;
  7955. _this.toRespond = [];
  7956. var len = observables.length;
  7957. _this.values = new Array(len);
  7958. for (var i = 0; i < len; i++) {
  7959. _this.toRespond.push(i);
  7960. }
  7961. for (var i = 0; i < len; i++) {
  7962. var observable = observables[i];
  7963. _this.add(subscribeToResult(_this, observable, observable, i));
  7964. }
  7965. return _this;
  7966. }
  7967. WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  7968. this.values[outerIndex] = innerValue;
  7969. var toRespond = this.toRespond;
  7970. if (toRespond.length > 0) {
  7971. var found = toRespond.indexOf(outerIndex);
  7972. if (found !== -1) {
  7973. toRespond.splice(found, 1);
  7974. }
  7975. }
  7976. };
  7977. WithLatestFromSubscriber.prototype.notifyComplete = function () {
  7978. };
  7979. WithLatestFromSubscriber.prototype._next = function (value) {
  7980. if (this.toRespond.length === 0) {
  7981. var args = [value].concat(this.values);
  7982. if (this.project) {
  7983. this._tryProject(args);
  7984. }
  7985. else {
  7986. this.destination.next(args);
  7987. }
  7988. }
  7989. };
  7990. WithLatestFromSubscriber.prototype._tryProject = function (args) {
  7991. var result;
  7992. try {
  7993. result = this.project.apply(this, args);
  7994. }
  7995. catch (err) {
  7996. this.destination.error(err);
  7997. return;
  7998. }
  7999. this.destination.next(result);
  8000. };
  8001. return WithLatestFromSubscriber;
  8002. }(OuterSubscriber));
  8003. function zip$1() {
  8004. var observables = [];
  8005. for (var _i = 0; _i < arguments.length; _i++) {
  8006. observables[_i] = arguments[_i];
  8007. }
  8008. return function zipOperatorFunction(source) {
  8009. return source.lift.call(zip.apply(void 0, [source].concat(observables)));
  8010. };
  8011. }
  8012. function zipAll(project) {
  8013. return function (source) { return source.lift(new ZipOperator(project)); };
  8014. }
  8015. var _operators = /*#__PURE__*/Object.freeze({
  8016. audit: audit,
  8017. auditTime: auditTime,
  8018. buffer: buffer,
  8019. bufferCount: bufferCount,
  8020. bufferTime: bufferTime,
  8021. bufferToggle: bufferToggle,
  8022. bufferWhen: bufferWhen,
  8023. catchError: catchError,
  8024. combineAll: combineAll,
  8025. combineLatest: combineLatest$1,
  8026. concat: concat$1,
  8027. concatAll: concatAll,
  8028. concatMap: concatMap,
  8029. concatMapTo: concatMapTo,
  8030. count: count,
  8031. debounce: debounce,
  8032. debounceTime: debounceTime,
  8033. defaultIfEmpty: defaultIfEmpty,
  8034. delay: delay,
  8035. delayWhen: delayWhen,
  8036. dematerialize: dematerialize,
  8037. distinct: distinct,
  8038. distinctUntilChanged: distinctUntilChanged,
  8039. distinctUntilKeyChanged: distinctUntilKeyChanged,
  8040. elementAt: elementAt,
  8041. endWith: endWith,
  8042. every: every,
  8043. exhaust: exhaust,
  8044. exhaustMap: exhaustMap,
  8045. expand: expand,
  8046. filter: filter,
  8047. finalize: finalize,
  8048. find: find,
  8049. findIndex: findIndex,
  8050. first: first,
  8051. groupBy: groupBy,
  8052. ignoreElements: ignoreElements,
  8053. isEmpty: isEmpty,
  8054. last: last,
  8055. map: map,
  8056. mapTo: mapTo,
  8057. materialize: materialize,
  8058. max: max,
  8059. merge: merge$1,
  8060. mergeAll: mergeAll,
  8061. mergeMap: mergeMap,
  8062. flatMap: mergeMap,
  8063. mergeMapTo: mergeMapTo,
  8064. mergeScan: mergeScan,
  8065. min: min,
  8066. multicast: multicast,
  8067. observeOn: observeOn,
  8068. onErrorResumeNext: onErrorResumeNext$1,
  8069. pairwise: pairwise,
  8070. partition: partition$1,
  8071. pluck: pluck,
  8072. publish: publish,
  8073. publishBehavior: publishBehavior,
  8074. publishLast: publishLast,
  8075. publishReplay: publishReplay,
  8076. race: race$1,
  8077. reduce: reduce,
  8078. repeat: repeat,
  8079. repeatWhen: repeatWhen,
  8080. retry: retry,
  8081. retryWhen: retryWhen,
  8082. refCount: refCount,
  8083. sample: sample,
  8084. sampleTime: sampleTime,
  8085. scan: scan,
  8086. sequenceEqual: sequenceEqual,
  8087. share: share,
  8088. shareReplay: shareReplay,
  8089. single: single,
  8090. skip: skip,
  8091. skipLast: skipLast,
  8092. skipUntil: skipUntil,
  8093. skipWhile: skipWhile,
  8094. startWith: startWith,
  8095. subscribeOn: subscribeOn,
  8096. switchAll: switchAll,
  8097. switchMap: switchMap,
  8098. switchMapTo: switchMapTo,
  8099. take: take,
  8100. takeLast: takeLast,
  8101. takeUntil: takeUntil,
  8102. takeWhile: takeWhile,
  8103. tap: tap,
  8104. throttle: throttle,
  8105. throttleTime: throttleTime,
  8106. throwIfEmpty: throwIfEmpty,
  8107. timeInterval: timeInterval,
  8108. timeout: timeout,
  8109. timeoutWith: timeoutWith,
  8110. timestamp: timestamp,
  8111. toArray: toArray,
  8112. window: window$1,
  8113. windowCount: windowCount,
  8114. windowTime: windowTime,
  8115. windowToggle: windowToggle,
  8116. windowWhen: windowWhen,
  8117. withLatestFrom: withLatestFrom,
  8118. zip: zip$1,
  8119. zipAll: zipAll
  8120. });
  8121. function buffer$1(closingNotifier) {
  8122. return buffer(closingNotifier)(this);
  8123. }
  8124. Observable.prototype.buffer = buffer$1;
  8125. function bufferCount$1(bufferSize, startBufferEvery) {
  8126. if (startBufferEvery === void 0) { startBufferEvery = null; }
  8127. return bufferCount(bufferSize, startBufferEvery)(this);
  8128. }
  8129. Observable.prototype.bufferCount = bufferCount$1;
  8130. function bufferTime$1(bufferTimeSpan) {
  8131. var length = arguments.length;
  8132. var scheduler = async;
  8133. if (isScheduler(arguments[arguments.length - 1])) {
  8134. scheduler = arguments[arguments.length - 1];
  8135. length--;
  8136. }
  8137. var bufferCreationInterval = null;
  8138. if (length >= 2) {
  8139. bufferCreationInterval = arguments[1];
  8140. }
  8141. var maxBufferSize = Number.POSITIVE_INFINITY;
  8142. if (length >= 3) {
  8143. maxBufferSize = arguments[2];
  8144. }
  8145. return bufferTime(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler)(this);
  8146. }
  8147. Observable.prototype.bufferTime = bufferTime$1;
  8148. function bufferToggle$1(openings, closingSelector) {
  8149. return bufferToggle(openings, closingSelector)(this);
  8150. }
  8151. Observable.prototype.bufferToggle = bufferToggle$1;
  8152. function bufferWhen$1(closingSelector) {
  8153. return bufferWhen(closingSelector)(this);
  8154. }
  8155. Observable.prototype.bufferWhen = bufferWhen$1;
  8156. function _catch(selector) {
  8157. return catchError(selector)(this);
  8158. }
  8159. Observable.prototype.catch = _catch;
  8160. Observable.prototype._catch = _catch;
  8161. function combineAll$1(project) {
  8162. return combineAll(project)(this);
  8163. }
  8164. Observable.prototype.combineAll = combineAll$1;
  8165. function combineLatest$2() {
  8166. var observables = [];
  8167. for (var _i = 0; _i < arguments.length; _i++) {
  8168. observables[_i] = arguments[_i];
  8169. }
  8170. var project = null;
  8171. if (typeof observables[observables.length - 1] === 'function') {
  8172. project = observables.pop();
  8173. }
  8174. if (observables.length === 1 && isArray(observables[0])) {
  8175. observables = observables[0].slice();
  8176. }
  8177. return this.lift.call(of.apply(void 0, [this].concat(observables)), new CombineLatestOperator(project));
  8178. }
  8179. Observable.prototype.combineLatest = combineLatest$2;
  8180. function concat$2() {
  8181. var observables = [];
  8182. for (var _i = 0; _i < arguments.length; _i++) {
  8183. observables[_i] = arguments[_i];
  8184. }
  8185. return this.lift.call(concat.apply(void 0, [this].concat(observables)));
  8186. }
  8187. Observable.prototype.concat = concat$2;
  8188. function concatAll$1() {
  8189. return concatAll()(this);
  8190. }
  8191. Observable.prototype.concatAll = concatAll$1;
  8192. function concatMap$1(project) {
  8193. return concatMap(project)(this);
  8194. }
  8195. Observable.prototype.concatMap = concatMap$1;
  8196. function concatMapTo$1(innerObservable) {
  8197. return concatMapTo(innerObservable)(this);
  8198. }
  8199. Observable.prototype.concatMapTo = concatMapTo$1;
  8200. function count$1(predicate) {
  8201. return count(predicate)(this);
  8202. }
  8203. Observable.prototype.count = count$1;
  8204. function dematerialize$1() {
  8205. return dematerialize()(this);
  8206. }
  8207. Observable.prototype.dematerialize = dematerialize$1;
  8208. function debounce$1(durationSelector) {
  8209. return debounce(durationSelector)(this);
  8210. }
  8211. Observable.prototype.debounce = debounce$1;
  8212. function debounceTime$1(dueTime, scheduler) {
  8213. if (scheduler === void 0) { scheduler = async; }
  8214. return debounceTime(dueTime, scheduler)(this);
  8215. }
  8216. Observable.prototype.debounceTime = debounceTime$1;
  8217. function defaultIfEmpty$1(defaultValue) {
  8218. if (defaultValue === void 0) { defaultValue = null; }
  8219. return defaultIfEmpty(defaultValue)(this);
  8220. }
  8221. Observable.prototype.defaultIfEmpty = defaultIfEmpty$1;
  8222. function delay$1(delay$$1, scheduler) {
  8223. if (scheduler === void 0) { scheduler = async; }
  8224. return delay(delay$$1, scheduler)(this);
  8225. }
  8226. Observable.prototype.delay = delay$1;
  8227. function delayWhen$1(delayDurationSelector, subscriptionDelay) {
  8228. return delayWhen(delayDurationSelector, subscriptionDelay)(this);
  8229. }
  8230. Observable.prototype.delayWhen = delayWhen$1;
  8231. function distinct$1(keySelector, flushes) {
  8232. return distinct(keySelector, flushes)(this);
  8233. }
  8234. Observable.prototype.distinct = distinct$1;
  8235. function distinctUntilChanged$1(compare, keySelector) {
  8236. return distinctUntilChanged(compare, keySelector)(this);
  8237. }
  8238. Observable.prototype.distinctUntilChanged = distinctUntilChanged$1;
  8239. function distinctUntilKeyChanged$1(key, compare) {
  8240. return distinctUntilKeyChanged(key, compare)(this);
  8241. }
  8242. Observable.prototype.distinctUntilKeyChanged = distinctUntilKeyChanged$1;
  8243. function _do(nextOrObserver, error, complete) {
  8244. return tap(nextOrObserver, error, complete)(this);
  8245. }
  8246. Observable.prototype.do = _do;
  8247. Observable.prototype._do = _do;
  8248. function exhaust$1() {
  8249. return exhaust()(this);
  8250. }
  8251. Observable.prototype.exhaust = exhaust$1;
  8252. function exhaustMap$1(project) {
  8253. return exhaustMap(project)(this);
  8254. }
  8255. Observable.prototype.exhaustMap = exhaustMap$1;
  8256. function expand$1(project, concurrent, scheduler) {
  8257. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  8258. if (scheduler === void 0) { scheduler = undefined; }
  8259. concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
  8260. return expand(project, concurrent, scheduler)(this);
  8261. }
  8262. Observable.prototype.expand = expand$1;
  8263. function elementAt$1(index, defaultValue) {
  8264. return elementAt.apply(undefined, arguments)(this);
  8265. }
  8266. Observable.prototype.elementAt = elementAt$1;
  8267. function filter$1(predicate, thisArg) {
  8268. return filter(predicate, thisArg)(this);
  8269. }
  8270. Observable.prototype.filter = filter$1;
  8271. function _finally(callback) {
  8272. return finalize(callback)(this);
  8273. }
  8274. Observable.prototype.finally = _finally;
  8275. Observable.prototype._finally = _finally;
  8276. function find$1(predicate, thisArg) {
  8277. return find(predicate, thisArg)(this);
  8278. }
  8279. Observable.prototype.find = find$1;
  8280. function findIndex$1(predicate, thisArg) {
  8281. return findIndex(predicate, thisArg)(this);
  8282. }
  8283. Observable.prototype.findIndex = findIndex$1;
  8284. function first$1() {
  8285. var args = [];
  8286. for (var _i = 0; _i < arguments.length; _i++) {
  8287. args[_i] = arguments[_i];
  8288. }
  8289. return first.apply(void 0, args)(this);
  8290. }
  8291. Observable.prototype.first = first$1;
  8292. function groupBy$1(keySelector, elementSelector, durationSelector, subjectSelector) {
  8293. return groupBy(keySelector, elementSelector, durationSelector, subjectSelector)(this);
  8294. }
  8295. Observable.prototype.groupBy = groupBy$1;
  8296. function ignoreElements$1() {
  8297. return ignoreElements()(this);
  8298. }
  8299. Observable.prototype.ignoreElements = ignoreElements$1;
  8300. function isEmpty$1() {
  8301. return isEmpty()(this);
  8302. }
  8303. Observable.prototype.isEmpty = isEmpty$1;
  8304. function audit$1(durationSelector) {
  8305. return audit(durationSelector)(this);
  8306. }
  8307. Observable.prototype.audit = audit$1;
  8308. function auditTime$1(duration, scheduler) {
  8309. if (scheduler === void 0) { scheduler = async; }
  8310. return auditTime(duration, scheduler)(this);
  8311. }
  8312. Observable.prototype.auditTime = auditTime$1;
  8313. function last$1() {
  8314. var args = [];
  8315. for (var _i = 0; _i < arguments.length; _i++) {
  8316. args[_i] = arguments[_i];
  8317. }
  8318. return last.apply(void 0, args)(this);
  8319. }
  8320. Observable.prototype.last = last$1;
  8321. function letProto(func) {
  8322. return func(this);
  8323. }
  8324. Observable.prototype.let = letProto;
  8325. Observable.prototype.letBind = letProto;
  8326. function every$1(predicate, thisArg) {
  8327. return every(predicate, thisArg)(this);
  8328. }
  8329. Observable.prototype.every = every$1;
  8330. function map$1(project, thisArg) {
  8331. return map(project, thisArg)(this);
  8332. }
  8333. Observable.prototype.map = map$1;
  8334. function mapTo$1(value) {
  8335. return mapTo(value)(this);
  8336. }
  8337. Observable.prototype.mapTo = mapTo$1;
  8338. function materialize$1() {
  8339. return materialize()(this);
  8340. }
  8341. Observable.prototype.materialize = materialize$1;
  8342. function max$1(comparer) {
  8343. return max(comparer)(this);
  8344. }
  8345. Observable.prototype.max = max$1;
  8346. function merge$2() {
  8347. var observables = [];
  8348. for (var _i = 0; _i < arguments.length; _i++) {
  8349. observables[_i] = arguments[_i];
  8350. }
  8351. return this.lift.call(merge.apply(void 0, [this].concat(observables)));
  8352. }
  8353. Observable.prototype.merge = merge$2;
  8354. function mergeAll$1(concurrent) {
  8355. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  8356. return mergeAll(concurrent)(this);
  8357. }
  8358. Observable.prototype.mergeAll = mergeAll$1;
  8359. function mergeMap$1(project, concurrent) {
  8360. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  8361. return mergeMap(project, concurrent)(this);
  8362. }
  8363. Observable.prototype.mergeMap = mergeMap$1;
  8364. Observable.prototype.flatMap = mergeMap$1;
  8365. function mergeMapTo$1(innerObservable, concurrent) {
  8366. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  8367. return mergeMapTo(innerObservable, concurrent)(this);
  8368. }
  8369. Observable.prototype.flatMapTo = mergeMapTo$1;
  8370. Observable.prototype.mergeMapTo = mergeMapTo$1;
  8371. function mergeScan$1(accumulator, seed, concurrent) {
  8372. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  8373. return mergeScan(accumulator, seed, concurrent)(this);
  8374. }
  8375. Observable.prototype.mergeScan = mergeScan$1;
  8376. function min$1(comparer) {
  8377. return min(comparer)(this);
  8378. }
  8379. Observable.prototype.min = min$1;
  8380. function multicast$1(subjectOrSubjectFactory, selector) {
  8381. return multicast(subjectOrSubjectFactory, selector)(this);
  8382. }
  8383. Observable.prototype.multicast = multicast$1;
  8384. function observeOn$1(scheduler, delay$$1) {
  8385. if (delay$$1 === void 0) { delay$$1 = 0; }
  8386. return observeOn(scheduler, delay$$1)(this);
  8387. }
  8388. Observable.prototype.observeOn = observeOn$1;
  8389. function onErrorResumeNext$2() {
  8390. var nextSources = [];
  8391. for (var _i = 0; _i < arguments.length; _i++) {
  8392. nextSources[_i] = arguments[_i];
  8393. }
  8394. return onErrorResumeNext$1.apply(void 0, nextSources)(this);
  8395. }
  8396. Observable.prototype.onErrorResumeNext = onErrorResumeNext$2;
  8397. function pairwise$1() {
  8398. return pairwise()(this);
  8399. }
  8400. Observable.prototype.pairwise = pairwise$1;
  8401. function partition$2(predicate, thisArg) {
  8402. return partition$1(predicate, thisArg)(this);
  8403. }
  8404. Observable.prototype.partition = partition$2;
  8405. function pluck$1() {
  8406. var properties = [];
  8407. for (var _i = 0; _i < arguments.length; _i++) {
  8408. properties[_i] = arguments[_i];
  8409. }
  8410. return pluck.apply(void 0, properties)(this);
  8411. }
  8412. Observable.prototype.pluck = pluck$1;
  8413. function publish$1(selector) {
  8414. return publish(selector)(this);
  8415. }
  8416. Observable.prototype.publish = publish$1;
  8417. function publishBehavior$1(value) {
  8418. return publishBehavior(value)(this);
  8419. }
  8420. Observable.prototype.publishBehavior = publishBehavior$1;
  8421. function publishReplay$1(bufferSize, windowTime$$1, selectorOrScheduler, scheduler) {
  8422. return publishReplay(bufferSize, windowTime$$1, selectorOrScheduler, scheduler)(this);
  8423. }
  8424. Observable.prototype.publishReplay = publishReplay$1;
  8425. function publishLast$1() {
  8426. return publishLast()(this);
  8427. }
  8428. Observable.prototype.publishLast = publishLast$1;
  8429. function race$2() {
  8430. var observables = [];
  8431. for (var _i = 0; _i < arguments.length; _i++) {
  8432. observables[_i] = arguments[_i];
  8433. }
  8434. return race$1.apply(void 0, observables)(this);
  8435. }
  8436. Observable.prototype.race = race$2;
  8437. function reduce$1(accumulator, seed) {
  8438. if (arguments.length >= 2) {
  8439. return reduce(accumulator, seed)(this);
  8440. }
  8441. return reduce(accumulator)(this);
  8442. }
  8443. Observable.prototype.reduce = reduce$1;
  8444. function repeat$1(count$$1) {
  8445. if (count$$1 === void 0) { count$$1 = -1; }
  8446. return repeat(count$$1)(this);
  8447. }
  8448. Observable.prototype.repeat = repeat$1;
  8449. function repeatWhen$1(notifier) {
  8450. return repeatWhen(notifier)(this);
  8451. }
  8452. Observable.prototype.repeatWhen = repeatWhen$1;
  8453. function retry$1(count$$1) {
  8454. if (count$$1 === void 0) { count$$1 = -1; }
  8455. return retry(count$$1)(this);
  8456. }
  8457. Observable.prototype.retry = retry$1;
  8458. function retryWhen$1(notifier) {
  8459. return retryWhen(notifier)(this);
  8460. }
  8461. Observable.prototype.retryWhen = retryWhen$1;
  8462. function sample$1(notifier) {
  8463. return sample(notifier)(this);
  8464. }
  8465. Observable.prototype.sample = sample$1;
  8466. function sampleTime$1(period, scheduler) {
  8467. if (scheduler === void 0) { scheduler = async; }
  8468. return sampleTime(period, scheduler)(this);
  8469. }
  8470. Observable.prototype.sampleTime = sampleTime$1;
  8471. function scan$1(accumulator, seed) {
  8472. if (arguments.length >= 2) {
  8473. return scan(accumulator, seed)(this);
  8474. }
  8475. return scan(accumulator)(this);
  8476. }
  8477. Observable.prototype.scan = scan$1;
  8478. function sequenceEqual$1(compareTo, comparor) {
  8479. return sequenceEqual(compareTo, comparor)(this);
  8480. }
  8481. Observable.prototype.sequenceEqual = sequenceEqual$1;
  8482. function share$1() {
  8483. return share()(this);
  8484. }
  8485. Observable.prototype.share = share$1;
  8486. function shareReplay$1(configOrBufferSize, windowTime$$1, scheduler) {
  8487. if (configOrBufferSize && typeof configOrBufferSize === 'object') {
  8488. return shareReplay(configOrBufferSize)(this);
  8489. }
  8490. return shareReplay(configOrBufferSize, windowTime$$1, scheduler)(this);
  8491. }
  8492. Observable.prototype.shareReplay = shareReplay$1;
  8493. function single$1(predicate) {
  8494. return single(predicate)(this);
  8495. }
  8496. Observable.prototype.single = single$1;
  8497. function skip$1(count$$1) {
  8498. return skip(count$$1)(this);
  8499. }
  8500. Observable.prototype.skip = skip$1;
  8501. function skipLast$1(count$$1) {
  8502. return skipLast(count$$1)(this);
  8503. }
  8504. Observable.prototype.skipLast = skipLast$1;
  8505. function skipUntil$1(notifier) {
  8506. return skipUntil(notifier)(this);
  8507. }
  8508. Observable.prototype.skipUntil = skipUntil$1;
  8509. function skipWhile$1(predicate) {
  8510. return skipWhile(predicate)(this);
  8511. }
  8512. Observable.prototype.skipWhile = skipWhile$1;
  8513. function startWith$1() {
  8514. var array = [];
  8515. for (var _i = 0; _i < arguments.length; _i++) {
  8516. array[_i] = arguments[_i];
  8517. }
  8518. return startWith.apply(void 0, array)(this);
  8519. }
  8520. Observable.prototype.startWith = startWith$1;
  8521. function subscribeOn$1(scheduler, delay$$1) {
  8522. if (delay$$1 === void 0) { delay$$1 = 0; }
  8523. return subscribeOn(scheduler, delay$$1)(this);
  8524. }
  8525. Observable.prototype.subscribeOn = subscribeOn$1;
  8526. function _switch() {
  8527. return switchAll()(this);
  8528. }
  8529. Observable.prototype.switch = _switch;
  8530. Observable.prototype._switch = _switch;
  8531. function switchMap$1(project) {
  8532. return switchMap(project)(this);
  8533. }
  8534. Observable.prototype.switchMap = switchMap$1;
  8535. function switchMapTo$1(innerObservable) {
  8536. return switchMapTo(innerObservable)(this);
  8537. }
  8538. Observable.prototype.switchMapTo = switchMapTo$1;
  8539. function take$1(count$$1) {
  8540. return take(count$$1)(this);
  8541. }
  8542. Observable.prototype.take = take$1;
  8543. function takeLast$1(count$$1) {
  8544. return takeLast(count$$1)(this);
  8545. }
  8546. Observable.prototype.takeLast = takeLast$1;
  8547. function takeUntil$1(notifier) {
  8548. return takeUntil(notifier)(this);
  8549. }
  8550. Observable.prototype.takeUntil = takeUntil$1;
  8551. function takeWhile$1(predicate) {
  8552. return takeWhile(predicate)(this);
  8553. }
  8554. Observable.prototype.takeWhile = takeWhile$1;
  8555. function throttle$1(durationSelector, config$$1) {
  8556. if (config$$1 === void 0) { config$$1 = defaultThrottleConfig; }
  8557. return throttle(durationSelector, config$$1)(this);
  8558. }
  8559. Observable.prototype.throttle = throttle$1;
  8560. function throttleTime$1(duration, scheduler, config$$1) {
  8561. if (scheduler === void 0) { scheduler = async; }
  8562. if (config$$1 === void 0) { config$$1 = defaultThrottleConfig; }
  8563. return throttleTime(duration, scheduler, config$$1)(this);
  8564. }
  8565. Observable.prototype.throttleTime = throttleTime$1;
  8566. function timeInterval$1(scheduler) {
  8567. if (scheduler === void 0) { scheduler = async; }
  8568. return timeInterval(scheduler)(this);
  8569. }
  8570. Observable.prototype.timeInterval = timeInterval$1;
  8571. function timeout$1(due, scheduler) {
  8572. if (scheduler === void 0) { scheduler = async; }
  8573. return timeout(due, scheduler)(this);
  8574. }
  8575. Observable.prototype.timeout = timeout$1;
  8576. function timeoutWith$1(due, withObservable, scheduler) {
  8577. if (scheduler === void 0) { scheduler = async; }
  8578. return timeoutWith(due, withObservable, scheduler)(this);
  8579. }
  8580. Observable.prototype.timeoutWith = timeoutWith$1;
  8581. function timestamp$1(scheduler) {
  8582. if (scheduler === void 0) { scheduler = async; }
  8583. return timestamp(scheduler)(this);
  8584. }
  8585. Observable.prototype.timestamp = timestamp$1;
  8586. function toArray$1() {
  8587. return toArray()(this);
  8588. }
  8589. Observable.prototype.toArray = toArray$1;
  8590. function window$2(windowBoundaries) {
  8591. return window$1(windowBoundaries)(this);
  8592. }
  8593. Observable.prototype.window = window$2;
  8594. function windowCount$1(windowSize, startWindowEvery) {
  8595. if (startWindowEvery === void 0) { startWindowEvery = 0; }
  8596. return windowCount(windowSize, startWindowEvery)(this);
  8597. }
  8598. Observable.prototype.windowCount = windowCount$1;
  8599. function windowTime$1(windowTimeSpan) {
  8600. var scheduler = async;
  8601. var windowCreationInterval = null;
  8602. var maxWindowSize = Number.POSITIVE_INFINITY;
  8603. if (isScheduler(arguments[3])) {
  8604. scheduler = arguments[3];
  8605. }
  8606. if (isScheduler(arguments[2])) {
  8607. scheduler = arguments[2];
  8608. }
  8609. else if (isNumeric(arguments[2])) {
  8610. maxWindowSize = arguments[2];
  8611. }
  8612. if (isScheduler(arguments[1])) {
  8613. scheduler = arguments[1];
  8614. }
  8615. else if (isNumeric(arguments[1])) {
  8616. windowCreationInterval = arguments[1];
  8617. }
  8618. return windowTime(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler)(this);
  8619. }
  8620. Observable.prototype.windowTime = windowTime$1;
  8621. function windowToggle$1(openings, closingSelector) {
  8622. return windowToggle(openings, closingSelector)(this);
  8623. }
  8624. Observable.prototype.windowToggle = windowToggle$1;
  8625. function windowWhen$1(closingSelector) {
  8626. return windowWhen(closingSelector)(this);
  8627. }
  8628. Observable.prototype.windowWhen = windowWhen$1;
  8629. function withLatestFrom$1() {
  8630. var args = [];
  8631. for (var _i = 0; _i < arguments.length; _i++) {
  8632. args[_i] = arguments[_i];
  8633. }
  8634. return withLatestFrom.apply(void 0, args)(this);
  8635. }
  8636. Observable.prototype.withLatestFrom = withLatestFrom$1;
  8637. function zipProto() {
  8638. var observables = [];
  8639. for (var _i = 0; _i < arguments.length; _i++) {
  8640. observables[_i] = arguments[_i];
  8641. }
  8642. return this.lift.call(zip.apply(void 0, [this].concat(observables)));
  8643. }
  8644. Observable.prototype.zip = zipProto;
  8645. function zipAll$1(project) {
  8646. return zipAll(project)(this);
  8647. }
  8648. Observable.prototype.zipAll = zipAll$1;
  8649. var SubscriptionLog = (function () {
  8650. function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
  8651. if (unsubscribedFrame === void 0) { unsubscribedFrame = Number.POSITIVE_INFINITY; }
  8652. this.subscribedFrame = subscribedFrame;
  8653. this.unsubscribedFrame = unsubscribedFrame;
  8654. }
  8655. return SubscriptionLog;
  8656. }());
  8657. var SubscriptionLoggable = (function () {
  8658. function SubscriptionLoggable() {
  8659. this.subscriptions = [];
  8660. }
  8661. SubscriptionLoggable.prototype.logSubscribedFrame = function () {
  8662. this.subscriptions.push(new SubscriptionLog(this.scheduler.now()));
  8663. return this.subscriptions.length - 1;
  8664. };
  8665. SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) {
  8666. var subscriptionLogs = this.subscriptions;
  8667. var oldSubscriptionLog = subscriptionLogs[index];
  8668. subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now());
  8669. };
  8670. return SubscriptionLoggable;
  8671. }());
  8672. var ColdObservable = (function (_super) {
  8673. __extends(ColdObservable, _super);
  8674. function ColdObservable(messages, scheduler) {
  8675. var _this = _super.call(this, function (subscriber) {
  8676. var observable = this;
  8677. var index = observable.logSubscribedFrame();
  8678. var subscription = new Subscription();
  8679. subscription.add(new Subscription(function () {
  8680. observable.logUnsubscribedFrame(index);
  8681. }));
  8682. observable.scheduleMessages(subscriber);
  8683. return subscription;
  8684. }) || this;
  8685. _this.messages = messages;
  8686. _this.subscriptions = [];
  8687. _this.scheduler = scheduler;
  8688. return _this;
  8689. }
  8690. ColdObservable.prototype.scheduleMessages = function (subscriber) {
  8691. var messagesLength = this.messages.length;
  8692. for (var i = 0; i < messagesLength; i++) {
  8693. var message = this.messages[i];
  8694. subscriber.add(this.scheduler.schedule(function (_a) {
  8695. var message = _a.message, subscriber = _a.subscriber;
  8696. message.notification.observe(subscriber);
  8697. }, message.frame, { message: message, subscriber: subscriber }));
  8698. }
  8699. };
  8700. return ColdObservable;
  8701. }(Observable));
  8702. applyMixins(ColdObservable, [SubscriptionLoggable]);
  8703. var HotObservable = (function (_super) {
  8704. __extends(HotObservable, _super);
  8705. function HotObservable(messages, scheduler) {
  8706. var _this = _super.call(this) || this;
  8707. _this.messages = messages;
  8708. _this.subscriptions = [];
  8709. _this.scheduler = scheduler;
  8710. return _this;
  8711. }
  8712. HotObservable.prototype._subscribe = function (subscriber) {
  8713. var subject = this;
  8714. var index = subject.logSubscribedFrame();
  8715. var subscription = new Subscription();
  8716. subscription.add(new Subscription(function () {
  8717. subject.logUnsubscribedFrame(index);
  8718. }));
  8719. subscription.add(_super.prototype._subscribe.call(this, subscriber));
  8720. return subscription;
  8721. };
  8722. HotObservable.prototype.setup = function () {
  8723. var subject = this;
  8724. var messagesLength = subject.messages.length;
  8725. for (var i = 0; i < messagesLength; i++) {
  8726. (function () {
  8727. var message = subject.messages[i];
  8728. subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame);
  8729. })();
  8730. }
  8731. };
  8732. return HotObservable;
  8733. }(Subject));
  8734. applyMixins(HotObservable, [SubscriptionLoggable]);
  8735. var defaultMaxFrame = 750;
  8736. var TestScheduler = (function (_super) {
  8737. __extends(TestScheduler, _super);
  8738. function TestScheduler(assertDeepEqual) {
  8739. var _this = _super.call(this, VirtualAction, defaultMaxFrame) || this;
  8740. _this.assertDeepEqual = assertDeepEqual;
  8741. _this.hotObservables = [];
  8742. _this.coldObservables = [];
  8743. _this.flushTests = [];
  8744. _this.runMode = false;
  8745. return _this;
  8746. }
  8747. TestScheduler.prototype.createTime = function (marbles) {
  8748. var indexOf = marbles.indexOf('|');
  8749. if (indexOf === -1) {
  8750. throw new Error('marble diagram for time should have a completion marker "|"');
  8751. }
  8752. return indexOf * TestScheduler.frameTimeFactor;
  8753. };
  8754. TestScheduler.prototype.createColdObservable = function (marbles, values, error) {
  8755. if (marbles.indexOf('^') !== -1) {
  8756. throw new Error('cold observable cannot have subscription offset "^"');
  8757. }
  8758. if (marbles.indexOf('!') !== -1) {
  8759. throw new Error('cold observable cannot have unsubscription marker "!"');
  8760. }
  8761. var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
  8762. var cold = new ColdObservable(messages, this);
  8763. this.coldObservables.push(cold);
  8764. return cold;
  8765. };
  8766. TestScheduler.prototype.createHotObservable = function (marbles, values, error) {
  8767. if (marbles.indexOf('!') !== -1) {
  8768. throw new Error('hot observable cannot have unsubscription marker "!"');
  8769. }
  8770. var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
  8771. var subject = new HotObservable(messages, this);
  8772. this.hotObservables.push(subject);
  8773. return subject;
  8774. };
  8775. TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
  8776. var _this = this;
  8777. var messages = [];
  8778. observable.subscribe(function (value) {
  8779. messages.push({ frame: _this.frame - outerFrame, notification: Notification.createNext(value) });
  8780. }, function (err) {
  8781. messages.push({ frame: _this.frame - outerFrame, notification: Notification.createError(err) });
  8782. }, function () {
  8783. messages.push({ frame: _this.frame - outerFrame, notification: Notification.createComplete() });
  8784. });
  8785. return messages;
  8786. };
  8787. TestScheduler.prototype.expectObservable = function (observable, subscriptionMarbles) {
  8788. var _this = this;
  8789. if (subscriptionMarbles === void 0) { subscriptionMarbles = null; }
  8790. var actual = [];
  8791. var flushTest = { actual: actual, ready: false };
  8792. var subscriptionParsed = TestScheduler.parseMarblesAsSubscriptions(subscriptionMarbles, this.runMode);
  8793. var subscriptionFrame = subscriptionParsed.subscribedFrame === Number.POSITIVE_INFINITY ?
  8794. 0 : subscriptionParsed.subscribedFrame;
  8795. var unsubscriptionFrame = subscriptionParsed.unsubscribedFrame;
  8796. var subscription;
  8797. this.schedule(function () {
  8798. subscription = observable.subscribe(function (x) {
  8799. var value = x;
  8800. if (x instanceof Observable) {
  8801. value = _this.materializeInnerObservable(value, _this.frame);
  8802. }
  8803. actual.push({ frame: _this.frame, notification: Notification.createNext(value) });
  8804. }, function (err) {
  8805. actual.push({ frame: _this.frame, notification: Notification.createError(err) });
  8806. }, function () {
  8807. actual.push({ frame: _this.frame, notification: Notification.createComplete() });
  8808. });
  8809. }, subscriptionFrame);
  8810. if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
  8811. this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
  8812. }
  8813. this.flushTests.push(flushTest);
  8814. var runMode = this.runMode;
  8815. return {
  8816. toBe: function (marbles, values, errorValue) {
  8817. flushTest.ready = true;
  8818. flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true, runMode);
  8819. }
  8820. };
  8821. };
  8822. TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
  8823. var flushTest = { actual: actualSubscriptionLogs, ready: false };
  8824. this.flushTests.push(flushTest);
  8825. var runMode = this.runMode;
  8826. return {
  8827. toBe: function (marbles) {
  8828. var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles;
  8829. flushTest.ready = true;
  8830. flushTest.expected = marblesArray.map(function (marbles) {
  8831. return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode);
  8832. });
  8833. }
  8834. };
  8835. };
  8836. TestScheduler.prototype.flush = function () {
  8837. var _this = this;
  8838. var hotObservables = this.hotObservables;
  8839. while (hotObservables.length > 0) {
  8840. hotObservables.shift().setup();
  8841. }
  8842. _super.prototype.flush.call(this);
  8843. this.flushTests = this.flushTests.filter(function (test) {
  8844. if (test.ready) {
  8845. _this.assertDeepEqual(test.actual, test.expected);
  8846. return false;
  8847. }
  8848. return true;
  8849. });
  8850. };
  8851. TestScheduler.parseMarblesAsSubscriptions = function (marbles, runMode) {
  8852. var _this = this;
  8853. if (runMode === void 0) { runMode = false; }
  8854. if (typeof marbles !== 'string') {
  8855. return new SubscriptionLog(Number.POSITIVE_INFINITY);
  8856. }
  8857. var len = marbles.length;
  8858. var groupStart = -1;
  8859. var subscriptionFrame = Number.POSITIVE_INFINITY;
  8860. var unsubscriptionFrame = Number.POSITIVE_INFINITY;
  8861. var frame = 0;
  8862. var _loop_1 = function (i) {
  8863. var nextFrame = frame;
  8864. var advanceFrameBy = function (count) {
  8865. nextFrame += count * _this.frameTimeFactor;
  8866. };
  8867. var c = marbles[i];
  8868. switch (c) {
  8869. case ' ':
  8870. if (!runMode) {
  8871. advanceFrameBy(1);
  8872. }
  8873. break;
  8874. case '-':
  8875. advanceFrameBy(1);
  8876. break;
  8877. case '(':
  8878. groupStart = frame;
  8879. advanceFrameBy(1);
  8880. break;
  8881. case ')':
  8882. groupStart = -1;
  8883. advanceFrameBy(1);
  8884. break;
  8885. case '^':
  8886. if (subscriptionFrame !== Number.POSITIVE_INFINITY) {
  8887. throw new Error('found a second subscription point \'^\' in a ' +
  8888. 'subscription marble diagram. There can only be one.');
  8889. }
  8890. subscriptionFrame = groupStart > -1 ? groupStart : frame;
  8891. advanceFrameBy(1);
  8892. break;
  8893. case '!':
  8894. if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
  8895. throw new Error('found a second subscription point \'^\' in a ' +
  8896. 'subscription marble diagram. There can only be one.');
  8897. }
  8898. unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
  8899. break;
  8900. default:
  8901. if (runMode && c.match(/^[0-9]$/)) {
  8902. if (i === 0 || marbles[i - 1] === ' ') {
  8903. var buffer = marbles.slice(i);
  8904. var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
  8905. if (match) {
  8906. i += match[0].length - 1;
  8907. var duration = parseFloat(match[1]);
  8908. var unit = match[2];
  8909. var durationInMs = void 0;
  8910. switch (unit) {
  8911. case 'ms':
  8912. durationInMs = duration;
  8913. break;
  8914. case 's':
  8915. durationInMs = duration * 1000;
  8916. break;
  8917. case 'm':
  8918. durationInMs = duration * 1000 * 60;
  8919. break;
  8920. default:
  8921. break;
  8922. }
  8923. advanceFrameBy(durationInMs / this_1.frameTimeFactor);
  8924. break;
  8925. }
  8926. }
  8927. }
  8928. throw new Error('there can only be \'^\' and \'!\' markers in a ' +
  8929. 'subscription marble diagram. Found instead \'' + c + '\'.');
  8930. }
  8931. frame = nextFrame;
  8932. out_i_1 = i;
  8933. };
  8934. var this_1 = this, out_i_1;
  8935. for (var i = 0; i < len; i++) {
  8936. _loop_1(i);
  8937. i = out_i_1;
  8938. }
  8939. if (unsubscriptionFrame < 0) {
  8940. return new SubscriptionLog(subscriptionFrame);
  8941. }
  8942. else {
  8943. return new SubscriptionLog(subscriptionFrame, unsubscriptionFrame);
  8944. }
  8945. };
  8946. TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables, runMode) {
  8947. var _this = this;
  8948. if (materializeInnerObservables === void 0) { materializeInnerObservables = false; }
  8949. if (runMode === void 0) { runMode = false; }
  8950. if (marbles.indexOf('!') !== -1) {
  8951. throw new Error('conventional marble diagrams cannot have the ' +
  8952. 'unsubscription marker "!"');
  8953. }
  8954. var len = marbles.length;
  8955. var testMessages = [];
  8956. var subIndex = runMode ? marbles.replace(/^[ ]+/, '').indexOf('^') : marbles.indexOf('^');
  8957. var frame = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);
  8958. var getValue = typeof values !== 'object' ?
  8959. function (x) { return x; } :
  8960. function (x) {
  8961. if (materializeInnerObservables && values[x] instanceof ColdObservable) {
  8962. return values[x].messages;
  8963. }
  8964. return values[x];
  8965. };
  8966. var groupStart = -1;
  8967. var _loop_2 = function (i) {
  8968. var nextFrame = frame;
  8969. var advanceFrameBy = function (count) {
  8970. nextFrame += count * _this.frameTimeFactor;
  8971. };
  8972. var notification = void 0;
  8973. var c = marbles[i];
  8974. switch (c) {
  8975. case ' ':
  8976. if (!runMode) {
  8977. advanceFrameBy(1);
  8978. }
  8979. break;
  8980. case '-':
  8981. advanceFrameBy(1);
  8982. break;
  8983. case '(':
  8984. groupStart = frame;
  8985. advanceFrameBy(1);
  8986. break;
  8987. case ')':
  8988. groupStart = -1;
  8989. advanceFrameBy(1);
  8990. break;
  8991. case '|':
  8992. notification = Notification.createComplete();
  8993. advanceFrameBy(1);
  8994. break;
  8995. case '^':
  8996. advanceFrameBy(1);
  8997. break;
  8998. case '#':
  8999. notification = Notification.createError(errorValue || 'error');
  9000. advanceFrameBy(1);
  9001. break;
  9002. default:
  9003. if (runMode && c.match(/^[0-9]$/)) {
  9004. if (i === 0 || marbles[i - 1] === ' ') {
  9005. var buffer = marbles.slice(i);
  9006. var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
  9007. if (match) {
  9008. i += match[0].length - 1;
  9009. var duration = parseFloat(match[1]);
  9010. var unit = match[2];
  9011. var durationInMs = void 0;
  9012. switch (unit) {
  9013. case 'ms':
  9014. durationInMs = duration;
  9015. break;
  9016. case 's':
  9017. durationInMs = duration * 1000;
  9018. break;
  9019. case 'm':
  9020. durationInMs = duration * 1000 * 60;
  9021. break;
  9022. default:
  9023. break;
  9024. }
  9025. advanceFrameBy(durationInMs / this_2.frameTimeFactor);
  9026. break;
  9027. }
  9028. }
  9029. }
  9030. notification = Notification.createNext(getValue(c));
  9031. advanceFrameBy(1);
  9032. break;
  9033. }
  9034. if (notification) {
  9035. testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification });
  9036. }
  9037. frame = nextFrame;
  9038. out_i_2 = i;
  9039. };
  9040. var this_2 = this, out_i_2;
  9041. for (var i = 0; i < len; i++) {
  9042. _loop_2(i);
  9043. i = out_i_2;
  9044. }
  9045. return testMessages;
  9046. };
  9047. TestScheduler.prototype.run = function (callback) {
  9048. var prevFrameTimeFactor = TestScheduler.frameTimeFactor;
  9049. var prevMaxFrames = this.maxFrames;
  9050. TestScheduler.frameTimeFactor = 1;
  9051. this.maxFrames = Number.POSITIVE_INFINITY;
  9052. this.runMode = true;
  9053. AsyncScheduler.delegate = this;
  9054. var helpers = {
  9055. cold: this.createColdObservable.bind(this),
  9056. hot: this.createHotObservable.bind(this),
  9057. flush: this.flush.bind(this),
  9058. expectObservable: this.expectObservable.bind(this),
  9059. expectSubscriptions: this.expectSubscriptions.bind(this),
  9060. };
  9061. try {
  9062. var ret = callback(helpers);
  9063. this.flush();
  9064. return ret;
  9065. }
  9066. finally {
  9067. TestScheduler.frameTimeFactor = prevFrameTimeFactor;
  9068. this.maxFrames = prevMaxFrames;
  9069. this.runMode = false;
  9070. AsyncScheduler.delegate = undefined;
  9071. }
  9072. };
  9073. return TestScheduler;
  9074. }(VirtualTimeScheduler));
  9075. var _testing = /*#__PURE__*/Object.freeze({
  9076. TestScheduler: TestScheduler
  9077. });
  9078. var operators = _operators;
  9079. var Scheduler$1 = {
  9080. asap: asap,
  9081. queue: queue,
  9082. animationFrame: animationFrame,
  9083. async: async
  9084. };
  9085. var Symbol$1 = {
  9086. rxSubscriber: rxSubscriber,
  9087. observable: observable,
  9088. iterator: iterator
  9089. };
  9090. var testing = _testing;
  9091. var ajax$1 = _ajax;
  9092. var webSocket$1 = _webSocket;
  9093. exports.testing = testing;
  9094. exports.ajax = ajax$1;
  9095. exports.webSocket = webSocket$1;
  9096. exports.operators = operators;
  9097. exports.Scheduler = Scheduler$1;
  9098. exports.Symbol = Symbol$1;
  9099. exports.Observable = Observable;
  9100. exports.Subject = Subject;
  9101. exports.AnonymousSubject = AnonymousSubject;
  9102. exports.config = config;
  9103. exports.Subscription = Subscription;
  9104. exports.ReplaySubject = ReplaySubject;
  9105. exports.BehaviorSubject = BehaviorSubject;
  9106. exports.Notification = Notification;
  9107. exports.EmptyError = EmptyError;
  9108. exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError;
  9109. exports.ObjectUnsubscribedError = ObjectUnsubscribedError;
  9110. exports.UnsubscriptionError = UnsubscriptionError;
  9111. exports.pipe = pipe;
  9112. exports.TestScheduler = TestScheduler;
  9113. exports.Subscriber = Subscriber;
  9114. exports.AsyncSubject = AsyncSubject;
  9115. exports.ConnectableObservable = ConnectableObservable;
  9116. exports.TimeoutError = TimeoutError;
  9117. exports.VirtualTimeScheduler = VirtualTimeScheduler;
  9118. exports.AjaxResponse = AjaxResponse;
  9119. exports.AjaxError = AjaxError;
  9120. exports.AjaxTimeoutError = AjaxTimeoutError;
  9121. exports.TimeInterval = TimeInterval;
  9122. exports.Timestamp = Timestamp;
  9123. Object.defineProperty(exports, '__esModule', { value: true });
  9124. })));
  9125. //# sourceMappingURL=rxjs-compat.umd.js.map