rxjs.umd.js 357 KB

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