12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263 |
- /**
- @license
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright (c) 2015-2017 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- **/
- /**
- @license
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright (c) 2015-2017 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- **/
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (factory((global.Rx = global.Rx || {})));
- }(this, (function (exports) { 'use strict';
-
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation. All rights reserved.
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of the
- License at http://www.apache.org/licenses/LICENSE-2.0
-
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
- MERCHANTABLITY OR NON-INFRINGEMENT.
-
- See the Apache Version 2.0 License for specific language governing permissions
- and limitations under the License.
- ***************************************************************************** */
- /* global Reflect, Promise */
-
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
-
- function __extends(d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function __values(o) {
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
- if (m) return m.call(o);
- return {
- next: function () {
- if (o && i >= o.length) o = void 0;
- return { value: o && o[i++], done: !o };
- }
- };
- }
-
- function __read(o, n) {
- var m = typeof Symbol === "function" && o[Symbol.iterator];
- if (!m) return o;
- var i = m.call(o), r, ar = [], e;
- try {
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
- }
- catch (error) { e = { error: error }; }
- finally {
- try {
- if (r && !r.done && (m = i["return"])) m.call(i);
- }
- finally { if (e) throw e.error; }
- }
- return ar;
- }
-
-
-
- function __await(v) {
- return this instanceof __await ? (this.v = v, this) : new __await(v);
- }
-
- // CommonJS / Node have global context exposed as "global" variable.
- // We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
- // the global "global" var for now.
- var __window = typeof window !== 'undefined' && window;
- var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
- self instanceof WorkerGlobalScope && self;
- var __global = typeof global !== 'undefined' && global;
- var _root = __window || __global || __self;
- // Workaround Closure Compiler restriction: The body of a goog.module cannot use throw.
- // This is needed when used with angular/tsickle which inserts a goog.module statement.
- // Wrap in IIFE
- (function () {
- if (!_root) {
- throw new Error('RxJS could not find any global context (window, self, global)');
- }
- })();
-
- function isFunction(x) {
- return typeof x === 'function';
- }
-
- var isArray = Array.isArray || (function (x) { return x && typeof x.length === 'number'; });
-
- function isObject(x) {
- return x != null && typeof x === 'object';
- }
-
- // typeof any so that it we don't have to cast when comparing a result to the error object
- var errorObject = { e: {} };
-
- var tryCatchTarget;
- function tryCatcher() {
- try {
- return tryCatchTarget.apply(this, arguments);
- }
- catch (e) {
- errorObject.e = e;
- return errorObject;
- }
- }
- function tryCatch(fn) {
- tryCatchTarget = fn;
- return tryCatcher;
- }
-
- /**
- * An error thrown when one or more errors have occurred during the
- * `unsubscribe` of a {@link Subscription}.
- */
- var UnsubscriptionError = (function (_super) {
- __extends(UnsubscriptionError, _super);
- function UnsubscriptionError(errors) {
- _super.call(this);
- this.errors = errors;
- var err = Error.call(this, errors ?
- errors.length + " errors occurred during unsubscription:\n " + errors.map(function (err, i) { return ((i + 1) + ") " + err.toString()); }).join('\n ') : '');
- this.name = err.name = 'UnsubscriptionError';
- this.stack = err.stack;
- this.message = err.message;
- }
- return UnsubscriptionError;
- }(Error));
-
- /**
- * Represents a disposable resource, such as the execution of an Observable. A
- * Subscription has one important method, `unsubscribe`, that takes no argument
- * and just disposes the resource held by the subscription.
- *
- * Additionally, subscriptions may be grouped together through the `add()`
- * method, which will attach a child Subscription to the current Subscription.
- * When a Subscription is unsubscribed, all its children (and its grandchildren)
- * will be unsubscribed as well.
- *
- * @class Subscription
- */
- var Subscription = (function () {
- /**
- * @param {function(): void} [unsubscribe] A function describing how to
- * perform the disposal of resources when the `unsubscribe` method is called.
- */
- function Subscription(unsubscribe) {
- /**
- * A flag to indicate whether this Subscription has already been unsubscribed.
- * @type {boolean}
- */
- this.closed = false;
- this._parent = null;
- this._parents = null;
- this._subscriptions = null;
- if (unsubscribe) {
- this._unsubscribe = unsubscribe;
- }
- }
- /**
- * Disposes the resources held by the subscription. May, for instance, cancel
- * an ongoing Observable execution or cancel any other type of work that
- * started when the Subscription was created.
- * @return {void}
- */
- Subscription.prototype.unsubscribe = function () {
- var hasErrors = false;
- var errors;
- if (this.closed) {
- return;
- }
- var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
- this.closed = true;
- this._parent = null;
- this._parents = null;
- // null out _subscriptions first so any child subscriptions that attempt
- // to remove themselves from this subscription will noop
- this._subscriptions = null;
- var index = -1;
- var len = _parents ? _parents.length : 0;
- // if this._parent is null, then so is this._parents, and we
- // don't have to remove ourselves from any parent subscriptions.
- while (_parent) {
- _parent.remove(this);
- // if this._parents is null or index >= len,
- // then _parent is set to null, and the loop exits
- _parent = ++index < len && _parents[index] || null;
- }
- if (isFunction(_unsubscribe)) {
- var trial = tryCatch(_unsubscribe).call(this);
- if (trial === errorObject) {
- hasErrors = true;
- errors = errors || (errorObject.e instanceof UnsubscriptionError ?
- flattenUnsubscriptionErrors(errorObject.e.errors) : [errorObject.e]);
- }
- }
- if (isArray(_subscriptions)) {
- index = -1;
- len = _subscriptions.length;
- while (++index < len) {
- var sub = _subscriptions[index];
- if (isObject(sub)) {
- var trial = tryCatch(sub.unsubscribe).call(sub);
- if (trial === errorObject) {
- hasErrors = true;
- errors = errors || [];
- var err = errorObject.e;
- if (err instanceof UnsubscriptionError) {
- errors = errors.concat(flattenUnsubscriptionErrors(err.errors));
- }
- else {
- errors.push(err);
- }
- }
- }
- }
- }
- if (hasErrors) {
- throw new UnsubscriptionError(errors);
- }
- };
- /**
- * Adds a tear down to be called during the unsubscribe() of this
- * Subscription.
- *
- * If the tear down being added is a subscription that is already
- * unsubscribed, is the same reference `add` is being called on, or is
- * `Subscription.EMPTY`, it will not be added.
- *
- * If this subscription is already in an `closed` state, the passed
- * tear down logic will be executed immediately.
- *
- * @param {TeardownLogic} teardown The additional logic to execute on
- * teardown.
- * @return {Subscription} Returns the Subscription used or created to be
- * added to the inner subscriptions list. This Subscription can be used with
- * `remove()` to remove the passed teardown logic from the inner subscriptions
- * list.
- */
- Subscription.prototype.add = function (teardown) {
- if (!teardown || (teardown === Subscription.EMPTY)) {
- return Subscription.EMPTY;
- }
- if (teardown === this) {
- return this;
- }
- var subscription = teardown;
- switch (typeof teardown) {
- case 'function':
- subscription = new Subscription(teardown);
- case 'object':
- if (subscription.closed || typeof subscription.unsubscribe !== 'function') {
- return subscription;
- }
- else if (this.closed) {
- subscription.unsubscribe();
- return subscription;
- }
- else if (typeof subscription._addParent !== 'function' /* quack quack */) {
- var tmp = subscription;
- subscription = new Subscription();
- subscription._subscriptions = [tmp];
- }
- break;
- default:
- throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
- }
- var subscriptions = this._subscriptions || (this._subscriptions = []);
- subscriptions.push(subscription);
- subscription._addParent(this);
- return subscription;
- };
- /**
- * Removes a Subscription from the internal list of subscriptions that will
- * unsubscribe during the unsubscribe process of this Subscription.
- * @param {Subscription} subscription The subscription to remove.
- * @return {void}
- */
- Subscription.prototype.remove = function (subscription) {
- var subscriptions = this._subscriptions;
- if (subscriptions) {
- var subscriptionIndex = subscriptions.indexOf(subscription);
- if (subscriptionIndex !== -1) {
- subscriptions.splice(subscriptionIndex, 1);
- }
- }
- };
- Subscription.prototype._addParent = function (parent) {
- var _a = this, _parent = _a._parent, _parents = _a._parents;
- if (!_parent || _parent === parent) {
- // If we don't have a parent, or the new parent is the same as the
- // current parent, then set this._parent to the new parent.
- this._parent = parent;
- }
- else if (!_parents) {
- // If there's already one parent, but not multiple, allocate an Array to
- // store the rest of the parent Subscriptions.
- this._parents = [parent];
- }
- else if (_parents.indexOf(parent) === -1) {
- // Only add the new parent to the _parents list if it's not already there.
- _parents.push(parent);
- }
- };
- Subscription.EMPTY = (function (empty) {
- empty.closed = true;
- return empty;
- }(new Subscription()));
- return Subscription;
- }());
- function flattenUnsubscriptionErrors(errors) {
- return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
- }
-
- var empty = {
- closed: true,
- next: function (value) { },
- error: function (err) { throw err; },
- complete: function () { }
- };
-
- var Symbol$2 = _root.Symbol;
- var rxSubscriber = (typeof Symbol$2 === 'function' && typeof Symbol$2.for === 'function') ?
- Symbol$2.for('rxSubscriber') : '@@rxSubscriber';
- /**
- * @deprecated use rxSubscriber instead
- */
-
- /**
- * Implements the {@link Observer} interface and extends the
- * {@link Subscription} class. While the {@link Observer} is the public API for
- * consuming the values of an {@link Observable}, all Observers get converted to
- * a Subscriber, in order to provide Subscription-like capabilities such as
- * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for
- * implementing operators, but it is rarely used as a public API.
- *
- * @class Subscriber<T>
- */
- var Subscriber = (function (_super) {
- __extends(Subscriber, _super);
- /**
- * @param {Observer|function(value: T): void} [destinationOrNext] A partially
- * defined Observer or a `next` callback function.
- * @param {function(e: ?any): void} [error] The `error` callback of an
- * Observer.
- * @param {function(): void} [complete] The `complete` callback of an
- * Observer.
- */
- function Subscriber(destinationOrNext, error, complete) {
- _super.call(this);
- this.syncErrorValue = null;
- this.syncErrorThrown = false;
- this.syncErrorThrowable = false;
- this.isStopped = false;
- switch (arguments.length) {
- case 0:
- this.destination = empty;
- break;
- case 1:
- if (!destinationOrNext) {
- this.destination = empty;
- break;
- }
- if (typeof destinationOrNext === 'object') {
- // HACK(benlesh): To resolve an issue where Node users may have multiple
- // copies of rxjs in their node_modules directory.
- if (isTrustedSubscriber(destinationOrNext)) {
- var trustedSubscriber = destinationOrNext[rxSubscriber]();
- this.syncErrorThrowable = trustedSubscriber.syncErrorThrowable;
- this.destination = trustedSubscriber;
- trustedSubscriber.add(this);
- }
- else {
- this.syncErrorThrowable = true;
- this.destination = new SafeSubscriber(this, destinationOrNext);
- }
- break;
- }
- default:
- this.syncErrorThrowable = true;
- this.destination = new SafeSubscriber(this, destinationOrNext, error, complete);
- break;
- }
- }
- Subscriber.prototype[rxSubscriber] = function () { return this; };
- /**
- * A static factory for a Subscriber, given a (potentially partial) definition
- * of an Observer.
- * @param {function(x: ?T): void} [next] The `next` callback of an Observer.
- * @param {function(e: ?any): void} [error] The `error` callback of an
- * Observer.
- * @param {function(): void} [complete] The `complete` callback of an
- * Observer.
- * @return {Subscriber<T>} A Subscriber wrapping the (partially defined)
- * Observer represented by the given arguments.
- */
- Subscriber.create = function (next, error, complete) {
- var subscriber = new Subscriber(next, error, complete);
- subscriber.syncErrorThrowable = false;
- return subscriber;
- };
- /**
- * The {@link Observer} callback to receive notifications of type `next` from
- * the Observable, with a value. The Observable may call this method 0 or more
- * times.
- * @param {T} [value] The `next` value.
- * @return {void}
- */
- Subscriber.prototype.next = function (value) {
- if (!this.isStopped) {
- this._next(value);
- }
- };
- /**
- * The {@link Observer} callback to receive notifications of type `error` from
- * the Observable, with an attached {@link Error}. Notifies the Observer that
- * the Observable has experienced an error condition.
- * @param {any} [err] The `error` exception.
- * @return {void}
- */
- Subscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- this.isStopped = true;
- this._error(err);
- }
- };
- /**
- * The {@link Observer} callback to receive a valueless notification of type
- * `complete` from the Observable. Notifies the Observer that the Observable
- * has finished sending push-based notifications.
- * @return {void}
- */
- Subscriber.prototype.complete = function () {
- if (!this.isStopped) {
- this.isStopped = true;
- this._complete();
- }
- };
- Subscriber.prototype.unsubscribe = function () {
- if (this.closed) {
- return;
- }
- this.isStopped = true;
- _super.prototype.unsubscribe.call(this);
- };
- Subscriber.prototype._next = function (value) {
- this.destination.next(value);
- };
- Subscriber.prototype._error = function (err) {
- this.destination.error(err);
- this.unsubscribe();
- };
- Subscriber.prototype._complete = function () {
- this.destination.complete();
- this.unsubscribe();
- };
- /** @deprecated internal use only */ Subscriber.prototype._unsubscribeAndRecycle = function () {
- var _a = this, _parent = _a._parent, _parents = _a._parents;
- this._parent = null;
- this._parents = null;
- this.unsubscribe();
- this.closed = false;
- this.isStopped = false;
- this._parent = _parent;
- this._parents = _parents;
- return this;
- };
- return Subscriber;
- }(Subscription));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SafeSubscriber = (function (_super) {
- __extends(SafeSubscriber, _super);
- function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
- _super.call(this);
- this._parentSubscriber = _parentSubscriber;
- var next;
- var context = this;
- if (isFunction(observerOrNext)) {
- next = observerOrNext;
- }
- else if (observerOrNext) {
- next = observerOrNext.next;
- error = observerOrNext.error;
- complete = observerOrNext.complete;
- if (observerOrNext !== empty) {
- context = Object.create(observerOrNext);
- if (isFunction(context.unsubscribe)) {
- this.add(context.unsubscribe.bind(context));
- }
- context.unsubscribe = this.unsubscribe.bind(this);
- }
- }
- this._context = context;
- this._next = next;
- this._error = error;
- this._complete = complete;
- }
- SafeSubscriber.prototype.next = function (value) {
- if (!this.isStopped && this._next) {
- var _parentSubscriber = this._parentSubscriber;
- if (!_parentSubscriber.syncErrorThrowable) {
- this.__tryOrUnsub(this._next, value);
- }
- else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
- this.unsubscribe();
- }
- }
- };
- SafeSubscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- var _parentSubscriber = this._parentSubscriber;
- if (this._error) {
- if (!_parentSubscriber.syncErrorThrowable) {
- this.__tryOrUnsub(this._error, err);
- this.unsubscribe();
- }
- else {
- this.__tryOrSetError(_parentSubscriber, this._error, err);
- this.unsubscribe();
- }
- }
- else if (!_parentSubscriber.syncErrorThrowable) {
- this.unsubscribe();
- throw err;
- }
- else {
- _parentSubscriber.syncErrorValue = err;
- _parentSubscriber.syncErrorThrown = true;
- this.unsubscribe();
- }
- }
- };
- SafeSubscriber.prototype.complete = function () {
- var _this = this;
- if (!this.isStopped) {
- var _parentSubscriber = this._parentSubscriber;
- if (this._complete) {
- var wrappedComplete = function () { return _this._complete.call(_this._context); };
- if (!_parentSubscriber.syncErrorThrowable) {
- this.__tryOrUnsub(wrappedComplete);
- this.unsubscribe();
- }
- else {
- this.__tryOrSetError(_parentSubscriber, wrappedComplete);
- this.unsubscribe();
- }
- }
- else {
- this.unsubscribe();
- }
- }
- };
- SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
- try {
- fn.call(this._context, value);
- }
- catch (err) {
- this.unsubscribe();
- throw err;
- }
- };
- SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
- try {
- fn.call(this._context, value);
- }
- catch (err) {
- parent.syncErrorValue = err;
- parent.syncErrorThrown = true;
- return true;
- }
- return false;
- };
- /** @deprecated internal use only */ SafeSubscriber.prototype._unsubscribe = function () {
- var _parentSubscriber = this._parentSubscriber;
- this._context = null;
- this._parentSubscriber = null;
- _parentSubscriber.unsubscribe();
- };
- return SafeSubscriber;
- }(Subscriber));
- function isTrustedSubscriber(obj) {
- return obj instanceof Subscriber || ('syncErrorThrowable' in obj && obj[rxSubscriber]);
- }
-
- function toSubscriber(nextOrObserver, error, complete) {
- if (nextOrObserver) {
- if (nextOrObserver instanceof Subscriber) {
- return nextOrObserver;
- }
- if (nextOrObserver[rxSubscriber]) {
- return nextOrObserver[rxSubscriber]();
- }
- }
- if (!nextOrObserver && !error && !complete) {
- return new Subscriber(empty);
- }
- return new Subscriber(nextOrObserver, error, complete);
- }
-
- function getSymbolObservable(context) {
- var $$observable;
- var Symbol = context.Symbol;
- if (typeof Symbol === 'function') {
- if (Symbol.observable) {
- $$observable = Symbol.observable;
- }
- else {
- $$observable = Symbol('observable');
- Symbol.observable = $$observable;
- }
- }
- else {
- $$observable = '@@observable';
- }
- return $$observable;
- }
- var observable = getSymbolObservable(_root);
- /**
- * @deprecated use observable instead
- */
-
- /* tslint:disable:no-empty */
- function noop() { }
-
- /* tslint:enable:max-line-length */
- function pipe() {
- var fns = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- fns[_i - 0] = arguments[_i];
- }
- return pipeFromArray(fns);
- }
- /* @internal */
- function pipeFromArray(fns) {
- if (!fns) {
- return noop;
- }
- if (fns.length === 1) {
- return fns[0];
- }
- return function piped(input) {
- return fns.reduce(function (prev, fn) { return fn(prev); }, input);
- };
- }
-
- /**
- * A representation of any set of values over any amount of time. This is the most basic building block
- * of RxJS.
- *
- * @class Observable<T>
- */
- var Observable = (function () {
- /**
- * @constructor
- * @param {Function} subscribe the function that is called when the Observable is
- * initially subscribed to. This function is given a Subscriber, to which new values
- * can be `next`ed, or an `error` method can be called to raise an error, or
- * `complete` can be called to notify of a successful completion.
- */
- function Observable(subscribe) {
- this._isScalar = false;
- if (subscribe) {
- this._subscribe = subscribe;
- }
- }
- /**
- * Creates a new Observable, with this Observable as the source, and the passed
- * operator defined as the new observable's operator.
- * @method lift
- * @param {Operator} operator the operator defining the operation to take on the observable
- * @return {Observable} a new observable with the Operator applied
- */
- Observable.prototype.lift = function (operator) {
- var observable$$1 = new Observable();
- observable$$1.source = this;
- observable$$1.operator = operator;
- return observable$$1;
- };
- /**
- * Invokes an execution of an Observable and registers Observer handlers for notifications it will emit.
- *
- * <span class="informal">Use it when you have all these Observables, but still nothing is happening.</span>
- *
- * `subscribe` is not a regular operator, but a method that calls Observable's internal `subscribe` function. It
- * might be for example a function that you passed to a {@link create} static factory, but most of the time it is
- * a library implementation, which defines what and when will be emitted by an Observable. This means that calling
- * `subscribe` is actually the moment when Observable starts its work, not when it is created, as it is often
- * thought.
- *
- * Apart from starting the execution of an Observable, this method allows you to listen for values
- * that an Observable emits, as well as for when it completes or errors. You can achieve this in two
- * following ways.
- *
- * The first way is creating an object that implements {@link Observer} interface. It should have methods
- * defined by that interface, but note that it should be just a regular JavaScript object, which you can create
- * yourself in any way you want (ES6 class, classic function constructor, object literal etc.). In particular do
- * not attempt to use any RxJS implementation details to create Observers - you don't need them. Remember also
- * that your object does not have to implement all methods. If you find yourself creating a method that doesn't
- * do anything, you can simply omit it. Note however, that if `error` method is not provided, all errors will
- * be left uncaught.
- *
- * The second way is to give up on Observer object altogether and simply provide callback functions in place of its methods.
- * This means you can provide three functions as arguments to `subscribe`, where first function is equivalent
- * of a `next` method, second of an `error` method and third of a `complete` method. Just as in case of Observer,
- * if you do not need to listen for something, you can omit a function, preferably by passing `undefined` or `null`,
- * since `subscribe` recognizes these functions by where they were placed in function call. When it comes
- * to `error` function, just as before, if not provided, errors emitted by an Observable will be thrown.
- *
- * Whatever style of calling `subscribe` you use, in both cases it returns a Subscription object.
- * This object allows you to call `unsubscribe` on it, which in turn will stop work that an Observable does and will clean
- * up all resources that an Observable used. Note that cancelling a subscription will not call `complete` callback
- * provided to `subscribe` function, which is reserved for a regular completion signal that comes from an Observable.
- *
- * Remember that callbacks provided to `subscribe` are not guaranteed to be called asynchronously.
- * It is an Observable itself that decides when these functions will be called. For example {@link of}
- * by default emits all its values synchronously. Always check documentation for how given Observable
- * will behave when subscribed and if its default behavior can be modified with a {@link Scheduler}.
- *
- * @example <caption>Subscribe with an Observer</caption>
- * const sumObserver = {
- * sum: 0,
- * next(value) {
- * console.log('Adding: ' + value);
- * this.sum = this.sum + value;
- * },
- * error() { // We actually could just remove this method,
- * }, // since we do not really care about errors right now.
- * complete() {
- * console.log('Sum equals: ' + this.sum);
- * }
- * };
- *
- * Rx.Observable.of(1, 2, 3) // Synchronously emits 1, 2, 3 and then completes.
- * .subscribe(sumObserver);
- *
- * // Logs:
- * // "Adding: 1"
- * // "Adding: 2"
- * // "Adding: 3"
- * // "Sum equals: 6"
- *
- *
- * @example <caption>Subscribe with functions</caption>
- * let sum = 0;
- *
- * Rx.Observable.of(1, 2, 3)
- * .subscribe(
- * function(value) {
- * console.log('Adding: ' + value);
- * sum = sum + value;
- * },
- * undefined,
- * function() {
- * console.log('Sum equals: ' + sum);
- * }
- * );
- *
- * // Logs:
- * // "Adding: 1"
- * // "Adding: 2"
- * // "Adding: 3"
- * // "Sum equals: 6"
- *
- *
- * @example <caption>Cancel a subscription</caption>
- * const subscription = Rx.Observable.interval(1000).subscribe(
- * num => console.log(num),
- * undefined,
- * () => console.log('completed!') // Will not be called, even
- * ); // when cancelling subscription
- *
- *
- * setTimeout(() => {
- * subscription.unsubscribe();
- * console.log('unsubscribed!');
- * }, 2500);
- *
- * // Logs:
- * // 0 after 1s
- * // 1 after 2s
- * // "unsubscribed!" after 2.5s
- *
- *
- * @param {Observer|Function} observerOrNext (optional) Either an observer with methods to be called,
- * or the first of three possible handlers, which is the handler for each value emitted from the subscribed
- * Observable.
- * @param {Function} error (optional) A handler for a terminal event resulting from an error. If no error handler is provided,
- * the error will be thrown as unhandled.
- * @param {Function} complete (optional) A handler for a terminal event resulting from successful completion.
- * @return {ISubscription} a subscription reference to the registered handlers
- * @method subscribe
- */
- Observable.prototype.subscribe = function (observerOrNext, error, complete) {
- var operator = this.operator;
- var sink = toSubscriber(observerOrNext, error, complete);
- if (operator) {
- operator.call(sink, this.source);
- }
- else {
- sink.add(this.source || !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink));
- }
- if (sink.syncErrorThrowable) {
- sink.syncErrorThrowable = false;
- if (sink.syncErrorThrown) {
- throw sink.syncErrorValue;
- }
- }
- return sink;
- };
- Observable.prototype._trySubscribe = function (sink) {
- try {
- return this._subscribe(sink);
- }
- catch (err) {
- sink.syncErrorThrown = true;
- sink.syncErrorValue = err;
- sink.error(err);
- }
- };
- /**
- * @method forEach
- * @param {Function} next a handler for each value emitted by the observable
- * @param {PromiseConstructor} [PromiseCtor] a constructor function used to instantiate the Promise
- * @return {Promise} a promise that either resolves on observable completion or
- * rejects with the handled error
- */
- Observable.prototype.forEach = function (next, PromiseCtor) {
- var _this = this;
- if (!PromiseCtor) {
- if (_root.Rx && _root.Rx.config && _root.Rx.config.Promise) {
- PromiseCtor = _root.Rx.config.Promise;
- }
- else if (_root.Promise) {
- PromiseCtor = _root.Promise;
- }
- }
- if (!PromiseCtor) {
- throw new Error('no Promise impl found');
- }
- return new PromiseCtor(function (resolve, reject) {
- // Must be declared in a separate statement to avoid a RefernceError when
- // accessing subscription below in the closure due to Temporal Dead Zone.
- var subscription;
- subscription = _this.subscribe(function (value) {
- if (subscription) {
- // if there is a subscription, then we can surmise
- // the next handling is asynchronous. Any errors thrown
- // need to be rejected explicitly and unsubscribe must be
- // called manually
- try {
- next(value);
- }
- catch (err) {
- reject(err);
- subscription.unsubscribe();
- }
- }
- else {
- // if there is NO subscription, then we're getting a nexted
- // value synchronously during subscription. We can just call it.
- // If it errors, Observable's `subscribe` will ensure the
- // unsubscription logic is called, then synchronously rethrow the error.
- // After that, Promise will trap the error and send it
- // down the rejection path.
- next(value);
- }
- }, reject, resolve);
- });
- };
- /** @deprecated internal use only */ Observable.prototype._subscribe = function (subscriber) {
- return this.source.subscribe(subscriber);
- };
- /**
- * An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable
- * @method Symbol.observable
- * @return {Observable} this instance of the observable
- */
- Observable.prototype[observable] = function () {
- return this;
- };
- /* tslint:enable:max-line-length */
- /**
- * Used to stitch together functional operators into a chain.
- * @method pipe
- * @return {Observable} the Observable result of all of the operators having
- * been called in the order they were passed in.
- *
- * @example
- *
- * import { map, filter, scan } from 'rxjs/operators';
- *
- * Rx.Observable.interval(1000)
- * .pipe(
- * filter(x => x % 2 === 0),
- * map(x => x + x),
- * scan((acc, x) => acc + x)
- * )
- * .subscribe(x => console.log(x))
- */
- Observable.prototype.pipe = function () {
- var operations = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- operations[_i - 0] = arguments[_i];
- }
- if (operations.length === 0) {
- return this;
- }
- return pipeFromArray(operations)(this);
- };
- /* tslint:enable:max-line-length */
- Observable.prototype.toPromise = function (PromiseCtor) {
- var _this = this;
- if (!PromiseCtor) {
- if (_root.Rx && _root.Rx.config && _root.Rx.config.Promise) {
- PromiseCtor = _root.Rx.config.Promise;
- }
- else if (_root.Promise) {
- PromiseCtor = _root.Promise;
- }
- }
- if (!PromiseCtor) {
- throw new Error('no Promise impl found');
- }
- return new PromiseCtor(function (resolve, reject) {
- var value;
- _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
- });
- };
- // HACK: Since TypeScript inherits static properties too, we have to
- // fight against TypeScript here so Subject can have a different static create signature
- /**
- * Creates a new cold Observable by calling the Observable constructor
- * @static true
- * @owner Observable
- * @method create
- * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor
- * @return {Observable} a new cold observable
- */
- Observable.create = function (subscribe) {
- return new Observable(subscribe);
- };
- return Observable;
- }());
-
- /**
- * An error thrown when an action is invalid because the object has been
- * unsubscribed.
- *
- * @see {@link Subject}
- * @see {@link BehaviorSubject}
- *
- * @class ObjectUnsubscribedError
- */
- var ObjectUnsubscribedError = (function (_super) {
- __extends(ObjectUnsubscribedError, _super);
- function ObjectUnsubscribedError() {
- var err = _super.call(this, 'object unsubscribed');
- this.name = err.name = 'ObjectUnsubscribedError';
- this.stack = err.stack;
- this.message = err.message;
- }
- return ObjectUnsubscribedError;
- }(Error));
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SubjectSubscription = (function (_super) {
- __extends(SubjectSubscription, _super);
- function SubjectSubscription(subject, subscriber) {
- _super.call(this);
- this.subject = subject;
- this.subscriber = subscriber;
- this.closed = false;
- }
- SubjectSubscription.prototype.unsubscribe = function () {
- if (this.closed) {
- return;
- }
- this.closed = true;
- var subject = this.subject;
- var observers = subject.observers;
- this.subject = null;
- if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
- return;
- }
- var subscriberIndex = observers.indexOf(this.subscriber);
- if (subscriberIndex !== -1) {
- observers.splice(subscriberIndex, 1);
- }
- };
- return SubjectSubscription;
- }(Subscription));
-
- /**
- * @class SubjectSubscriber<T>
- */
- var SubjectSubscriber = (function (_super) {
- __extends(SubjectSubscriber, _super);
- function SubjectSubscriber(destination) {
- _super.call(this, destination);
- this.destination = destination;
- }
- return SubjectSubscriber;
- }(Subscriber));
- /**
- * @class Subject<T>
- */
- var Subject = (function (_super) {
- __extends(Subject, _super);
- function Subject() {
- _super.call(this);
- this.observers = [];
- this.closed = false;
- this.isStopped = false;
- this.hasError = false;
- this.thrownError = null;
- }
- Subject.prototype[rxSubscriber] = function () {
- return new SubjectSubscriber(this);
- };
- Subject.prototype.lift = function (operator) {
- var subject = new AnonymousSubject(this, this);
- subject.operator = operator;
- return subject;
- };
- Subject.prototype.next = function (value) {
- if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- if (!this.isStopped) {
- var observers = this.observers;
- var len = observers.length;
- var copy = observers.slice();
- for (var i = 0; i < len; i++) {
- copy[i].next(value);
- }
- }
- };
- Subject.prototype.error = function (err) {
- if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- this.hasError = true;
- this.thrownError = err;
- this.isStopped = true;
- var observers = this.observers;
- var len = observers.length;
- var copy = observers.slice();
- for (var i = 0; i < len; i++) {
- copy[i].error(err);
- }
- this.observers.length = 0;
- };
- Subject.prototype.complete = function () {
- if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- this.isStopped = true;
- var observers = this.observers;
- var len = observers.length;
- var copy = observers.slice();
- for (var i = 0; i < len; i++) {
- copy[i].complete();
- }
- this.observers.length = 0;
- };
- Subject.prototype.unsubscribe = function () {
- this.isStopped = true;
- this.closed = true;
- this.observers = null;
- };
- Subject.prototype._trySubscribe = function (subscriber) {
- if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- else {
- return _super.prototype._trySubscribe.call(this, subscriber);
- }
- };
- /** @deprecated internal use only */ Subject.prototype._subscribe = function (subscriber) {
- if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- else if (this.hasError) {
- subscriber.error(this.thrownError);
- return Subscription.EMPTY;
- }
- else if (this.isStopped) {
- subscriber.complete();
- return Subscription.EMPTY;
- }
- else {
- this.observers.push(subscriber);
- return new SubjectSubscription(this, subscriber);
- }
- };
- Subject.prototype.asObservable = function () {
- var observable = new Observable();
- observable.source = this;
- return observable;
- };
- Subject.create = function (destination, source) {
- return new AnonymousSubject(destination, source);
- };
- return Subject;
- }(Observable));
- /**
- * @class AnonymousSubject<T>
- */
- var AnonymousSubject = (function (_super) {
- __extends(AnonymousSubject, _super);
- function AnonymousSubject(destination, source) {
- _super.call(this);
- this.destination = destination;
- this.source = source;
- }
- AnonymousSubject.prototype.next = function (value) {
- var destination = this.destination;
- if (destination && destination.next) {
- destination.next(value);
- }
- };
- AnonymousSubject.prototype.error = function (err) {
- var destination = this.destination;
- if (destination && destination.error) {
- this.destination.error(err);
- }
- };
- AnonymousSubject.prototype.complete = function () {
- var destination = this.destination;
- if (destination && destination.complete) {
- this.destination.complete();
- }
- };
- /** @deprecated internal use only */ AnonymousSubject.prototype._subscribe = function (subscriber) {
- var source = this.source;
- if (source) {
- return this.source.subscribe(subscriber);
- }
- else {
- return Subscription.EMPTY;
- }
- };
- return AnonymousSubject;
- }(Subject));
-
- /**
- * @class AsyncSubject<T>
- */
- var AsyncSubject = (function (_super) {
- __extends(AsyncSubject, _super);
- function AsyncSubject() {
- _super.apply(this, arguments);
- this.value = null;
- this.hasNext = false;
- this.hasCompleted = false;
- }
- /** @deprecated internal use only */ AsyncSubject.prototype._subscribe = function (subscriber) {
- if (this.hasError) {
- subscriber.error(this.thrownError);
- return Subscription.EMPTY;
- }
- else if (this.hasCompleted && this.hasNext) {
- subscriber.next(this.value);
- subscriber.complete();
- return Subscription.EMPTY;
- }
- return _super.prototype._subscribe.call(this, subscriber);
- };
- AsyncSubject.prototype.next = function (value) {
- if (!this.hasCompleted) {
- this.value = value;
- this.hasNext = true;
- }
- };
- AsyncSubject.prototype.error = function (error) {
- if (!this.hasCompleted) {
- _super.prototype.error.call(this, error);
- }
- };
- AsyncSubject.prototype.complete = function () {
- this.hasCompleted = true;
- if (this.hasNext) {
- _super.prototype.next.call(this, this.value);
- }
- _super.prototype.complete.call(this);
- };
- return AsyncSubject;
- }(Subject));
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var BoundCallbackObservable = (function (_super) {
- __extends(BoundCallbackObservable, _super);
- function BoundCallbackObservable(callbackFunc, selector, args, context, scheduler) {
- _super.call(this);
- this.callbackFunc = callbackFunc;
- this.selector = selector;
- this.args = args;
- this.context = context;
- this.scheduler = scheduler;
- }
- /* tslint:enable:max-line-length */
- /**
- * Converts a callback API to a function that returns an Observable.
- *
- * <span class="informal">Give it a function `f` of type `f(x, callback)` and
- * it will return a function `g` that when called as `g(x)` will output an
- * Observable.</span>
- *
- * `bindCallback` is not an operator because its input and output are not
- * Observables. The input is a function `func` with some parameters, the
- * last parameter must be a callback function that `func` calls when it is
- * done.
- *
- * The output of `bindCallback` is a function that takes the same parameters
- * as `func`, except the last one (the callback). When the output function
- * is called with arguments it will return an Observable. If function `func`
- * calls its callback with one argument the Observable will emit that value.
- * If on the other hand the callback is called with multiple values the resulting
- * Observable will emit an array with said values as arguments.
- *
- * It is very important to remember that input function `func` is not called
- * when the output function is, but rather when the Observable returned by the output
- * function is subscribed. This means if `func` makes an AJAX request, that request
- * will be made every time someone subscribes to the resulting Observable, but not before.
- *
- * Optionally, a selector function can be passed to `bindObservable`. The selector function
- * takes the same arguments as the callback and returns the value that will be emitted by the Observable.
- * Even though by default multiple arguments passed to callback appear in the stream as an array
- * the selector function will be called with arguments directly, just as the callback would.
- * This means you can imagine the default selector (when one is not provided explicitly)
- * as a function that aggregates all its arguments into an array, or simply returns first argument
- * if there is only one.
- *
- * The last optional parameter - {@link Scheduler} - can be used to control when the call
- * to `func` happens after someone subscribes to Observable, as well as when results
- * passed to callback will be emitted. By default, the subscription to an Observable calls `func`
- * synchronously, but using `Scheduler.async` as the last parameter will defer the call to `func`,
- * just like wrapping the call in `setTimeout` with a timeout of `0` would. If you use the async Scheduler
- * and call `subscribe` on the output Observable all function calls that are currently executing
- * will end before `func` is invoked.
- *
- * By default results passed to the callback are emitted immediately after `func` invokes the callback.
- * In particular, if the callback is called synchronously the subscription of the resulting Observable
- * will call the `next` function synchronously as well. If you want to defer that call,
- * you may use `Scheduler.async` just as before. This means that by using `Scheduler.async` you can
- * ensure that `func` always calls its callback asynchronously, thus avoiding terrifying Zalgo.
- *
- * Note that the Observable created by the output function will always emit a single value
- * and then complete immediately. If `func` calls the callback multiple times, values from subsequent
- * calls will not appear in the stream. If you need to listen for multiple calls,
- * you probably want to use {@link fromEvent} or {@link fromEventPattern} instead.
- *
- * If `func` depends on some context (`this` property) and is not already bound the context of `func`
- * will be the context that the output function has at call time. In particular, if `func`
- * is called as a method of some objec and if `func` is not already bound, in order to preserve the context
- * it is recommended that the context of the output function is set to that object as well.
- *
- * If the input function calls its callback in the "node style" (i.e. first argument to callback is
- * optional error parameter signaling whether the call failed or not), {@link bindNodeCallback}
- * provides convenient error handling and probably is a better choice.
- * `bindCallback` will treat such functions the same as any other and error parameters
- * (whether passed or not) will always be interpreted as regular callback argument.
- *
- *
- * @example <caption>Convert jQuery's getJSON to an Observable API</caption>
- * // Suppose we have jQuery.getJSON('/my/url', callback)
- * var getJSONAsObservable = Rx.Observable.bindCallback(jQuery.getJSON);
- * var result = getJSONAsObservable('/my/url');
- * result.subscribe(x => console.log(x), e => console.error(e));
- *
- *
- * @example <caption>Receive an array of arguments passed to a callback</caption>
- * someFunction((a, b, c) => {
- * console.log(a); // 5
- * console.log(b); // 'some string'
- * console.log(c); // {someProperty: 'someValue'}
- * });
- *
- * const boundSomeFunction = Rx.Observable.bindCallback(someFunction);
- * boundSomeFunction().subscribe(values => {
- * console.log(values) // [5, 'some string', {someProperty: 'someValue'}]
- * });
- *
- *
- * @example <caption>Use bindCallback with a selector function</caption>
- * someFunction((a, b, c) => {
- * console.log(a); // 'a'
- * console.log(b); // 'b'
- * console.log(c); // 'c'
- * });
- *
- * const boundSomeFunction = Rx.Observable.bindCallback(someFunction, (a, b, c) => a + b + c);
- * boundSomeFunction().subscribe(value => {
- * console.log(value) // 'abc'
- * });
- *
- *
- * @example <caption>Compare behaviour with and without async Scheduler</caption>
- * function iCallMyCallbackSynchronously(cb) {
- * cb();
- * }
- *
- * const boundSyncFn = Rx.Observable.bindCallback(iCallMyCallbackSynchronously);
- * const boundAsyncFn = Rx.Observable.bindCallback(iCallMyCallbackSynchronously, null, Rx.Scheduler.async);
- *
- * boundSyncFn().subscribe(() => console.log('I was sync!'));
- * boundAsyncFn().subscribe(() => console.log('I was async!'));
- * console.log('This happened...');
- *
- * // Logs:
- * // I was sync!
- * // This happened...
- * // I was async!
- *
- *
- * @example <caption>Use bindCallback on an object method</caption>
- * const boundMethod = Rx.Observable.bindCallback(someObject.methodWithCallback);
- * boundMethod.call(someObject) // make sure methodWithCallback has access to someObject
- * .subscribe(subscriber);
- *
- *
- * @see {@link bindNodeCallback}
- * @see {@link from}
- * @see {@link fromPromise}
- *
- * @param {function} func A function with a callback as the last parameter.
- * @param {function} [selector] A function which takes the arguments from the
- * callback and maps them to a value that is emitted on the output Observable.
- * @param {Scheduler} [scheduler] The scheduler on which to schedule the
- * callbacks.
- * @return {function(...params: *): Observable} A function which returns the
- * Observable that delivers the same values the callback would deliver.
- * @static true
- * @name bindCallback
- * @owner Observable
- */
- BoundCallbackObservable.create = function (func, selector, scheduler) {
- if (selector === void 0) { selector = undefined; }
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i - 0] = arguments[_i];
- }
- return new BoundCallbackObservable(func, selector, args, this, scheduler);
- };
- };
- /** @deprecated internal use only */ BoundCallbackObservable.prototype._subscribe = function (subscriber) {
- var callbackFunc = this.callbackFunc;
- var args = this.args;
- var scheduler = this.scheduler;
- var subject = this.subject;
- if (!scheduler) {
- if (!subject) {
- subject = this.subject = new AsyncSubject();
- var handler = function handlerFn() {
- var innerArgs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- innerArgs[_i - 0] = arguments[_i];
- }
- var source = handlerFn.source;
- var selector = source.selector, subject = source.subject;
- if (selector) {
- var result_1 = tryCatch(selector).apply(this, innerArgs);
- if (result_1 === errorObject) {
- subject.error(errorObject.e);
- }
- else {
- subject.next(result_1);
- subject.complete();
- }
- }
- else {
- subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
- subject.complete();
- }
- };
- // use named function instance to avoid closure.
- handler.source = this;
- var result = tryCatch(callbackFunc).apply(this.context, args.concat(handler));
- if (result === errorObject) {
- subject.error(errorObject.e);
- }
- }
- return subject.subscribe(subscriber);
- }
- else {
- return scheduler.schedule(BoundCallbackObservable.dispatch, 0, { source: this, subscriber: subscriber, context: this.context });
- }
- };
- BoundCallbackObservable.dispatch = function (state) {
- var self = this;
- var source = state.source, subscriber = state.subscriber, context = state.context;
- var callbackFunc = source.callbackFunc, args = source.args, scheduler = source.scheduler;
- var subject = source.subject;
- if (!subject) {
- subject = source.subject = new AsyncSubject();
- var handler = function handlerFn() {
- var innerArgs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- innerArgs[_i - 0] = arguments[_i];
- }
- var source = handlerFn.source;
- var selector = source.selector, subject = source.subject;
- if (selector) {
- var result_2 = tryCatch(selector).apply(this, innerArgs);
- if (result_2 === errorObject) {
- self.add(scheduler.schedule(dispatchError, 0, { err: errorObject.e, subject: subject }));
- }
- else {
- self.add(scheduler.schedule(dispatchNext, 0, { value: result_2, subject: subject }));
- }
- }
- else {
- var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
- self.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
- }
- };
- // use named function to pass values in without closure
- handler.source = source;
- var result = tryCatch(callbackFunc).apply(context, args.concat(handler));
- if (result === errorObject) {
- subject.error(errorObject.e);
- }
- }
- self.add(subject.subscribe(subscriber));
- };
- return BoundCallbackObservable;
- }(Observable));
- function dispatchNext(arg) {
- var value = arg.value, subject = arg.subject;
- subject.next(value);
- subject.complete();
- }
- function dispatchError(arg) {
- var err = arg.err, subject = arg.subject;
- subject.error(err);
- }
-
- var bindCallback = BoundCallbackObservable.create;
-
- Observable.bindCallback = bindCallback;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var BoundNodeCallbackObservable = (function (_super) {
- __extends(BoundNodeCallbackObservable, _super);
- function BoundNodeCallbackObservable(callbackFunc, selector, args, context, scheduler) {
- _super.call(this);
- this.callbackFunc = callbackFunc;
- this.selector = selector;
- this.args = args;
- this.context = context;
- this.scheduler = scheduler;
- }
- /* tslint:enable:max-line-length */
- /**
- * Converts a Node.js-style callback API to a function that returns an
- * Observable.
- *
- * <span class="informal">It's just like {@link bindCallback}, but the
- * callback is expected to be of type `callback(error, result)`.</span>
- *
- * `bindNodeCallback` is not an operator because its input and output are not
- * Observables. The input is a function `func` with some parameters, but the
- * last parameter must be a callback function that `func` calls when it is
- * done. The callback function is expected to follow Node.js conventions,
- * where the first argument to the callback is an error object, signaling
- * whether call was successful. If that object is passed to callback, it means
- * something went wrong.
- *
- * The output of `bindNodeCallback` is a function that takes the same
- * parameters as `func`, except the last one (the callback). When the output
- * function is called with arguments, it will return an Observable.
- * If `func` calls its callback with error parameter present, Observable will
- * error with that value as well. If error parameter is not passed, Observable will emit
- * second parameter. If there are more parameters (third and so on),
- * Observable will emit an array with all arguments, except first error argument.
- *
- * Optionally `bindNodeCallback` accepts selector function, which allows you to
- * make resulting Observable emit value computed by selector, instead of regular
- * callback arguments. It works similarly to {@link bindCallback} selector, but
- * Node.js-style error argument will never be passed to that function.
- *
- * Note that `func` will not be called at the same time output function is,
- * but rather whenever resulting Observable is subscribed. By default call to
- * `func` will happen synchronously after subscription, but that can be changed
- * with proper {@link Scheduler} provided as optional third parameter. Scheduler
- * can also control when values from callback will be emitted by Observable.
- * To find out more, check out documentation for {@link bindCallback}, where
- * Scheduler works exactly the same.
- *
- * As in {@link bindCallback}, context (`this` property) of input function will be set to context
- * of returned function, when it is called.
- *
- * After Observable emits value, it will complete immediately. This means
- * even if `func` calls callback again, values from second and consecutive
- * calls will never appear on the stream. If you need to handle functions
- * that call callbacks multiple times, check out {@link fromEvent} or
- * {@link fromEventPattern} instead.
- *
- * Note that `bindNodeCallback` can be used in non-Node.js environments as well.
- * "Node.js-style" callbacks are just a convention, so if you write for
- * browsers or any other environment and API you use implements that callback style,
- * `bindNodeCallback` can be safely used on that API functions as well.
- *
- * Remember that Error object passed to callback does not have to be an instance
- * of JavaScript built-in `Error` object. In fact, it does not even have to an object.
- * Error parameter of callback function is interpreted as "present", when value
- * of that parameter is truthy. It could be, for example, non-zero number, non-empty
- * string or boolean `true`. In all of these cases resulting Observable would error
- * with that value. This means usually regular style callbacks will fail very often when
- * `bindNodeCallback` is used. If your Observable errors much more often then you
- * would expect, check if callback really is called in Node.js-style and, if not,
- * switch to {@link bindCallback} instead.
- *
- * Note that even if error parameter is technically present in callback, but its value
- * is falsy, it still won't appear in array emitted by Observable or in selector function.
- *
- *
- * @example <caption>Read a file from the filesystem and get the data as an Observable</caption>
- * import * as fs from 'fs';
- * var readFileAsObservable = Rx.Observable.bindNodeCallback(fs.readFile);
- * var result = readFileAsObservable('./roadNames.txt', 'utf8');
- * result.subscribe(x => console.log(x), e => console.error(e));
- *
- *
- * @example <caption>Use on function calling callback with multiple arguments</caption>
- * someFunction((err, a, b) => {
- * console.log(err); // null
- * console.log(a); // 5
- * console.log(b); // "some string"
- * });
- * var boundSomeFunction = Rx.Observable.bindNodeCallback(someFunction);
- * boundSomeFunction()
- * .subscribe(value => {
- * console.log(value); // [5, "some string"]
- * });
- *
- *
- * @example <caption>Use with selector function</caption>
- * someFunction((err, a, b) => {
- * console.log(err); // undefined
- * console.log(a); // "abc"
- * console.log(b); // "DEF"
- * });
- * var boundSomeFunction = Rx.Observable.bindNodeCallback(someFunction, (a, b) => a + b);
- * boundSomeFunction()
- * .subscribe(value => {
- * console.log(value); // "abcDEF"
- * });
- *
- *
- * @example <caption>Use on function calling callback in regular style</caption>
- * someFunction(a => {
- * console.log(a); // 5
- * });
- * var boundSomeFunction = Rx.Observable.bindNodeCallback(someFunction);
- * boundSomeFunction()
- * .subscribe(
- * value => {} // never gets called
- * err => console.log(err) // 5
- *);
- *
- *
- * @see {@link bindCallback}
- * @see {@link from}
- * @see {@link fromPromise}
- *
- * @param {function} func Function with a Node.js-style callback as the last parameter.
- * @param {function} [selector] A function which takes the arguments from the
- * callback and maps those to a value to emit on the output Observable.
- * @param {Scheduler} [scheduler] The scheduler on which to schedule the
- * callbacks.
- * @return {function(...params: *): Observable} A function which returns the
- * Observable that delivers the same values the Node.js callback would
- * deliver.
- * @static true
- * @name bindNodeCallback
- * @owner Observable
- */
- BoundNodeCallbackObservable.create = function (func, selector, scheduler) {
- if (selector === void 0) { selector = undefined; }
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i - 0] = arguments[_i];
- }
- return new BoundNodeCallbackObservable(func, selector, args, this, scheduler);
- };
- };
- /** @deprecated internal use only */ BoundNodeCallbackObservable.prototype._subscribe = function (subscriber) {
- var callbackFunc = this.callbackFunc;
- var args = this.args;
- var scheduler = this.scheduler;
- var subject = this.subject;
- if (!scheduler) {
- if (!subject) {
- subject = this.subject = new AsyncSubject();
- var handler = function handlerFn() {
- var innerArgs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- innerArgs[_i - 0] = arguments[_i];
- }
- var source = handlerFn.source;
- var selector = source.selector, subject = source.subject;
- var err = innerArgs.shift();
- if (err) {
- subject.error(err);
- }
- else if (selector) {
- var result_1 = tryCatch(selector).apply(this, innerArgs);
- if (result_1 === errorObject) {
- subject.error(errorObject.e);
- }
- else {
- subject.next(result_1);
- subject.complete();
- }
- }
- else {
- subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
- subject.complete();
- }
- };
- // use named function instance to avoid closure.
- handler.source = this;
- var result = tryCatch(callbackFunc).apply(this.context, args.concat(handler));
- if (result === errorObject) {
- subject.error(errorObject.e);
- }
- }
- return subject.subscribe(subscriber);
- }
- else {
- return scheduler.schedule(dispatch, 0, { source: this, subscriber: subscriber, context: this.context });
- }
- };
- return BoundNodeCallbackObservable;
- }(Observable));
- function dispatch(state) {
- var self = this;
- var source = state.source, subscriber = state.subscriber, context = state.context;
- // XXX: cast to `any` to access to the private field in `source`.
- var _a = source, callbackFunc = _a.callbackFunc, args = _a.args, scheduler = _a.scheduler;
- var subject = source.subject;
- if (!subject) {
- subject = source.subject = new AsyncSubject();
- var handler = function handlerFn() {
- var innerArgs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- innerArgs[_i - 0] = arguments[_i];
- }
- var source = handlerFn.source;
- var selector = source.selector, subject = source.subject;
- var err = innerArgs.shift();
- if (err) {
- self.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
- }
- else if (selector) {
- var result_2 = tryCatch(selector).apply(this, innerArgs);
- if (result_2 === errorObject) {
- self.add(scheduler.schedule(dispatchError$1, 0, { err: errorObject.e, subject: subject }));
- }
- else {
- self.add(scheduler.schedule(dispatchNext$1, 0, { value: result_2, subject: subject }));
- }
- }
- else {
- var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
- self.add(scheduler.schedule(dispatchNext$1, 0, { value: value, subject: subject }));
- }
- };
- // use named function to pass values in without closure
- handler.source = source;
- var result = tryCatch(callbackFunc).apply(context, args.concat(handler));
- if (result === errorObject) {
- self.add(scheduler.schedule(dispatchError$1, 0, { err: errorObject.e, subject: subject }));
- }
- }
- self.add(subject.subscribe(subscriber));
- }
- function dispatchNext$1(arg) {
- var value = arg.value, subject = arg.subject;
- subject.next(value);
- subject.complete();
- }
- function dispatchError$1(arg) {
- var err = arg.err, subject = arg.subject;
- subject.error(err);
- }
-
- var bindNodeCallback = BoundNodeCallbackObservable.create;
-
- Observable.bindNodeCallback = bindNodeCallback;
-
- function isScheduler(value) {
- return value && typeof value.schedule === 'function';
- }
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var ScalarObservable = (function (_super) {
- __extends(ScalarObservable, _super);
- function ScalarObservable(value, scheduler) {
- _super.call(this);
- this.value = value;
- this.scheduler = scheduler;
- this._isScalar = true;
- if (scheduler) {
- this._isScalar = false;
- }
- }
- ScalarObservable.create = function (value, scheduler) {
- return new ScalarObservable(value, scheduler);
- };
- ScalarObservable.dispatch = function (state) {
- var done = state.done, value = state.value, subscriber = state.subscriber;
- if (done) {
- subscriber.complete();
- return;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- return;
- }
- state.done = true;
- this.schedule(state);
- };
- /** @deprecated internal use only */ ScalarObservable.prototype._subscribe = function (subscriber) {
- var value = this.value;
- var scheduler = this.scheduler;
- if (scheduler) {
- return scheduler.schedule(ScalarObservable.dispatch, 0, {
- done: false, value: value, subscriber: subscriber
- });
- }
- else {
- subscriber.next(value);
- if (!subscriber.closed) {
- subscriber.complete();
- }
- }
- };
- return ScalarObservable;
- }(Observable));
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var EmptyObservable = (function (_super) {
- __extends(EmptyObservable, _super);
- function EmptyObservable(scheduler) {
- _super.call(this);
- this.scheduler = scheduler;
- }
- /**
- * Creates an Observable that emits no items to the Observer and immediately
- * emits a complete notification.
- *
- * <span class="informal">Just emits 'complete', and nothing else.
- * </span>
- *
- * <img src="./img/empty.png" width="100%">
- *
- * This static operator is useful for creating a simple Observable that only
- * emits the complete notification. It can be used for composing with other
- * Observables, such as in a {@link mergeMap}.
- *
- * @example <caption>Emit the number 7, then complete.</caption>
- * var result = Rx.Observable.empty().startWith(7);
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Map and flatten only odd numbers to the sequence 'a', 'b', 'c'</caption>
- * var interval = Rx.Observable.interval(1000);
- * var result = interval.mergeMap(x =>
- * x % 2 === 1 ? Rx.Observable.of('a', 'b', 'c') : Rx.Observable.empty()
- * );
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following to the console:
- * // x is equal to the count on the interval eg(0,1,2,3,...)
- * // x will occur every 1000ms
- * // if x % 2 is equal to 1 print abc
- * // if x % 2 is not equal to 1 nothing will be output
- *
- * @see {@link create}
- * @see {@link never}
- * @see {@link of}
- * @see {@link throw}
- *
- * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
- * the emission of the complete notification.
- * @return {Observable} An "empty" Observable: emits only the complete
- * notification.
- * @static true
- * @name empty
- * @owner Observable
- */
- EmptyObservable.create = function (scheduler) {
- return new EmptyObservable(scheduler);
- };
- EmptyObservable.dispatch = function (arg) {
- var subscriber = arg.subscriber;
- subscriber.complete();
- };
- /** @deprecated internal use only */ EmptyObservable.prototype._subscribe = function (subscriber) {
- var scheduler = this.scheduler;
- if (scheduler) {
- return scheduler.schedule(EmptyObservable.dispatch, 0, { subscriber: subscriber });
- }
- else {
- subscriber.complete();
- }
- };
- return EmptyObservable;
- }(Observable));
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var ArrayObservable = (function (_super) {
- __extends(ArrayObservable, _super);
- function ArrayObservable(array, scheduler) {
- _super.call(this);
- this.array = array;
- this.scheduler = scheduler;
- if (!scheduler && array.length === 1) {
- this._isScalar = true;
- this.value = array[0];
- }
- }
- ArrayObservable.create = function (array, scheduler) {
- return new ArrayObservable(array, scheduler);
- };
- /**
- * Creates an Observable that emits some values you specify as arguments,
- * immediately one after the other, and then emits a complete notification.
- *
- * <span class="informal">Emits the arguments you provide, then completes.
- * </span>
- *
- * <img src="./img/of.png" width="100%">
- *
- * This static operator is useful for creating a simple Observable that only
- * emits the arguments given, and the complete notification thereafter. It can
- * be used for composing with other Observables, such as with {@link concat}.
- * By default, it uses a `null` IScheduler, which means the `next`
- * notifications are sent synchronously, although with a different IScheduler
- * it is possible to determine when those notifications will be delivered.
- *
- * @example <caption>Emit 10, 20, 30, then 'a', 'b', 'c', then start ticking every second.</caption>
- * var numbers = Rx.Observable.of(10, 20, 30);
- * var letters = Rx.Observable.of('a', 'b', 'c');
- * var interval = Rx.Observable.interval(1000);
- * var result = numbers.concat(letters).concat(interval);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link create}
- * @see {@link empty}
- * @see {@link never}
- * @see {@link throw}
- *
- * @param {...T} values Arguments that represent `next` values to be emitted.
- * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
- * the emissions of the `next` notifications.
- * @return {Observable<T>} An Observable that emits each given input value.
- * @static true
- * @name of
- * @owner Observable
- */
- ArrayObservable.of = function () {
- var array = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- array[_i - 0] = arguments[_i];
- }
- var scheduler = array[array.length - 1];
- if (isScheduler(scheduler)) {
- array.pop();
- }
- else {
- scheduler = null;
- }
- var len = array.length;
- if (len > 1) {
- return new ArrayObservable(array, scheduler);
- }
- else if (len === 1) {
- return new ScalarObservable(array[0], scheduler);
- }
- else {
- return new EmptyObservable(scheduler);
- }
- };
- ArrayObservable.dispatch = function (state) {
- var array = state.array, index = state.index, count = state.count, subscriber = state.subscriber;
- if (index >= count) {
- subscriber.complete();
- return;
- }
- subscriber.next(array[index]);
- if (subscriber.closed) {
- return;
- }
- state.index = index + 1;
- this.schedule(state);
- };
- /** @deprecated internal use only */ ArrayObservable.prototype._subscribe = function (subscriber) {
- var index = 0;
- var array = this.array;
- var count = array.length;
- var scheduler = this.scheduler;
- if (scheduler) {
- return scheduler.schedule(ArrayObservable.dispatch, 0, {
- array: array, index: index, count: count, subscriber: subscriber
- });
- }
- else {
- for (var i = 0; i < count && !subscriber.closed; i++) {
- subscriber.next(array[i]);
- }
- subscriber.complete();
- }
- };
- return ArrayObservable;
- }(Observable));
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var OuterSubscriber = (function (_super) {
- __extends(OuterSubscriber, _super);
- function OuterSubscriber() {
- _super.apply(this, arguments);
- }
- OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.destination.next(innerValue);
- };
- OuterSubscriber.prototype.notifyError = function (error, innerSub) {
- this.destination.error(error);
- };
- OuterSubscriber.prototype.notifyComplete = function (innerSub) {
- this.destination.complete();
- };
- return OuterSubscriber;
- }(Subscriber));
-
- var isArrayLike = (function (x) { return x && typeof x.length === 'number'; });
-
- function isPromise(value) {
- return value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
- }
-
- function symbolIteratorPonyfill(root$$1) {
- var Symbol = root$$1.Symbol;
- if (typeof Symbol === 'function') {
- if (!Symbol.iterator) {
- Symbol.iterator = Symbol('iterator polyfill');
- }
- return Symbol.iterator;
- }
- else {
- // [for Mozilla Gecko 27-35:](https://mzl.la/2ewE1zC)
- var Set_1 = root$$1.Set;
- if (Set_1 && typeof new Set_1()['@@iterator'] === 'function') {
- return '@@iterator';
- }
- var Map_1 = root$$1.Map;
- // required for compatability with es6-shim
- if (Map_1) {
- var keys = Object.getOwnPropertyNames(Map_1.prototype);
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- // according to spec, Map.prototype[@@iterator] and Map.orototype.entries must be equal.
- if (key !== 'entries' && key !== 'size' && Map_1.prototype[key] === Map_1.prototype['entries']) {
- return key;
- }
- }
- }
- return '@@iterator';
- }
- }
- var iterator = symbolIteratorPonyfill(_root);
- /**
- * @deprecated use iterator instead
- */
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var InnerSubscriber = (function (_super) {
- __extends(InnerSubscriber, _super);
- function InnerSubscriber(parent, outerValue, outerIndex) {
- _super.call(this);
- this.parent = parent;
- this.outerValue = outerValue;
- this.outerIndex = outerIndex;
- this.index = 0;
- }
- InnerSubscriber.prototype._next = function (value) {
- this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this);
- };
- InnerSubscriber.prototype._error = function (error) {
- this.parent.notifyError(error, this);
- this.unsubscribe();
- };
- InnerSubscriber.prototype._complete = function () {
- this.parent.notifyComplete(this);
- this.unsubscribe();
- };
- return InnerSubscriber;
- }(Subscriber));
-
- function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) {
- var destination = new InnerSubscriber(outerSubscriber, outerValue, outerIndex);
- if (destination.closed) {
- return null;
- }
- if (result instanceof Observable) {
- if (result._isScalar) {
- destination.next(result.value);
- destination.complete();
- return null;
- }
- else {
- destination.syncErrorThrowable = true;
- return result.subscribe(destination);
- }
- }
- else if (isArrayLike(result)) {
- for (var i = 0, len = result.length; i < len && !destination.closed; i++) {
- destination.next(result[i]);
- }
- if (!destination.closed) {
- destination.complete();
- }
- }
- else if (isPromise(result)) {
- result.then(function (value) {
- if (!destination.closed) {
- destination.next(value);
- destination.complete();
- }
- }, function (err) { return destination.error(err); })
- .then(null, function (err) {
- // Escaping the Promise trap: globally throw unhandled errors
- _root.setTimeout(function () { throw err; });
- });
- return destination;
- }
- else if (result && typeof result[iterator] === 'function') {
- var iterator$$1 = result[iterator]();
- do {
- var item = iterator$$1.next();
- if (item.done) {
- destination.complete();
- break;
- }
- destination.next(item.value);
- if (destination.closed) {
- break;
- }
- } while (true);
- }
- else if (result && typeof result[observable] === 'function') {
- var obs = result[observable]();
- if (typeof obs.subscribe !== 'function') {
- destination.error(new TypeError('Provided object does not correctly implement Symbol.observable'));
- }
- else {
- return obs.subscribe(new InnerSubscriber(outerSubscriber, outerValue, outerIndex));
- }
- }
- else {
- var value = isObject(result) ? 'an invalid object' : "'" + result + "'";
- var msg = ("You provided " + value + " where a stream was expected.")
- + ' You can provide an Observable, Promise, Array, or Iterable.';
- destination.error(new TypeError(msg));
- }
- return null;
- }
-
- var none = {};
- /* tslint:enable:max-line-length */
- /**
- * Combines multiple Observables to create an Observable whose values are
- * calculated from the latest values of each of its input Observables.
- *
- * <span class="informal">Whenever any input Observable emits a value, it
- * computes a formula using the latest values from all the inputs, then emits
- * the output of that formula.</span>
- *
- * <img src="./img/combineLatest.png" width="100%">
- *
- * `combineLatest` combines the values from this Observable with values from
- * Observables passed as arguments. This is done by subscribing to each
- * Observable, in order, and collecting an array of each of the most recent
- * values any time any of the input Observables emits, then either taking that
- * array and passing it as arguments to an optional `project` function and
- * emitting the return value of that, or just emitting the array of recent
- * values directly if there is no `project` function.
- *
- * @example <caption>Dynamically calculate the Body-Mass Index from an Observable of weight and one for height</caption>
- * var weight = Rx.Observable.of(70, 72, 76, 79, 75);
- * var height = Rx.Observable.of(1.76, 1.77, 1.78);
- * var bmi = weight.combineLatest(height, (w, h) => w / (h * h));
- * bmi.subscribe(x => console.log('BMI is ' + x));
- *
- * // With output to console:
- * // BMI is 24.212293388429753
- * // BMI is 23.93948099205209
- * // BMI is 23.671253629592222
- *
- * @see {@link combineAll}
- * @see {@link merge}
- * @see {@link withLatestFrom}
- *
- * @param {ObservableInput} other An input Observable to combine with the source
- * Observable. More than one input Observables may be given as argument.
- * @param {function} [project] An optional function to project the values from
- * the combined latest values into a new value on the output Observable.
- * @return {Observable} An Observable of projected values from the most recent
- * values from each input Observable, or an array of the most recent values from
- * each input Observable.
- * @method combineLatest
- * @owner Observable
- */
- function combineLatest$1() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- var project = null;
- if (typeof observables[observables.length - 1] === 'function') {
- project = observables.pop();
- }
- // if the first and only other argument besides the resultSelector is an array
- // assume it's been called with `combineLatest([obs1, obs2, obs3], project)`
- if (observables.length === 1 && isArray(observables[0])) {
- observables = observables[0].slice();
- }
- return function (source) { return source.lift.call(new ArrayObservable([source].concat(observables)), new CombineLatestOperator(project)); };
- }
- var CombineLatestOperator = (function () {
- function CombineLatestOperator(project) {
- this.project = project;
- }
- CombineLatestOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new CombineLatestSubscriber(subscriber, this.project));
- };
- return CombineLatestOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var CombineLatestSubscriber = (function (_super) {
- __extends(CombineLatestSubscriber, _super);
- function CombineLatestSubscriber(destination, project) {
- _super.call(this, destination);
- this.project = project;
- this.active = 0;
- this.values = [];
- this.observables = [];
- }
- CombineLatestSubscriber.prototype._next = function (observable) {
- this.values.push(none);
- this.observables.push(observable);
- };
- CombineLatestSubscriber.prototype._complete = function () {
- var observables = this.observables;
- var len = observables.length;
- if (len === 0) {
- this.destination.complete();
- }
- else {
- this.active = len;
- this.toRespond = len;
- for (var i = 0; i < len; i++) {
- var observable = observables[i];
- this.add(subscribeToResult(this, observable, observable, i));
- }
- }
- };
- CombineLatestSubscriber.prototype.notifyComplete = function (unused) {
- if ((this.active -= 1) === 0) {
- this.destination.complete();
- }
- };
- CombineLatestSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var values = this.values;
- var oldVal = values[outerIndex];
- var toRespond = !this.toRespond
- ? 0
- : oldVal === none ? --this.toRespond : this.toRespond;
- values[outerIndex] = innerValue;
- if (toRespond === 0) {
- if (this.project) {
- this._tryProject(values);
- }
- else {
- this.destination.next(values.slice());
- }
- }
- };
- CombineLatestSubscriber.prototype._tryProject = function (values) {
- var result;
- try {
- result = this.project.apply(this, values);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.destination.next(result);
- };
- return CombineLatestSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Combines multiple Observables to create an Observable whose values are
- * calculated from the latest values of each of its input Observables.
- *
- * <span class="informal">Whenever any input Observable emits a value, it
- * computes a formula using the latest values from all the inputs, then emits
- * the output of that formula.</span>
- *
- * <img src="./img/combineLatest.png" width="100%">
- *
- * `combineLatest` combines the values from all the Observables passed as
- * arguments. This is done by subscribing to each Observable in order and,
- * whenever any Observable emits, collecting an array of the most recent
- * values from each Observable. So if you pass `n` Observables to operator,
- * returned Observable will always emit an array of `n` values, in order
- * corresponding to order of passed Observables (value from the first Observable
- * on the first place and so on).
- *
- * Static version of `combineLatest` accepts either an array of Observables
- * or each Observable can be put directly as an argument. Note that array of
- * Observables is good choice, if you don't know beforehand how many Observables
- * you will combine. Passing empty array will result in Observable that
- * completes immediately.
- *
- * To ensure output array has always the same length, `combineLatest` will
- * actually wait for all input Observables to emit at least once,
- * before it starts emitting results. This means if some Observable emits
- * values before other Observables started emitting, all that values but last
- * will be lost. On the other hand, is some Observable does not emit value but
- * completes, resulting Observable will complete at the same moment without
- * emitting anything, since it will be now impossible to include value from
- * completed Observable in resulting array. Also, if some input Observable does
- * not emit any value and never completes, `combineLatest` will also never emit
- * and never complete, since, again, it will wait for all streams to emit some
- * value.
- *
- * If at least one Observable was passed to `combineLatest` and all passed Observables
- * emitted something, resulting Observable will complete when all combined
- * streams complete. So even if some Observable completes, result of
- * `combineLatest` will still emit values when other Observables do. In case
- * of completed Observable, its value from now on will always be the last
- * emitted value. On the other hand, if any Observable errors, `combineLatest`
- * will error immediately as well, and all other Observables will be unsubscribed.
- *
- * `combineLatest` accepts as optional parameter `project` function, which takes
- * as arguments all values that would normally be emitted by resulting Observable.
- * `project` can return any kind of value, which will be then emitted by Observable
- * instead of default array. Note that `project` does not take as argument that array
- * of values, but values themselves. That means default `project` can be imagined
- * as function that takes all its arguments and puts them into an array.
- *
- *
- * @example <caption>Combine two timer Observables</caption>
- * const firstTimer = Rx.Observable.timer(0, 1000); // emit 0, 1, 2... after every second, starting from now
- * const secondTimer = Rx.Observable.timer(500, 1000); // emit 0, 1, 2... after every second, starting 0,5s from now
- * const combinedTimers = Rx.Observable.combineLatest(firstTimer, secondTimer);
- * combinedTimers.subscribe(value => console.log(value));
- * // Logs
- * // [0, 0] after 0.5s
- * // [1, 0] after 1s
- * // [1, 1] after 1.5s
- * // [2, 1] after 2s
- *
- *
- * @example <caption>Combine an array of Observables</caption>
- * const observables = [1, 5, 10].map(
- * n => Rx.Observable.of(n).delay(n * 1000).startWith(0) // emit 0 and then emit n after n seconds
- * );
- * const combined = Rx.Observable.combineLatest(observables);
- * combined.subscribe(value => console.log(value));
- * // Logs
- * // [0, 0, 0] immediately
- * // [1, 0, 0] after 1s
- * // [1, 5, 0] after 5s
- * // [1, 5, 10] after 10s
- *
- *
- * @example <caption>Use project function to dynamically calculate the Body-Mass Index</caption>
- * var weight = Rx.Observable.of(70, 72, 76, 79, 75);
- * var height = Rx.Observable.of(1.76, 1.77, 1.78);
- * var bmi = Rx.Observable.combineLatest(weight, height, (w, h) => w / (h * h));
- * bmi.subscribe(x => console.log('BMI is ' + x));
- *
- * // With output to console:
- * // BMI is 24.212293388429753
- * // BMI is 23.93948099205209
- * // BMI is 23.671253629592222
- *
- *
- * @see {@link combineAll}
- * @see {@link merge}
- * @see {@link withLatestFrom}
- *
- * @param {ObservableInput} observable1 An input Observable to combine with other Observables.
- * @param {ObservableInput} observable2 An input Observable to combine with other Observables.
- * More than one input Observables may be given as arguments
- * or an array of Observables may be given as the first argument.
- * @param {function} [project] An optional function to project the values from
- * the combined latest values into a new value on the output Observable.
- * @param {Scheduler} [scheduler=null] The IScheduler to use for subscribing to
- * each input Observable.
- * @return {Observable} An Observable of projected values from the most recent
- * values from each input Observable, or an array of the most recent values from
- * each input Observable.
- * @static true
- * @name combineLatest
- * @owner Observable
- */
- function combineLatest$$1() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- var project = null;
- var scheduler = null;
- if (isScheduler(observables[observables.length - 1])) {
- scheduler = observables.pop();
- }
- if (typeof observables[observables.length - 1] === 'function') {
- project = observables.pop();
- }
- // if the first and only other argument besides the resultSelector is an array
- // assume it's been called with `combineLatest([obs1, obs2, obs3], project)`
- if (observables.length === 1 && isArray(observables[0])) {
- observables = observables[0];
- }
- return new ArrayObservable(observables, scheduler).lift(new CombineLatestOperator(project));
- }
-
- Observable.combineLatest = combineLatest$$1;
-
- var of = ArrayObservable.of;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var PromiseObservable = (function (_super) {
- __extends(PromiseObservable, _super);
- function PromiseObservable(promise, scheduler) {
- _super.call(this);
- this.promise = promise;
- this.scheduler = scheduler;
- }
- /**
- * Converts a Promise to an Observable.
- *
- * <span class="informal">Returns an Observable that just emits the Promise's
- * resolved value, then completes.</span>
- *
- * Converts an ES2015 Promise or a Promises/A+ spec compliant Promise to an
- * Observable. If the Promise resolves with a value, the output Observable
- * emits that resolved value as a `next`, and then completes. If the Promise
- * is rejected, then the output Observable emits the corresponding Error.
- *
- * @example <caption>Convert the Promise returned by Fetch to an Observable</caption>
- * var result = Rx.Observable.fromPromise(fetch('http://myserver.com/'));
- * result.subscribe(x => console.log(x), e => console.error(e));
- *
- * @see {@link bindCallback}
- * @see {@link from}
- *
- * @param {PromiseLike<T>} promise The promise to be converted.
- * @param {Scheduler} [scheduler] An optional IScheduler to use for scheduling
- * the delivery of the resolved value (or the rejection).
- * @return {Observable<T>} An Observable which wraps the Promise.
- * @static true
- * @name fromPromise
- * @owner Observable
- */
- PromiseObservable.create = function (promise, scheduler) {
- return new PromiseObservable(promise, scheduler);
- };
- /** @deprecated internal use only */ PromiseObservable.prototype._subscribe = function (subscriber) {
- var _this = this;
- var promise = this.promise;
- var scheduler = this.scheduler;
- if (scheduler == null) {
- if (this._isScalar) {
- if (!subscriber.closed) {
- subscriber.next(this.value);
- subscriber.complete();
- }
- }
- else {
- promise.then(function (value) {
- _this.value = value;
- _this._isScalar = true;
- if (!subscriber.closed) {
- subscriber.next(value);
- subscriber.complete();
- }
- }, function (err) {
- if (!subscriber.closed) {
- subscriber.error(err);
- }
- })
- .then(null, function (err) {
- // escape the promise trap, throw unhandled errors
- _root.setTimeout(function () { throw err; });
- });
- }
- }
- else {
- if (this._isScalar) {
- if (!subscriber.closed) {
- return scheduler.schedule(dispatchNext$2, 0, { value: this.value, subscriber: subscriber });
- }
- }
- else {
- promise.then(function (value) {
- _this.value = value;
- _this._isScalar = true;
- if (!subscriber.closed) {
- subscriber.add(scheduler.schedule(dispatchNext$2, 0, { value: value, subscriber: subscriber }));
- }
- }, function (err) {
- if (!subscriber.closed) {
- subscriber.add(scheduler.schedule(dispatchError$2, 0, { err: err, subscriber: subscriber }));
- }
- })
- .then(null, function (err) {
- // escape the promise trap, throw unhandled errors
- _root.setTimeout(function () { throw err; });
- });
- }
- }
- };
- return PromiseObservable;
- }(Observable));
- function dispatchNext$2(arg) {
- var value = arg.value, subscriber = arg.subscriber;
- if (!subscriber.closed) {
- subscriber.next(value);
- subscriber.complete();
- }
- }
- function dispatchError$2(arg) {
- var err = arg.err, subscriber = arg.subscriber;
- if (!subscriber.closed) {
- subscriber.error(err);
- }
- }
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var IteratorObservable = (function (_super) {
- __extends(IteratorObservable, _super);
- function IteratorObservable(iterator$$1, scheduler) {
- _super.call(this);
- this.scheduler = scheduler;
- if (iterator$$1 == null) {
- throw new Error('iterator cannot be null.');
- }
- this.iterator = getIterator(iterator$$1);
- }
- IteratorObservable.create = function (iterator$$1, scheduler) {
- return new IteratorObservable(iterator$$1, scheduler);
- };
- IteratorObservable.dispatch = function (state) {
- var index = state.index, hasError = state.hasError, iterator$$1 = state.iterator, subscriber = state.subscriber;
- if (hasError) {
- subscriber.error(state.error);
- return;
- }
- var result = iterator$$1.next();
- if (result.done) {
- subscriber.complete();
- return;
- }
- subscriber.next(result.value);
- state.index = index + 1;
- if (subscriber.closed) {
- if (typeof iterator$$1.return === 'function') {
- iterator$$1.return();
- }
- return;
- }
- this.schedule(state);
- };
- /** @deprecated internal use only */ IteratorObservable.prototype._subscribe = function (subscriber) {
- var index = 0;
- var _a = this, iterator$$1 = _a.iterator, scheduler = _a.scheduler;
- if (scheduler) {
- return scheduler.schedule(IteratorObservable.dispatch, 0, {
- index: index, iterator: iterator$$1, subscriber: subscriber
- });
- }
- else {
- do {
- var result = iterator$$1.next();
- if (result.done) {
- subscriber.complete();
- break;
- }
- else {
- subscriber.next(result.value);
- }
- if (subscriber.closed) {
- if (typeof iterator$$1.return === 'function') {
- iterator$$1.return();
- }
- break;
- }
- } while (true);
- }
- };
- return IteratorObservable;
- }(Observable));
- var StringIterator = (function () {
- function StringIterator(str, idx, len) {
- if (idx === void 0) { idx = 0; }
- if (len === void 0) { len = str.length; }
- this.str = str;
- this.idx = idx;
- this.len = len;
- }
- StringIterator.prototype[iterator] = function () { return (this); };
- StringIterator.prototype.next = function () {
- return this.idx < this.len ? {
- done: false,
- value: this.str.charAt(this.idx++)
- } : {
- done: true,
- value: undefined
- };
- };
- return StringIterator;
- }());
- var ArrayIterator = (function () {
- function ArrayIterator(arr, idx, len) {
- if (idx === void 0) { idx = 0; }
- if (len === void 0) { len = toLength(arr); }
- this.arr = arr;
- this.idx = idx;
- this.len = len;
- }
- ArrayIterator.prototype[iterator] = function () { return this; };
- ArrayIterator.prototype.next = function () {
- return this.idx < this.len ? {
- done: false,
- value: this.arr[this.idx++]
- } : {
- done: true,
- value: undefined
- };
- };
- return ArrayIterator;
- }());
- function getIterator(obj) {
- var i = obj[iterator];
- if (!i && typeof obj === 'string') {
- return new StringIterator(obj);
- }
- if (!i && obj.length !== undefined) {
- return new ArrayIterator(obj);
- }
- if (!i) {
- throw new TypeError('object is not iterable');
- }
- return obj[iterator]();
- }
- var maxSafeInteger = Math.pow(2, 53) - 1;
- function toLength(o) {
- var len = +o.length;
- if (isNaN(len)) {
- return 0;
- }
- if (len === 0 || !numberIsFinite(len)) {
- return len;
- }
- len = sign(len) * Math.floor(Math.abs(len));
- if (len <= 0) {
- return 0;
- }
- if (len > maxSafeInteger) {
- return maxSafeInteger;
- }
- return len;
- }
- function numberIsFinite(value) {
- return typeof value === 'number' && _root.isFinite(value);
- }
- function sign(value) {
- var valueAsNumber = +value;
- if (valueAsNumber === 0) {
- return valueAsNumber;
- }
- if (isNaN(valueAsNumber)) {
- return valueAsNumber;
- }
- return valueAsNumber < 0 ? -1 : 1;
- }
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var ArrayLikeObservable = (function (_super) {
- __extends(ArrayLikeObservable, _super);
- function ArrayLikeObservable(arrayLike, scheduler) {
- _super.call(this);
- this.arrayLike = arrayLike;
- this.scheduler = scheduler;
- if (!scheduler && arrayLike.length === 1) {
- this._isScalar = true;
- this.value = arrayLike[0];
- }
- }
- ArrayLikeObservable.create = function (arrayLike, scheduler) {
- var length = arrayLike.length;
- if (length === 0) {
- return new EmptyObservable();
- }
- else if (length === 1) {
- return new ScalarObservable(arrayLike[0], scheduler);
- }
- else {
- return new ArrayLikeObservable(arrayLike, scheduler);
- }
- };
- ArrayLikeObservable.dispatch = function (state) {
- var arrayLike = state.arrayLike, index = state.index, length = state.length, subscriber = state.subscriber;
- if (subscriber.closed) {
- return;
- }
- if (index >= length) {
- subscriber.complete();
- return;
- }
- subscriber.next(arrayLike[index]);
- state.index = index + 1;
- this.schedule(state);
- };
- /** @deprecated internal use only */ ArrayLikeObservable.prototype._subscribe = function (subscriber) {
- var index = 0;
- var _a = this, arrayLike = _a.arrayLike, scheduler = _a.scheduler;
- var length = arrayLike.length;
- if (scheduler) {
- return scheduler.schedule(ArrayLikeObservable.dispatch, 0, {
- arrayLike: arrayLike, index: index, length: length, subscriber: subscriber
- });
- }
- else {
- for (var i = 0; i < length && !subscriber.closed; i++) {
- subscriber.next(arrayLike[i]);
- }
- subscriber.complete();
- }
- };
- return ArrayLikeObservable;
- }(Observable));
-
- /**
- * Represents a push-based event or value that an {@link Observable} can emit.
- * This class is particularly useful for operators that manage notifications,
- * like {@link materialize}, {@link dematerialize}, {@link observeOn}, and
- * others. Besides wrapping the actual delivered value, it also annotates it
- * with metadata of, for instance, what type of push message it is (`next`,
- * `error`, or `complete`).
- *
- * @see {@link materialize}
- * @see {@link dematerialize}
- * @see {@link observeOn}
- *
- * @class Notification<T>
- */
- var Notification = (function () {
- function Notification(kind, value, error) {
- this.kind = kind;
- this.value = value;
- this.error = error;
- this.hasValue = kind === 'N';
- }
- /**
- * Delivers to the given `observer` the value wrapped by this Notification.
- * @param {Observer} observer
- * @return
- */
- Notification.prototype.observe = function (observer) {
- switch (this.kind) {
- case 'N':
- return observer.next && observer.next(this.value);
- case 'E':
- return observer.error && observer.error(this.error);
- case 'C':
- return observer.complete && observer.complete();
- }
- };
- /**
- * Given some {@link Observer} callbacks, deliver the value represented by the
- * current Notification to the correctly corresponding callback.
- * @param {function(value: T): void} next An Observer `next` callback.
- * @param {function(err: any): void} [error] An Observer `error` callback.
- * @param {function(): void} [complete] An Observer `complete` callback.
- * @return {any}
- */
- Notification.prototype.do = function (next, error, complete) {
- var kind = this.kind;
- switch (kind) {
- case 'N':
- return next && next(this.value);
- case 'E':
- return error && error(this.error);
- case 'C':
- return complete && complete();
- }
- };
- /**
- * Takes an Observer or its individual callback functions, and calls `observe`
- * or `do` methods accordingly.
- * @param {Observer|function(value: T): void} nextOrObserver An Observer or
- * the `next` callback.
- * @param {function(err: any): void} [error] An Observer `error` callback.
- * @param {function(): void} [complete] An Observer `complete` callback.
- * @return {any}
- */
- Notification.prototype.accept = function (nextOrObserver, error, complete) {
- if (nextOrObserver && typeof nextOrObserver.next === 'function') {
- return this.observe(nextOrObserver);
- }
- else {
- return this.do(nextOrObserver, error, complete);
- }
- };
- /**
- * Returns a simple Observable that just delivers the notification represented
- * by this Notification instance.
- * @return {any}
- */
- Notification.prototype.toObservable = function () {
- var kind = this.kind;
- switch (kind) {
- case 'N':
- return Observable.of(this.value);
- case 'E':
- return Observable.throw(this.error);
- case 'C':
- return Observable.empty();
- }
- throw new Error('unexpected notification kind value');
- };
- /**
- * A shortcut to create a Notification instance of the type `next` from a
- * given value.
- * @param {T} value The `next` value.
- * @return {Notification<T>} The "next" Notification representing the
- * argument.
- */
- Notification.createNext = function (value) {
- if (typeof value !== 'undefined') {
- return new Notification('N', value);
- }
- return Notification.undefinedValueNotification;
- };
- /**
- * A shortcut to create a Notification instance of the type `error` from a
- * given error.
- * @param {any} [err] The `error` error.
- * @return {Notification<T>} The "error" Notification representing the
- * argument.
- */
- Notification.createError = function (err) {
- return new Notification('E', undefined, err);
- };
- /**
- * A shortcut to create a Notification instance of the type `complete`.
- * @return {Notification<any>} The valueless "complete" Notification.
- */
- Notification.createComplete = function () {
- return Notification.completeNotification;
- };
- Notification.completeNotification = new Notification('C');
- Notification.undefinedValueNotification = new Notification('N', undefined);
- return Notification;
- }());
-
- /**
- *
- * Re-emits all notifications from source Observable with specified scheduler.
- *
- * <span class="informal">Ensure a specific scheduler is used, from outside of an Observable.</span>
- *
- * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule
- * notifications emitted by the source Observable. It might be useful, if you do not have control over
- * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.
- *
- * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,
- * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal
- * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits
- * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.
- * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split
- * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source
- * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a
- * little bit more, to ensure that they are emitted at expected moments.
- *
- * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications
- * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`
- * will delay all notifications - including error notifications - while `delay` will pass through error
- * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator
- * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used
- * for notification emissions in general.
- *
- * @example <caption>Ensure values in subscribe are called just before browser repaint.</caption>
- * const intervals = Rx.Observable.interval(10); // Intervals are scheduled
- * // with async scheduler by default...
- *
- * intervals
- * .observeOn(Rx.Scheduler.animationFrame) // ...but we will observe on animationFrame
- * .subscribe(val => { // scheduler to ensure smooth animation.
- * someDiv.style.height = val + 'px';
- * });
- *
- * @see {@link delay}
- *
- * @param {IScheduler} scheduler Scheduler that will be used to reschedule notifications from source Observable.
- * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.
- * @return {Observable<T>} Observable that emits the same notifications as the source Observable,
- * but with provided scheduler.
- *
- * @method observeOn
- * @owner Observable
- */
- function observeOn(scheduler, delay) {
- if (delay === void 0) { delay = 0; }
- return function observeOnOperatorFunction(source) {
- return source.lift(new ObserveOnOperator(scheduler, delay));
- };
- }
- var ObserveOnOperator = (function () {
- function ObserveOnOperator(scheduler, delay) {
- if (delay === void 0) { delay = 0; }
- this.scheduler = scheduler;
- this.delay = delay;
- }
- ObserveOnOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
- };
- return ObserveOnOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ObserveOnSubscriber = (function (_super) {
- __extends(ObserveOnSubscriber, _super);
- function ObserveOnSubscriber(destination, scheduler, delay) {
- if (delay === void 0) { delay = 0; }
- _super.call(this, destination);
- this.scheduler = scheduler;
- this.delay = delay;
- }
- ObserveOnSubscriber.dispatch = function (arg) {
- var notification = arg.notification, destination = arg.destination;
- notification.observe(destination);
- this.unsubscribe();
- };
- ObserveOnSubscriber.prototype.scheduleMessage = function (notification) {
- this.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
- };
- ObserveOnSubscriber.prototype._next = function (value) {
- this.scheduleMessage(Notification.createNext(value));
- };
- ObserveOnSubscriber.prototype._error = function (err) {
- this.scheduleMessage(Notification.createError(err));
- };
- ObserveOnSubscriber.prototype._complete = function () {
- this.scheduleMessage(Notification.createComplete());
- };
- return ObserveOnSubscriber;
- }(Subscriber));
- var ObserveOnMessage = (function () {
- function ObserveOnMessage(notification, destination) {
- this.notification = notification;
- this.destination = destination;
- }
- return ObserveOnMessage;
- }());
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var FromObservable = (function (_super) {
- __extends(FromObservable, _super);
- function FromObservable(ish, scheduler) {
- _super.call(this, null);
- this.ish = ish;
- this.scheduler = scheduler;
- }
- /**
- * Creates an Observable from an Array, an array-like object, a Promise, an
- * iterable object, or an Observable-like object.
- *
- * <span class="informal">Converts almost anything to an Observable.</span>
- *
- * <img src="./img/from.png" width="100%">
- *
- * Convert various other objects and data types into Observables. `from`
- * converts a Promise or an array-like or an
- * [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable)
- * object into an Observable that emits the items in that promise or array or
- * iterable. A String, in this context, is treated as an array of characters.
- * Observable-like objects (contains a function named with the ES2015 Symbol
- * for Observable) can also be converted through this operator.
- *
- * @example <caption>Converts an array to an Observable</caption>
- * var array = [10, 20, 30];
- * var result = Rx.Observable.from(array);
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // 10 20 30
- *
- * @example <caption>Convert an infinite iterable (from a generator) to an Observable</caption>
- * function* generateDoubles(seed) {
- * var i = seed;
- * while (true) {
- * yield i;
- * i = 2 * i; // double it
- * }
- * }
- *
- * var iterator = generateDoubles(3);
- * var result = Rx.Observable.from(iterator).take(10);
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // 3 6 12 24 48 96 192 384 768 1536
- *
- * @see {@link create}
- * @see {@link fromEvent}
- * @see {@link fromEventPattern}
- * @see {@link fromPromise}
- *
- * @param {ObservableInput<T>} ish A subscribable object, a Promise, an
- * Observable-like, an Array, an iterable or an array-like object to be
- * converted.
- * @param {Scheduler} [scheduler] The scheduler on which to schedule the
- * emissions of values.
- * @return {Observable<T>} The Observable whose values are originally from the
- * input object that was converted.
- * @static true
- * @name from
- * @owner Observable
- */
- FromObservable.create = function (ish, scheduler) {
- if (ish != null) {
- if (typeof ish[observable] === 'function') {
- if (ish instanceof Observable && !scheduler) {
- return ish;
- }
- return new FromObservable(ish, scheduler);
- }
- else if (isArray(ish)) {
- return new ArrayObservable(ish, scheduler);
- }
- else if (isPromise(ish)) {
- return new PromiseObservable(ish, scheduler);
- }
- else if (typeof ish[iterator] === 'function' || typeof ish === 'string') {
- return new IteratorObservable(ish, scheduler);
- }
- else if (isArrayLike(ish)) {
- return new ArrayLikeObservable(ish, scheduler);
- }
- }
- throw new TypeError((ish !== null && typeof ish || ish) + ' is not observable');
- };
- /** @deprecated internal use only */ FromObservable.prototype._subscribe = function (subscriber) {
- var ish = this.ish;
- var scheduler = this.scheduler;
- if (scheduler == null) {
- return ish[observable]().subscribe(subscriber);
- }
- else {
- return ish[observable]().subscribe(new ObserveOnSubscriber(subscriber, scheduler, 0));
- }
- };
- return FromObservable;
- }(Observable));
-
- var from = FromObservable.create;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link mergeAll}.</span>
- *
- * <img src="./img/mergeMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an Observable, and then merging those resulting Observables and
- * emitting the results of this merger.
- *
- * @example <caption>Map and flatten each letter to an Observable ticking every 1 second</caption>
- * var letters = Rx.Observable.of('a', 'b', 'c');
- * var result = letters.mergeMap(x =>
- * Rx.Observable.interval(1000).map(i => x+i)
- * );
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // a0
- * // b0
- * // c0
- * // a1
- * // b1
- * // c1
- * // continues to list a,b,c with respective ascending integers
- *
- * @see {@link concatMap}
- * @see {@link exhaustMap}
- * @see {@link merge}
- * @see {@link mergeAll}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- * @see {@link switchMap}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @return {Observable} An Observable that emits the result of applying the
- * projection function (and the optional `resultSelector`) to each item emitted
- * by the source Observable and merging the results of the Observables obtained
- * from this transformation.
- * @method mergeMap
- * @owner Observable
- */
- function mergeMap(project, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return function mergeMapOperatorFunction(source) {
- if (typeof resultSelector === 'number') {
- concurrent = resultSelector;
- resultSelector = null;
- }
- return source.lift(new MergeMapOperator(project, resultSelector, concurrent));
- };
- }
- var MergeMapOperator = (function () {
- function MergeMapOperator(project, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- this.project = project;
- this.resultSelector = resultSelector;
- this.concurrent = concurrent;
- }
- MergeMapOperator.prototype.call = function (observer, source) {
- return source.subscribe(new MergeMapSubscriber(observer, this.project, this.resultSelector, this.concurrent));
- };
- return MergeMapOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var MergeMapSubscriber = (function (_super) {
- __extends(MergeMapSubscriber, _super);
- function MergeMapSubscriber(destination, project, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- _super.call(this, destination);
- this.project = project;
- this.resultSelector = resultSelector;
- this.concurrent = concurrent;
- this.hasCompleted = false;
- this.buffer = [];
- this.active = 0;
- this.index = 0;
- }
- MergeMapSubscriber.prototype._next = function (value) {
- if (this.active < this.concurrent) {
- this._tryNext(value);
- }
- else {
- this.buffer.push(value);
- }
- };
- MergeMapSubscriber.prototype._tryNext = function (value) {
- var result;
- var index = this.index++;
- try {
- result = this.project(value, index);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.active++;
- this._innerSub(result, value, index);
- };
- MergeMapSubscriber.prototype._innerSub = function (ish, value, index) {
- this.add(subscribeToResult(this, ish, value, index));
- };
- MergeMapSubscriber.prototype._complete = function () {
- this.hasCompleted = true;
- if (this.active === 0 && this.buffer.length === 0) {
- this.destination.complete();
- }
- };
- MergeMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- if (this.resultSelector) {
- this._notifyResultSelector(outerValue, innerValue, outerIndex, innerIndex);
- }
- else {
- this.destination.next(innerValue);
- }
- };
- MergeMapSubscriber.prototype._notifyResultSelector = function (outerValue, innerValue, outerIndex, innerIndex) {
- var result;
- try {
- result = this.resultSelector(outerValue, innerValue, outerIndex, innerIndex);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.destination.next(result);
- };
- MergeMapSubscriber.prototype.notifyComplete = function (innerSub) {
- var buffer = this.buffer;
- this.remove(innerSub);
- this.active--;
- if (buffer.length > 0) {
- this._next(buffer.shift());
- }
- else if (this.active === 0 && this.hasCompleted) {
- this.destination.complete();
- }
- };
- return MergeMapSubscriber;
- }(OuterSubscriber));
-
- function identity(x) {
- return x;
- }
-
- /**
- * Converts a higher-order Observable into a first-order Observable which
- * concurrently delivers all values that are emitted on the inner Observables.
- *
- * <span class="informal">Flattens an Observable-of-Observables.</span>
- *
- * <img src="./img/mergeAll.png" width="100%">
- *
- * `mergeAll` subscribes to an Observable that emits Observables, also known as
- * a higher-order Observable. Each time it observes one of these emitted inner
- * Observables, it subscribes to that and delivers all the values from the
- * inner Observable on the output Observable. The output Observable only
- * completes once all inner Observables have completed. Any error delivered by
- * a inner Observable will be immediately emitted on the output Observable.
- *
- * @example <caption>Spawn a new interval Observable for each click event, and blend their outputs as one Observable</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000));
- * var firstOrder = higherOrder.mergeAll();
- * firstOrder.subscribe(x => console.log(x));
- *
- * @example <caption>Count from 0 to 9 every second for each click, but only allow 2 concurrent timers</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(10));
- * var firstOrder = higherOrder.mergeAll(2);
- * firstOrder.subscribe(x => console.log(x));
- *
- * @see {@link combineAll}
- * @see {@link concatAll}
- * @see {@link exhaust}
- * @see {@link merge}
- * @see {@link mergeMap}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- * @see {@link switch}
- * @see {@link zipAll}
- *
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of inner
- * Observables being subscribed to concurrently.
- * @return {Observable} An Observable that emits values coming from all the
- * inner Observables emitted by the source Observable.
- * @method mergeAll
- * @owner Observable
- */
- function mergeAll(concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return mergeMap(identity, null, concurrent);
- }
-
- /**
- * Converts a higher-order Observable into a first-order Observable by
- * concatenating the inner Observables in order.
- *
- * <span class="informal">Flattens an Observable-of-Observables by putting one
- * inner Observable after the other.</span>
- *
- * <img src="./img/concatAll.png" width="100%">
- *
- * Joins every Observable emitted by the source (a higher-order Observable), in
- * a serial fashion. It subscribes to each inner Observable only after the
- * previous inner Observable has completed, and merges all of their values into
- * the returned observable.
- *
- * __Warning:__ If the source Observable emits Observables quickly and
- * endlessly, and the inner Observables it emits generally complete slower than
- * the source emits, you can run into memory issues as the incoming Observables
- * collect in an unbounded buffer.
- *
- * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set
- * to `1`.
- *
- * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map(ev => Rx.Observable.interval(1000).take(4));
- * var firstOrder = higherOrder.concatAll();
- * firstOrder.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // (results are not concurrent)
- * // For every click on the "document" it will emit values 0 to 3 spaced
- * // on a 1000ms interval
- * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
- *
- * @see {@link combineAll}
- * @see {@link concat}
- * @see {@link concatMap}
- * @see {@link concatMapTo}
- * @see {@link exhaust}
- * @see {@link mergeAll}
- * @see {@link switch}
- * @see {@link zipAll}
- *
- * @return {Observable} An Observable emitting values from all the inner
- * Observables concatenated.
- * @method concatAll
- * @owner Observable
- */
- function concatAll() {
- return mergeAll(1);
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Creates an output Observable which sequentially emits all values from given
- * Observable and then moves on to the next.
- *
- * <span class="informal">Concatenates multiple Observables together by
- * sequentially emitting their values, one Observable after the other.</span>
- *
- * <img src="./img/concat.png" width="100%">
- *
- * `concat` joins multiple Observables together, by subscribing to them one at a time and
- * merging their results into the output Observable. You can pass either an array of
- * Observables, or put them directly as arguments. Passing an empty array will result
- * in Observable that completes immediately.
- *
- * `concat` will subscribe to first input Observable and emit all its values, without
- * changing or affecting them in any way. When that Observable completes, it will
- * subscribe to then next Observable passed and, again, emit its values. This will be
- * repeated, until the operator runs out of Observables. When last input Observable completes,
- * `concat` will complete as well. At any given moment only one Observable passed to operator
- * emits values. If you would like to emit values from passed Observables concurrently, check out
- * {@link merge} instead, especially with optional `concurrent` parameter. As a matter of fact,
- * `concat` is an equivalent of `merge` operator with `concurrent` parameter set to `1`.
- *
- * Note that if some input Observable never completes, `concat` will also never complete
- * and Observables following the one that did not complete will never be subscribed. On the other
- * hand, if some Observable simply completes immediately after it is subscribed, it will be
- * invisible for `concat`, which will just move on to the next Observable.
- *
- * If any Observable in chain errors, instead of passing control to the next Observable,
- * `concat` will error immediately as well. Observables that would be subscribed after
- * the one that emitted error, never will.
- *
- * If you pass to `concat` the same Observable many times, its stream of values
- * will be "replayed" on every subscription, which means you can repeat given Observable
- * as many times as you like. If passing the same Observable to `concat` 1000 times becomes tedious,
- * you can always use {@link repeat}.
- *
- * @example <caption>Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10</caption>
- * var timer = Rx.Observable.interval(1000).take(4);
- * var sequence = Rx.Observable.range(1, 10);
- * var result = Rx.Observable.concat(timer, sequence);
- * result.subscribe(x => console.log(x));
- *
- * // results in:
- * // 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
- *
- *
- * @example <caption>Concatenate an array of 3 Observables</caption>
- * var timer1 = Rx.Observable.interval(1000).take(10);
- * var timer2 = Rx.Observable.interval(2000).take(6);
- * var timer3 = Rx.Observable.interval(500).take(10);
- * var result = Rx.Observable.concat([timer1, timer2, timer3]); // note that array is passed
- * result.subscribe(x => console.log(x));
- *
- * // results in the following:
- * // (Prints to console sequentially)
- * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
- * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
- * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9
- *
- *
- * @example <caption>Concatenate the same Observable to repeat it</caption>
- * const timer = Rx.Observable.interval(1000).take(2);
- *
- * Rx.Observable.concat(timer, timer) // concating the same Observable!
- * .subscribe(
- * value => console.log(value),
- * err => {},
- * () => console.log('...and it is done!')
- * );
- *
- * // Logs:
- * // 0 after 1s
- * // 1 after 2s
- * // 0 after 3s
- * // 1 after 4s
- * // "...and it is done!" also after 4s
- *
- * @see {@link concatAll}
- * @see {@link concatMap}
- * @see {@link concatMapTo}
- *
- * @param {ObservableInput} input1 An input Observable to concatenate with others.
- * @param {ObservableInput} input2 An input Observable to concatenate with others.
- * More than one input Observables may be given as argument.
- * @param {Scheduler} [scheduler=null] An optional IScheduler to schedule each
- * Observable subscription on.
- * @return {Observable} All values of each passed Observable merged into a
- * single Observable, in order, in serial fashion.
- * @static true
- * @name concat
- * @owner Observable
- */
- function concat() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- if (observables.length === 1 || (observables.length === 2 && isScheduler(observables[1]))) {
- return from(observables[0]);
- }
- return concatAll()(of.apply(void 0, observables));
- }
-
- Observable.concat = concat;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var DeferObservable = (function (_super) {
- __extends(DeferObservable, _super);
- function DeferObservable(observableFactory) {
- _super.call(this);
- this.observableFactory = observableFactory;
- }
- /**
- * Creates an Observable that, on subscribe, calls an Observable factory to
- * make an Observable for each new Observer.
- *
- * <span class="informal">Creates the Observable lazily, that is, only when it
- * is subscribed.
- * </span>
- *
- * <img src="./img/defer.png" width="100%">
- *
- * `defer` allows you to create the Observable only when the Observer
- * subscribes, and create a fresh Observable for each Observer. It waits until
- * an Observer subscribes to it, and then it generates an Observable,
- * typically with an Observable factory function. It does this afresh for each
- * subscriber, so although each subscriber may think it is subscribing to the
- * same Observable, in fact each subscriber gets its own individual
- * Observable.
- *
- * @example <caption>Subscribe to either an Observable of clicks or an Observable of interval, at random</caption>
- * var clicksOrInterval = Rx.Observable.defer(function () {
- * if (Math.random() > 0.5) {
- * return Rx.Observable.fromEvent(document, 'click');
- * } else {
- * return Rx.Observable.interval(1000);
- * }
- * });
- * clicksOrInterval.subscribe(x => console.log(x));
- *
- * // Results in the following behavior:
- * // If the result of Math.random() is greater than 0.5 it will listen
- * // for clicks anywhere on the "document"; when document is clicked it
- * // will log a MouseEvent object to the console. If the result is less
- * // than 0.5 it will emit ascending numbers, one every second(1000ms).
- *
- * @see {@link create}
- *
- * @param {function(): SubscribableOrPromise} observableFactory The Observable
- * factory function to invoke for each Observer that subscribes to the output
- * Observable. May also return a Promise, which will be converted on the fly
- * to an Observable.
- * @return {Observable} An Observable whose Observers' subscriptions trigger
- * an invocation of the given Observable factory function.
- * @static true
- * @name defer
- * @owner Observable
- */
- DeferObservable.create = function (observableFactory) {
- return new DeferObservable(observableFactory);
- };
- /** @deprecated internal use only */ DeferObservable.prototype._subscribe = function (subscriber) {
- return new DeferSubscriber(subscriber, this.observableFactory);
- };
- return DeferObservable;
- }(Observable));
- var DeferSubscriber = (function (_super) {
- __extends(DeferSubscriber, _super);
- function DeferSubscriber(destination, factory) {
- _super.call(this, destination);
- this.factory = factory;
- this.tryDefer();
- }
- DeferSubscriber.prototype.tryDefer = function () {
- try {
- this._callFactory();
- }
- catch (err) {
- this._error(err);
- }
- };
- DeferSubscriber.prototype._callFactory = function () {
- var result = this.factory();
- if (result) {
- this.add(subscribeToResult(this, result));
- }
- };
- return DeferSubscriber;
- }(OuterSubscriber));
-
- var defer = DeferObservable.create;
-
- Observable.defer = defer;
-
- var empty$1 = EmptyObservable.create;
-
- Observable.empty = empty$1;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var ForkJoinObservable = (function (_super) {
- __extends(ForkJoinObservable, _super);
- function ForkJoinObservable(sources, resultSelector) {
- _super.call(this);
- this.sources = sources;
- this.resultSelector = resultSelector;
- }
- /* tslint:enable:max-line-length */
- /**
- * Joins last values emitted by passed Observables.
- *
- * <span class="informal">Wait for Observables to complete and then combine last values they emitted.</span>
- *
- * <img src="./img/forkJoin.png" width="100%">
- *
- * `forkJoin` is an operator that takes any number of Observables which can be passed either as an array
- * or directly as arguments. If no input Observables are provided, resulting stream will complete
- * immediately.
- *
- * `forkJoin` will wait for all passed Observables to complete and then it will emit an array with last
- * values from corresponding Observables. So if you pass `n` Observables to the operator, resulting
- * array will have `n` values, where first value is the last thing emitted by the first Observable,
- * second value is the last thing emitted by the second Observable and so on. That means `forkJoin` will
- * not emit more than once and it will complete after that. If you need to emit combined values not only
- * at the end of lifecycle of passed Observables, but also throughout it, try out {@link combineLatest}
- * or {@link zip} instead.
- *
- * In order for resulting array to have the same length as the number of input Observables, whenever any of
- * that Observables completes without emitting any value, `forkJoin` will complete at that moment as well
- * and it will not emit anything either, even if it already has some last values from other Observables.
- * Conversely, if there is an Observable that never completes, `forkJoin` will never complete as well,
- * unless at any point some other Observable completes without emitting value, which brings us back to
- * the previous case. Overall, in order for `forkJoin` to emit a value, all Observables passed as arguments
- * have to emit something at least once and complete.
- *
- * If any input Observable errors at some point, `forkJoin` will error as well and all other Observables
- * will be immediately unsubscribed.
- *
- * Optionally `forkJoin` accepts project function, that will be called with values which normally
- * would land in emitted array. Whatever is returned by project function, will appear in output
- * Observable instead. This means that default project can be thought of as a function that takes
- * all its arguments and puts them into an array. Note that project function will be called only
- * when output Observable is supposed to emit a result.
- *
- * @example <caption>Use forkJoin with operator emitting immediately</caption>
- * const observable = Rx.Observable.forkJoin(
- * Rx.Observable.of(1, 2, 3, 4),
- * Rx.Observable.of(5, 6, 7, 8)
- * );
- * observable.subscribe(
- * value => console.log(value),
- * err => {},
- * () => console.log('This is how it ends!')
- * );
- *
- * // Logs:
- * // [4, 8]
- * // "This is how it ends!"
- *
- *
- * @example <caption>Use forkJoin with operator emitting after some time</caption>
- * const observable = Rx.Observable.forkJoin(
- * Rx.Observable.interval(1000).take(3), // emit 0, 1, 2 every second and complete
- * Rx.Observable.interval(500).take(4) // emit 0, 1, 2, 3 every half a second and complete
- * );
- * observable.subscribe(
- * value => console.log(value),
- * err => {},
- * () => console.log('This is how it ends!')
- * );
- *
- * // Logs:
- * // [2, 3] after 3 seconds
- * // "This is how it ends!" immediately after
- *
- *
- * @example <caption>Use forkJoin with project function</caption>
- * const observable = Rx.Observable.forkJoin(
- * Rx.Observable.interval(1000).take(3), // emit 0, 1, 2 every second and complete
- * Rx.Observable.interval(500).take(4), // emit 0, 1, 2, 3 every half a second and complete
- * (n, m) => n + m
- * );
- * observable.subscribe(
- * value => console.log(value),
- * err => {},
- * () => console.log('This is how it ends!')
- * );
- *
- * // Logs:
- * // 5 after 3 seconds
- * // "This is how it ends!" immediately after
- *
- * @see {@link combineLatest}
- * @see {@link zip}
- *
- * @param {...SubscribableOrPromise} sources Any number of Observables provided either as an array or as an arguments
- * passed directly to the operator.
- * @param {function} [project] Function that takes values emitted by input Observables and returns value
- * that will appear in resulting Observable instead of default array.
- * @return {Observable} Observable emitting either an array of last values emitted by passed Observables
- * or value from project function.
- * @static true
- * @name forkJoin
- * @owner Observable
- */
- ForkJoinObservable.create = function () {
- var sources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- sources[_i - 0] = arguments[_i];
- }
- if (sources === null || arguments.length === 0) {
- return new EmptyObservable();
- }
- var resultSelector = null;
- if (typeof sources[sources.length - 1] === 'function') {
- resultSelector = sources.pop();
- }
- // if the first and only other argument besides the resultSelector is an array
- // assume it's been called with `forkJoin([obs1, obs2, obs3], resultSelector)`
- if (sources.length === 1 && isArray(sources[0])) {
- sources = sources[0];
- }
- if (sources.length === 0) {
- return new EmptyObservable();
- }
- return new ForkJoinObservable(sources, resultSelector);
- };
- /** @deprecated internal use only */ ForkJoinObservable.prototype._subscribe = function (subscriber) {
- return new ForkJoinSubscriber(subscriber, this.sources, this.resultSelector);
- };
- return ForkJoinObservable;
- }(Observable));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ForkJoinSubscriber = (function (_super) {
- __extends(ForkJoinSubscriber, _super);
- function ForkJoinSubscriber(destination, sources, resultSelector) {
- _super.call(this, destination);
- this.sources = sources;
- this.resultSelector = resultSelector;
- this.completed = 0;
- this.haveValues = 0;
- var len = sources.length;
- this.total = len;
- this.values = new Array(len);
- for (var i = 0; i < len; i++) {
- var source = sources[i];
- var innerSubscription = subscribeToResult(this, source, null, i);
- if (innerSubscription) {
- innerSubscription.outerIndex = i;
- this.add(innerSubscription);
- }
- }
- }
- ForkJoinSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.values[outerIndex] = innerValue;
- if (!innerSub._hasValue) {
- innerSub._hasValue = true;
- this.haveValues++;
- }
- };
- ForkJoinSubscriber.prototype.notifyComplete = function (innerSub) {
- var destination = this.destination;
- var _a = this, haveValues = _a.haveValues, resultSelector = _a.resultSelector, values = _a.values;
- var len = values.length;
- if (!innerSub._hasValue) {
- destination.complete();
- return;
- }
- this.completed++;
- if (this.completed !== len) {
- return;
- }
- if (haveValues === len) {
- var value = resultSelector ? resultSelector.apply(this, values) : values;
- destination.next(value);
- }
- destination.complete();
- };
- return ForkJoinSubscriber;
- }(OuterSubscriber));
-
- var forkJoin = ForkJoinObservable.create;
-
- Observable.forkJoin = forkJoin;
-
- Observable.from = from;
-
- var toString = Object.prototype.toString;
- function isNodeStyleEventEmitter(sourceObj) {
- return !!sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function';
- }
- function isJQueryStyleEventEmitter(sourceObj) {
- return !!sourceObj && typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function';
- }
- function isNodeList(sourceObj) {
- return !!sourceObj && toString.call(sourceObj) === '[object NodeList]';
- }
- function isHTMLCollection(sourceObj) {
- return !!sourceObj && toString.call(sourceObj) === '[object HTMLCollection]';
- }
- function isEventTarget(sourceObj) {
- return !!sourceObj && typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function';
- }
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var FromEventObservable = (function (_super) {
- __extends(FromEventObservable, _super);
- function FromEventObservable(sourceObj, eventName, selector, options) {
- _super.call(this);
- this.sourceObj = sourceObj;
- this.eventName = eventName;
- this.selector = selector;
- this.options = options;
- }
- /* tslint:enable:max-line-length */
- /**
- * Creates an Observable that emits events of a specific type coming from the
- * given event target.
- *
- * <span class="informal">Creates an Observable from DOM events, or Node.js
- * EventEmitter events or others.</span>
- *
- * <img src="./img/fromEvent.png" width="100%">
- *
- * `fromEvent` accepts as a first argument event target, which is an object with methods
- * for registering event handler functions. As a second argument it takes string that indicates
- * type of event we want to listen for. `fromEvent` supports selected types of event targets,
- * which are described in detail below. If your event target does not match any of the ones listed,
- * you should use {@link fromEventPattern}, which can be used on arbitrary APIs.
- * When it comes to APIs supported by `fromEvent`, their methods for adding and removing event
- * handler functions have different names, but they all accept a string describing event type
- * and function itself, which will be called whenever said event happens.
- *
- * Every time resulting Observable is subscribed, event handler function will be registered
- * to event target on given event type. When that event fires, value
- * passed as a first argument to registered function will be emitted by output Observable.
- * When Observable is unsubscribed, function will be unregistered from event target.
- *
- * Note that if event target calls registered function with more than one argument, second
- * and following arguments will not appear in resulting stream. In order to get access to them,
- * you can pass to `fromEvent` optional project function, which will be called with all arguments
- * passed to event handler. Output Observable will then emit value returned by project function,
- * instead of the usual value.
- *
- * Remember that event targets listed below are checked via duck typing. It means that
- * no matter what kind of object you have and no matter what environment you work in,
- * you can safely use `fromEvent` on that object if it exposes described methods (provided
- * of course they behave as was described above). So for example if Node.js library exposes
- * event target which has the same method names as DOM EventTarget, `fromEvent` is still
- * a good choice.
- *
- * If the API you use is more callback then event handler oriented (subscribed
- * callback function fires only once and thus there is no need to manually
- * unregister it), you should use {@link bindCallback} or {@link bindNodeCallback}
- * instead.
- *
- * `fromEvent` supports following types of event targets:
- *
- * **DOM EventTarget**
- *
- * This is an object with `addEventListener` and `removeEventListener` methods.
- *
- * In the browser, `addEventListener` accepts - apart from event type string and event
- * handler function arguments - optional third parameter, which is either an object or boolean,
- * both used for additional configuration how and when passed function will be called. When
- * `fromEvent` is used with event target of that type, you can provide this values
- * as third parameter as well.
- *
- * **Node.js EventEmitter**
- *
- * An object with `addListener` and `removeListener` methods.
- *
- * **JQuery-style event target**
- *
- * An object with `on` and `off` methods
- *
- * **DOM NodeList**
- *
- * List of DOM Nodes, returned for example by `document.querySelectorAll` or `Node.childNodes`.
- *
- * Although this collection is not event target in itself, `fromEvent` will iterate over all Nodes
- * it contains and install event handler function in every of them. When returned Observable
- * is unsubscribed, function will be removed from all Nodes.
- *
- * **DOM HtmlCollection**
- *
- * Just as in case of NodeList it is a collection of DOM nodes. Here as well event handler function is
- * installed and removed in each of elements.
- *
- *
- * @example <caption>Emits clicks happening on the DOM document</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * clicks.subscribe(x => console.log(x));
- *
- * // Results in:
- * // MouseEvent object logged to console every time a click
- * // occurs on the document.
- *
- *
- * @example <caption>Use addEventListener with capture option</caption>
- * var clicksInDocument = Rx.Observable.fromEvent(document, 'click', true); // note optional configuration parameter
- * // which will be passed to addEventListener
- * var clicksInDiv = Rx.Observable.fromEvent(someDivInDocument, 'click');
- *
- * clicksInDocument.subscribe(() => console.log('document'));
- * clicksInDiv.subscribe(() => console.log('div'));
- *
- * // By default events bubble UP in DOM tree, so normally
- * // when we would click on div in document
- * // "div" would be logged first and then "document".
- * // Since we specified optional `capture` option, document
- * // will catch event when it goes DOWN DOM tree, so console
- * // will log "document" and then "div".
- *
- * @see {@link bindCallback}
- * @see {@link bindNodeCallback}
- * @see {@link fromEventPattern}
- *
- * @param {EventTargetLike} target The DOM EventTarget, Node.js
- * EventEmitter, JQuery-like event target, NodeList or HTMLCollection to attach the event handler to.
- * @param {string} eventName The event name of interest, being emitted by the
- * `target`.
- * @param {EventListenerOptions} [options] Options to pass through to addEventListener
- * @param {SelectorMethodSignature<T>} [selector] An optional function to
- * post-process results. It takes the arguments from the event handler and
- * should return a single value.
- * @return {Observable<T>}
- * @static true
- * @name fromEvent
- * @owner Observable
- */
- FromEventObservable.create = function (target, eventName, options, selector) {
- if (isFunction(options)) {
- selector = options;
- options = undefined;
- }
- return new FromEventObservable(target, eventName, selector, options);
- };
- FromEventObservable.setupSubscription = function (sourceObj, eventName, handler, subscriber, options) {
- var unsubscribe;
- if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
- for (var i = 0, len = sourceObj.length; i < len; i++) {
- FromEventObservable.setupSubscription(sourceObj[i], eventName, handler, subscriber, options);
- }
- }
- else if (isEventTarget(sourceObj)) {
- var source_1 = sourceObj;
- sourceObj.addEventListener(eventName, handler, options);
- unsubscribe = function () { return source_1.removeEventListener(eventName, handler, options); };
- }
- else if (isJQueryStyleEventEmitter(sourceObj)) {
- var source_2 = sourceObj;
- sourceObj.on(eventName, handler);
- unsubscribe = function () { return source_2.off(eventName, handler); };
- }
- else if (isNodeStyleEventEmitter(sourceObj)) {
- var source_3 = sourceObj;
- sourceObj.addListener(eventName, handler);
- unsubscribe = function () { return source_3.removeListener(eventName, handler); };
- }
- else {
- throw new TypeError('Invalid event target');
- }
- subscriber.add(new Subscription(unsubscribe));
- };
- /** @deprecated internal use only */ FromEventObservable.prototype._subscribe = function (subscriber) {
- var sourceObj = this.sourceObj;
- var eventName = this.eventName;
- var options = this.options;
- var selector = this.selector;
- var handler = selector ? function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i - 0] = arguments[_i];
- }
- var result = tryCatch(selector).apply(void 0, args);
- if (result === errorObject) {
- subscriber.error(errorObject.e);
- }
- else {
- subscriber.next(result);
- }
- } : function (e) { return subscriber.next(e); };
- FromEventObservable.setupSubscription(sourceObj, eventName, handler, subscriber, options);
- };
- return FromEventObservable;
- }(Observable));
-
- var fromEvent = FromEventObservable.create;
-
- Observable.fromEvent = fromEvent;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var FromEventPatternObservable = (function (_super) {
- __extends(FromEventPatternObservable, _super);
- function FromEventPatternObservable(addHandler, removeHandler, selector) {
- _super.call(this);
- this.addHandler = addHandler;
- this.removeHandler = removeHandler;
- this.selector = selector;
- }
- /**
- * Creates an Observable from an API based on addHandler/removeHandler
- * functions.
- *
- * <span class="informal">Converts any addHandler/removeHandler API to an
- * Observable.</span>
- *
- * <img src="./img/fromEventPattern.png" width="100%">
- *
- * Creates an Observable by using the `addHandler` and `removeHandler`
- * functions to add and remove the handlers, with an optional selector
- * function to project the event arguments to a result. The `addHandler` is
- * called when the output Observable is subscribed, and `removeHandler` is
- * called when the Subscription is unsubscribed.
- *
- * @example <caption>Emits clicks happening on the DOM document</caption>
- * function addClickHandler(handler) {
- * document.addEventListener('click', handler);
- * }
- *
- * function removeClickHandler(handler) {
- * document.removeEventListener('click', handler);
- * }
- *
- * var clicks = Rx.Observable.fromEventPattern(
- * addClickHandler,
- * removeClickHandler
- * );
- * clicks.subscribe(x => console.log(x));
- *
- * @see {@link from}
- * @see {@link fromEvent}
- *
- * @param {function(handler: Function): any} addHandler A function that takes
- * a `handler` function as argument and attaches it somehow to the actual
- * source of events.
- * @param {function(handler: Function, signal?: any): void} [removeHandler] An optional function that
- * takes a `handler` function as argument and removes it in case it was
- * previously attached using `addHandler`. if addHandler returns signal to teardown when remove,
- * removeHandler function will forward it.
- * @param {function(...args: any): T} [selector] An optional function to
- * post-process results. It takes the arguments from the event handler and
- * should return a single value.
- * @return {Observable<T>}
- * @static true
- * @name fromEventPattern
- * @owner Observable
- */
- FromEventPatternObservable.create = function (addHandler, removeHandler, selector) {
- return new FromEventPatternObservable(addHandler, removeHandler, selector);
- };
- /** @deprecated internal use only */ FromEventPatternObservable.prototype._subscribe = function (subscriber) {
- var _this = this;
- var removeHandler = this.removeHandler;
- var handler = !!this.selector ? function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i - 0] = arguments[_i];
- }
- _this._callSelector(subscriber, args);
- } : function (e) { subscriber.next(e); };
- var retValue = this._callAddHandler(handler, subscriber);
- if (!isFunction(removeHandler)) {
- return;
- }
- subscriber.add(new Subscription(function () {
- //TODO: determine whether or not to forward to error handler
- removeHandler(handler, retValue);
- }));
- };
- FromEventPatternObservable.prototype._callSelector = function (subscriber, args) {
- try {
- var result = this.selector.apply(this, args);
- subscriber.next(result);
- }
- catch (e) {
- subscriber.error(e);
- }
- };
- FromEventPatternObservable.prototype._callAddHandler = function (handler, errorSubscriber) {
- try {
- return this.addHandler(handler) || null;
- }
- catch (e) {
- errorSubscriber.error(e);
- }
- };
- return FromEventPatternObservable;
- }(Observable));
-
- var fromEventPattern = FromEventPatternObservable.create;
-
- Observable.fromEventPattern = fromEventPattern;
-
- var fromPromise = PromiseObservable.create;
-
- Observable.fromPromise = fromPromise;
-
- var selfSelector = function (value) { return value; };
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var GenerateObservable = (function (_super) {
- __extends(GenerateObservable, _super);
- function GenerateObservable(initialState, condition, iterate, resultSelector, scheduler) {
- _super.call(this);
- this.initialState = initialState;
- this.condition = condition;
- this.iterate = iterate;
- this.resultSelector = resultSelector;
- this.scheduler = scheduler;
- }
- GenerateObservable.create = function (initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
- if (arguments.length == 1) {
- return new GenerateObservable(initialStateOrOptions.initialState, initialStateOrOptions.condition, initialStateOrOptions.iterate, initialStateOrOptions.resultSelector || selfSelector, initialStateOrOptions.scheduler);
- }
- if (resultSelectorOrObservable === undefined || isScheduler(resultSelectorOrObservable)) {
- return new GenerateObservable(initialStateOrOptions, condition, iterate, selfSelector, resultSelectorOrObservable);
- }
- return new GenerateObservable(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler);
- };
- /** @deprecated internal use only */ GenerateObservable.prototype._subscribe = function (subscriber) {
- var state = this.initialState;
- if (this.scheduler) {
- return this.scheduler.schedule(GenerateObservable.dispatch, 0, {
- subscriber: subscriber,
- iterate: this.iterate,
- condition: this.condition,
- resultSelector: this.resultSelector,
- state: state });
- }
- var _a = this, condition = _a.condition, resultSelector = _a.resultSelector, iterate = _a.iterate;
- do {
- if (condition) {
- var conditionResult = void 0;
- try {
- conditionResult = condition(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (!conditionResult) {
- subscriber.complete();
- break;
- }
- }
- var value = void 0;
- try {
- value = resultSelector(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- break;
- }
- try {
- state = iterate(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- } while (true);
- };
- GenerateObservable.dispatch = function (state) {
- var subscriber = state.subscriber, condition = state.condition;
- if (subscriber.closed) {
- return;
- }
- if (state.needIterate) {
- try {
- state.state = state.iterate(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- }
- else {
- state.needIterate = true;
- }
- if (condition) {
- var conditionResult = void 0;
- try {
- conditionResult = condition(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (!conditionResult) {
- subscriber.complete();
- return;
- }
- if (subscriber.closed) {
- return;
- }
- }
- var value;
- try {
- value = state.resultSelector(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (subscriber.closed) {
- return;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- return;
- }
- return this.schedule(state);
- };
- return GenerateObservable;
- }(Observable));
-
- var generate = GenerateObservable.create;
-
- Observable.generate = generate;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var IfObservable = (function (_super) {
- __extends(IfObservable, _super);
- function IfObservable(condition, thenSource, elseSource) {
- _super.call(this);
- this.condition = condition;
- this.thenSource = thenSource;
- this.elseSource = elseSource;
- }
- IfObservable.create = function (condition, thenSource, elseSource) {
- return new IfObservable(condition, thenSource, elseSource);
- };
- /** @deprecated internal use only */ IfObservable.prototype._subscribe = function (subscriber) {
- var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource;
- return new IfSubscriber(subscriber, condition, thenSource, elseSource);
- };
- return IfObservable;
- }(Observable));
- var IfSubscriber = (function (_super) {
- __extends(IfSubscriber, _super);
- function IfSubscriber(destination, condition, thenSource, elseSource) {
- _super.call(this, destination);
- this.condition = condition;
- this.thenSource = thenSource;
- this.elseSource = elseSource;
- this.tryIf();
- }
- IfSubscriber.prototype.tryIf = function () {
- var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource;
- var result;
- try {
- result = condition();
- var source = result ? thenSource : elseSource;
- if (source) {
- this.add(subscribeToResult(this, source));
- }
- else {
- this._complete();
- }
- }
- catch (err) {
- this._error(err);
- }
- };
- return IfSubscriber;
- }(OuterSubscriber));
-
- var _if = IfObservable.create;
-
- Observable.if = _if;
-
- function isNumeric(val) {
- // parseFloat NaNs numeric-cast false positives (null|true|false|"")
- // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
- // subtraction forces infinities to NaN
- // adding 1 corrects loss of precision from parseFloat (#15100)
- return !isArray(val) && (val - parseFloat(val) + 1) >= 0;
- }
-
- /**
- * A unit of work to be executed in a {@link Scheduler}. An action is typically
- * created from within a Scheduler and an RxJS user does not need to concern
- * themselves about creating and manipulating an Action.
- *
- * ```ts
- * class Action<T> extends Subscription {
- * new (scheduler: Scheduler, work: (state?: T) => void);
- * schedule(state?: T, delay: number = 0): Subscription;
- * }
- * ```
- *
- * @class Action<T>
- */
- var Action = (function (_super) {
- __extends(Action, _super);
- function Action(scheduler, work) {
- _super.call(this);
- }
- /**
- * Schedules this action on its parent Scheduler for execution. May be passed
- * some context object, `state`. May happen at some point in the future,
- * according to the `delay` parameter, if specified.
- * @param {T} [state] Some contextual data that the `work` function uses when
- * called by the Scheduler.
- * @param {number} [delay] Time to wait before executing the work, where the
- * time unit is implicit and defined by the Scheduler.
- * @return {void}
- */
- Action.prototype.schedule = function (state, delay) {
- if (delay === void 0) { delay = 0; }
- return this;
- };
- return Action;
- }(Subscription));
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var AsyncAction = (function (_super) {
- __extends(AsyncAction, _super);
- function AsyncAction(scheduler, work) {
- _super.call(this, scheduler, work);
- this.scheduler = scheduler;
- this.work = work;
- this.pending = false;
- }
- AsyncAction.prototype.schedule = function (state, delay) {
- if (delay === void 0) { delay = 0; }
- if (this.closed) {
- return this;
- }
- // Always replace the current state with the new state.
- this.state = state;
- // Set the pending flag indicating that this action has been scheduled, or
- // has recursively rescheduled itself.
- this.pending = true;
- var id = this.id;
- var scheduler = this.scheduler;
- //
- // Important implementation note:
- //
- // Actions only execute once by default, unless rescheduled from within the
- // scheduled callback. This allows us to implement single and repeat
- // actions via the same code path, without adding API surface area, as well
- // as mimic traditional recursion but across asynchronous boundaries.
- //
- // However, JS runtimes and timers distinguish between intervals achieved by
- // serial `setTimeout` calls vs. a single `setInterval` call. An interval of
- // serial `setTimeout` calls can be individually delayed, which delays
- // scheduling the next `setTimeout`, and so on. `setInterval` attempts to
- // guarantee the interval callback will be invoked more precisely to the
- // interval period, regardless of load.
- //
- // Therefore, we use `setInterval` to schedule single and repeat actions.
- // If the action reschedules itself with the same delay, the interval is not
- // canceled. If the action doesn't reschedule, or reschedules with a
- // different delay, the interval will be canceled after scheduled callback
- // execution.
- //
- if (id != null) {
- this.id = this.recycleAsyncId(scheduler, id, delay);
- }
- this.delay = delay;
- // If this action has already an async Id, don't request a new one.
- this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
- return this;
- };
- AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- return _root.setInterval(scheduler.flush.bind(scheduler, this), delay);
- };
- AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- // If this action is rescheduled with the same delay time, don't clear the interval id.
- if (delay !== null && this.delay === delay && this.pending === false) {
- return id;
- }
- // Otherwise, if the action's delay time is different from the current delay,
- // or the action has been rescheduled before it's executed, clear the interval id
- return _root.clearInterval(id) && undefined || undefined;
- };
- /**
- * Immediately executes this action and the `work` it contains.
- * @return {any}
- */
- AsyncAction.prototype.execute = function (state, delay) {
- if (this.closed) {
- return new Error('executing a cancelled action');
- }
- this.pending = false;
- var error = this._execute(state, delay);
- if (error) {
- return error;
- }
- else if (this.pending === false && this.id != null) {
- // Dequeue if the action didn't reschedule itself. Don't call
- // unsubscribe(), because the action could reschedule later.
- // For example:
- // ```
- // scheduler.schedule(function doWork(counter) {
- // /* ... I'm a busy worker bee ... */
- // var originalAction = this;
- // /* wait 100ms before rescheduling the action */
- // setTimeout(function () {
- // originalAction.schedule(counter + 1);
- // }, 100);
- // }, 1000);
- // ```
- this.id = this.recycleAsyncId(this.scheduler, this.id, null);
- }
- };
- AsyncAction.prototype._execute = function (state, delay) {
- var errored = false;
- var errorValue = undefined;
- try {
- this.work(state);
- }
- catch (e) {
- errored = true;
- errorValue = !!e && e || new Error(e);
- }
- if (errored) {
- this.unsubscribe();
- return errorValue;
- }
- };
- /** @deprecated internal use only */ AsyncAction.prototype._unsubscribe = function () {
- var id = this.id;
- var scheduler = this.scheduler;
- var actions = scheduler.actions;
- var index = actions.indexOf(this);
- this.work = null;
- this.state = null;
- this.pending = false;
- this.scheduler = null;
- if (index !== -1) {
- actions.splice(index, 1);
- }
- if (id != null) {
- this.id = this.recycleAsyncId(scheduler, id, null);
- }
- this.delay = null;
- };
- return AsyncAction;
- }(Action));
-
- /**
- * An execution context and a data structure to order tasks and schedule their
- * execution. Provides a notion of (potentially virtual) time, through the
- * `now()` getter method.
- *
- * Each unit of work in a Scheduler is called an {@link Action}.
- *
- * ```ts
- * class Scheduler {
- * now(): number;
- * schedule(work, delay?, state?): Subscription;
- * }
- * ```
- *
- * @class Scheduler
- */
- var Scheduler$1 = (function () {
- function Scheduler(SchedulerAction, now) {
- if (now === void 0) { now = Scheduler.now; }
- this.SchedulerAction = SchedulerAction;
- this.now = now;
- }
- /**
- * Schedules a function, `work`, for execution. May happen at some point in
- * the future, according to the `delay` parameter, if specified. May be passed
- * some context object, `state`, which will be passed to the `work` function.
- *
- * The given arguments will be processed an stored as an Action object in a
- * queue of actions.
- *
- * @param {function(state: ?T): ?Subscription} work A function representing a
- * task, or some unit of work to be executed by the Scheduler.
- * @param {number} [delay] Time to wait before executing the work, where the
- * time unit is implicit and defined by the Scheduler itself.
- * @param {T} [state] Some contextual data that the `work` function uses when
- * called by the Scheduler.
- * @return {Subscription} A subscription in order to be able to unsubscribe
- * the scheduled work.
- */
- Scheduler.prototype.schedule = function (work, delay, state) {
- if (delay === void 0) { delay = 0; }
- return new this.SchedulerAction(this, work).schedule(state, delay);
- };
- Scheduler.now = Date.now ? Date.now : function () { return +new Date(); };
- return Scheduler;
- }());
-
- var AsyncScheduler = (function (_super) {
- __extends(AsyncScheduler, _super);
- function AsyncScheduler() {
- _super.apply(this, arguments);
- this.actions = [];
- /**
- * A flag to indicate whether the Scheduler is currently executing a batch of
- * queued actions.
- * @type {boolean}
- */
- this.active = false;
- /**
- * An internal ID used to track the latest asynchronous task such as those
- * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and
- * others.
- * @type {any}
- */
- this.scheduled = undefined;
- }
- AsyncScheduler.prototype.flush = function (action) {
- var actions = this.actions;
- if (this.active) {
- actions.push(action);
- return;
- }
- var error;
- this.active = true;
- do {
- if (error = action.execute(action.state, action.delay)) {
- break;
- }
- } while (action = actions.shift()); // exhaust the scheduler queue
- this.active = false;
- if (error) {
- while (action = actions.shift()) {
- action.unsubscribe();
- }
- throw error;
- }
- };
- return AsyncScheduler;
- }(Scheduler$1));
-
- /**
- *
- * Async Scheduler
- *
- * <span class="informal">Schedule task as if you used setTimeout(task, duration)</span>
- *
- * `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript
- * event loop queue. It is best used to delay tasks in time or to schedule tasks repeating
- * in intervals.
- *
- * If you just want to "defer" task, that is to perform it right after currently
- * executing synchronous code ends (commonly achieved by `setTimeout(deferredTask, 0)`),
- * better choice will be the {@link asap} scheduler.
- *
- * @example <caption>Use async scheduler to delay task</caption>
- * const task = () => console.log('it works!');
- *
- * Rx.Scheduler.async.schedule(task, 2000);
- *
- * // After 2 seconds logs:
- * // "it works!"
- *
- *
- * @example <caption>Use async scheduler to repeat task in intervals</caption>
- * function task(state) {
- * console.log(state);
- * this.schedule(state + 1, 1000); // `this` references currently executing Action,
- * // which we reschedule with new state and delay
- * }
- *
- * Rx.Scheduler.async.schedule(task, 3000, 0);
- *
- * // Logs:
- * // 0 after 3s
- * // 1 after 4s
- * // 2 after 5s
- * // 3 after 6s
- *
- * @static true
- * @name async
- * @owner Scheduler
- */
- var async = new AsyncScheduler(AsyncAction);
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var IntervalObservable = (function (_super) {
- __extends(IntervalObservable, _super);
- function IntervalObservable(period, scheduler) {
- if (period === void 0) { period = 0; }
- if (scheduler === void 0) { scheduler = async; }
- _super.call(this);
- this.period = period;
- this.scheduler = scheduler;
- if (!isNumeric(period) || period < 0) {
- this.period = 0;
- }
- if (!scheduler || typeof scheduler.schedule !== 'function') {
- this.scheduler = async;
- }
- }
- /**
- * Creates an Observable that emits sequential numbers every specified
- * interval of time, on a specified IScheduler.
- *
- * <span class="informal">Emits incremental numbers periodically in time.
- * </span>
- *
- * <img src="./img/interval.png" width="100%">
- *
- * `interval` returns an Observable that emits an infinite sequence of
- * ascending integers, with a constant interval of time of your choosing
- * between those emissions. The first emission is not sent immediately, but
- * only after the first period has passed. By default, this operator uses the
- * `async` IScheduler to provide a notion of time, but you may pass any
- * IScheduler to it.
- *
- * @example <caption>Emits ascending numbers, one every second (1000ms)</caption>
- * var numbers = Rx.Observable.interval(1000);
- * numbers.subscribe(x => console.log(x));
- *
- * @see {@link timer}
- * @see {@link delay}
- *
- * @param {number} [period=0] The interval size in milliseconds (by default)
- * or the time unit determined by the scheduler's clock.
- * @param {Scheduler} [scheduler=async] The IScheduler to use for scheduling
- * the emission of values, and providing a notion of "time".
- * @return {Observable} An Observable that emits a sequential number each time
- * interval.
- * @static true
- * @name interval
- * @owner Observable
- */
- IntervalObservable.create = function (period, scheduler) {
- if (period === void 0) { period = 0; }
- if (scheduler === void 0) { scheduler = async; }
- return new IntervalObservable(period, scheduler);
- };
- IntervalObservable.dispatch = function (state) {
- var index = state.index, subscriber = state.subscriber, period = state.period;
- subscriber.next(index);
- if (subscriber.closed) {
- return;
- }
- state.index += 1;
- this.schedule(state, period);
- };
- /** @deprecated internal use only */ IntervalObservable.prototype._subscribe = function (subscriber) {
- var index = 0;
- var period = this.period;
- var scheduler = this.scheduler;
- subscriber.add(scheduler.schedule(IntervalObservable.dispatch, period, {
- index: index, subscriber: subscriber, period: period
- }));
- };
- return IntervalObservable;
- }(Observable));
-
- var interval = IntervalObservable.create;
-
- Observable.interval = interval;
-
- /* tslint:enable:max-line-length */
- /**
- * Creates an output Observable which concurrently emits all values from every
- * given input Observable.
- *
- * <span class="informal">Flattens multiple Observables together by blending
- * their values into one Observable.</span>
- *
- * <img src="./img/merge.png" width="100%">
- *
- * `merge` subscribes to each given input Observable (as arguments), and simply
- * forwards (without doing any transformation) all the values from all the input
- * Observables to the output Observable. The output Observable only completes
- * once all input Observables have completed. Any error delivered by an input
- * Observable will be immediately emitted on the output Observable.
- *
- * @example <caption>Merge together two Observables: 1s interval and clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var timer = Rx.Observable.interval(1000);
- * var clicksOrTimer = Rx.Observable.merge(clicks, timer);
- * clicksOrTimer.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // timer will emit ascending values, one every second(1000ms) to console
- * // clicks logs MouseEvents to console everytime the "document" is clicked
- * // Since the two streams are merged you see these happening
- * // as they occur.
- *
- * @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
- * var timer1 = Rx.Observable.interval(1000).take(10);
- * var timer2 = Rx.Observable.interval(2000).take(6);
- * var timer3 = Rx.Observable.interval(500).take(10);
- * var concurrent = 2; // the argument
- * var merged = Rx.Observable.merge(timer1, timer2, timer3, concurrent);
- * merged.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // - First timer1 and timer2 will run concurrently
- * // - timer1 will emit a value every 1000ms for 10 iterations
- * // - timer2 will emit a value every 2000ms for 6 iterations
- * // - after timer1 hits it's max iteration, timer2 will
- * // continue, and timer3 will start to run concurrently with timer2
- * // - when timer2 hits it's max iteration it terminates, and
- * // timer3 will continue to emit a value every 500ms until it is complete
- *
- * @see {@link mergeAll}
- * @see {@link mergeMap}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- *
- * @param {...ObservableInput} observables Input Observables to merge together.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @param {Scheduler} [scheduler=null] The IScheduler to use for managing
- * concurrency of input Observables.
- * @return {Observable} an Observable that emits items that are the result of
- * every input Observable.
- * @static true
- * @name merge
- * @owner Observable
- */
- function merge() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- var concurrent = Number.POSITIVE_INFINITY;
- var scheduler = null;
- var last = observables[observables.length - 1];
- if (isScheduler(last)) {
- scheduler = observables.pop();
- if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
- concurrent = observables.pop();
- }
- }
- else if (typeof last === 'number') {
- concurrent = observables.pop();
- }
- if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
- return observables[0];
- }
- return mergeAll(concurrent)(new ArrayObservable(observables, scheduler));
- }
-
- Observable.merge = merge;
-
- function race() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- // if the only argument is an array, it was most likely called with
- // `race([obs1, obs2, ...])`
- if (observables.length === 1) {
- if (isArray(observables[0])) {
- observables = observables[0];
- }
- else {
- return observables[0];
- }
- }
- return new ArrayObservable(observables).lift(new RaceOperator());
- }
- var RaceOperator = (function () {
- function RaceOperator() {
- }
- RaceOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new RaceSubscriber(subscriber));
- };
- return RaceOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var RaceSubscriber = (function (_super) {
- __extends(RaceSubscriber, _super);
- function RaceSubscriber(destination) {
- _super.call(this, destination);
- this.hasFirst = false;
- this.observables = [];
- this.subscriptions = [];
- }
- RaceSubscriber.prototype._next = function (observable) {
- this.observables.push(observable);
- };
- RaceSubscriber.prototype._complete = function () {
- var observables = this.observables;
- var len = observables.length;
- if (len === 0) {
- this.destination.complete();
- }
- else {
- for (var i = 0; i < len && !this.hasFirst; i++) {
- var observable = observables[i];
- var subscription = subscribeToResult(this, observable, observable, i);
- if (this.subscriptions) {
- this.subscriptions.push(subscription);
- }
- this.add(subscription);
- }
- this.observables = null;
- }
- };
- RaceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- if (!this.hasFirst) {
- this.hasFirst = true;
- for (var i = 0; i < this.subscriptions.length; i++) {
- if (i !== outerIndex) {
- var subscription = this.subscriptions[i];
- subscription.unsubscribe();
- this.remove(subscription);
- }
- }
- this.subscriptions = null;
- }
- this.destination.next(innerValue);
- };
- return RaceSubscriber;
- }(OuterSubscriber));
-
- Observable.race = race;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var NeverObservable = (function (_super) {
- __extends(NeverObservable, _super);
- function NeverObservable() {
- _super.call(this);
- }
- /**
- * Creates an Observable that emits no items to the Observer.
- *
- * <span class="informal">An Observable that never emits anything.</span>
- *
- * <img src="./img/never.png" width="100%">
- *
- * This static operator is useful for creating a simple Observable that emits
- * neither values nor errors nor the completion notification. It can be used
- * for testing purposes or for composing with other Observables. Please note
- * that by never emitting a complete notification, this Observable keeps the
- * subscription from being disposed automatically. Subscriptions need to be
- * manually disposed.
- *
- * @example <caption>Emit the number 7, then never emit anything else (not even complete).</caption>
- * function info() {
- * console.log('Will not be called');
- * }
- * var result = Rx.Observable.never().startWith(7);
- * result.subscribe(x => console.log(x), info, info);
- *
- * @see {@link create}
- * @see {@link empty}
- * @see {@link of}
- * @see {@link throw}
- *
- * @return {Observable} A "never" Observable: never emits anything.
- * @static true
- * @name never
- * @owner Observable
- */
- NeverObservable.create = function () {
- return new NeverObservable();
- };
- /** @deprecated internal use only */ NeverObservable.prototype._subscribe = function (subscriber) {
- noop();
- };
- return NeverObservable;
- }(Observable));
-
- var never = NeverObservable.create;
-
- Observable.never = never;
-
- Observable.of = of;
-
- /* tslint:enable:max-line-length */
- /**
- * When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one
- * that was passed.
- *
- * <span class="informal">Execute series of Observables no matter what, even if it means swallowing errors.</span>
- *
- * <img src="./img/onErrorResumeNext.png" width="100%">
- *
- * `onErrorResumeNext` is an operator that accepts a series of Observables, provided either directly as
- * arguments or as an array. If no single Observable is provided, returned Observable will simply behave the same
- * as the source.
- *
- * `onErrorResumeNext` returns an Observable that starts by subscribing and re-emitting values from the source Observable.
- * When its stream of values ends - no matter if Observable completed or emitted an error - `onErrorResumeNext`
- * will subscribe to the first Observable that was passed as an argument to the method. It will start re-emitting
- * its values as well and - again - when that stream ends, `onErrorResumeNext` will proceed to subscribing yet another
- * Observable in provided series, no matter if previous Observable completed or ended with an error. This will
- * be happening until there is no more Observables left in the series, at which point returned Observable will
- * complete - even if the last subscribed stream ended with an error.
- *
- * `onErrorResumeNext` can be therefore thought of as version of {@link concat} operator, which is more permissive
- * when it comes to the errors emitted by its input Observables. While `concat` subscribes to the next Observable
- * in series only if previous one successfully completed, `onErrorResumeNext` subscribes even if it ended with
- * an error.
- *
- * Note that you do not get any access to errors emitted by the Observables. In particular do not
- * expect these errors to appear in error callback passed to {@link subscribe}. If you want to take
- * specific actions based on what error was emitted by an Observable, you should try out {@link catch} instead.
- *
- *
- * @example <caption>Subscribe to the next Observable after map fails</caption>
- * Rx.Observable.of(1, 2, 3, 0)
- * .map(x => {
- * if (x === 0) { throw Error(); }
- return 10 / x;
- * })
- * .onErrorResumeNext(Rx.Observable.of(1, 2, 3))
- * .subscribe(
- * val => console.log(val),
- * err => console.log(err), // Will never be called.
- * () => console.log('that\'s it!')
- * );
- *
- * // Logs:
- * // 10
- * // 5
- * // 3.3333333333333335
- * // 1
- * // 2
- * // 3
- * // "that's it!"
- *
- * @see {@link concat}
- * @see {@link catch}
- *
- * @param {...ObservableInput} observables Observables passed either directly or as an array.
- * @return {Observable} An Observable that emits values from source Observable, but - if it errors - subscribes
- * to the next passed Observable and so on, until it completes or runs out of Observables.
- * @method onErrorResumeNext
- * @owner Observable
- */
- function onErrorResumeNext$1() {
- var nextSources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nextSources[_i - 0] = arguments[_i];
- }
- if (nextSources.length === 1 && isArray(nextSources[0])) {
- nextSources = nextSources[0];
- }
- return function (source) { return source.lift(new OnErrorResumeNextOperator(nextSources)); };
- }
- /* tslint:enable:max-line-length */
- function onErrorResumeNextStatic() {
- var nextSources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nextSources[_i - 0] = arguments[_i];
- }
- var source = null;
- if (nextSources.length === 1 && isArray(nextSources[0])) {
- nextSources = nextSources[0];
- }
- source = nextSources.shift();
- return new FromObservable(source, null).lift(new OnErrorResumeNextOperator(nextSources));
- }
- var OnErrorResumeNextOperator = (function () {
- function OnErrorResumeNextOperator(nextSources) {
- this.nextSources = nextSources;
- }
- OnErrorResumeNextOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources));
- };
- return OnErrorResumeNextOperator;
- }());
- var OnErrorResumeNextSubscriber = (function (_super) {
- __extends(OnErrorResumeNextSubscriber, _super);
- function OnErrorResumeNextSubscriber(destination, nextSources) {
- _super.call(this, destination);
- this.destination = destination;
- this.nextSources = nextSources;
- }
- OnErrorResumeNextSubscriber.prototype.notifyError = function (error, innerSub) {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype.notifyComplete = function (innerSub) {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype._error = function (err) {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype._complete = function () {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype.subscribeToNextSource = function () {
- var next = this.nextSources.shift();
- if (next) {
- this.add(subscribeToResult(this, next));
- }
- else {
- this.destination.complete();
- }
- };
- return OnErrorResumeNextSubscriber;
- }(OuterSubscriber));
-
- var onErrorResumeNext$$1 = onErrorResumeNextStatic;
-
- Observable.onErrorResumeNext = onErrorResumeNext$$1;
-
- function dispatch$1(state) {
- var obj = state.obj, keys = state.keys, length = state.length, index = state.index, subscriber = state.subscriber;
- if (index === length) {
- subscriber.complete();
- return;
- }
- var key = keys[index];
- subscriber.next([key, obj[key]]);
- state.index = index + 1;
- this.schedule(state);
- }
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var PairsObservable = (function (_super) {
- __extends(PairsObservable, _super);
- function PairsObservable(obj, scheduler) {
- _super.call(this);
- this.obj = obj;
- this.scheduler = scheduler;
- this.keys = Object.keys(obj);
- }
- /**
- * Convert an object into an observable sequence of [key, value] pairs
- * using an optional IScheduler to enumerate the object.
- *
- * @example <caption>Converts a javascript object to an Observable</caption>
- * var obj = {
- * foo: 42,
- * bar: 56,
- * baz: 78
- * };
- *
- * var source = Rx.Observable.pairs(obj);
- *
- * var subscription = source.subscribe(
- * function (x) {
- * console.log('Next: %s', x);
- * },
- * function (err) {
- * console.log('Error: %s', err);
- * },
- * function () {
- * console.log('Completed');
- * });
- *
- * @param {Object} obj The object to inspect and turn into an
- * Observable sequence.
- * @param {Scheduler} [scheduler] An optional IScheduler to run the
- * enumeration of the input sequence on.
- * @returns {(Observable<Array<string | T>>)} An observable sequence of
- * [key, value] pairs from the object.
- */
- PairsObservable.create = function (obj, scheduler) {
- return new PairsObservable(obj, scheduler);
- };
- /** @deprecated internal use only */ PairsObservable.prototype._subscribe = function (subscriber) {
- var _a = this, keys = _a.keys, scheduler = _a.scheduler;
- var length = keys.length;
- if (scheduler) {
- return scheduler.schedule(dispatch$1, 0, {
- obj: this.obj, keys: keys, length: length, index: 0, subscriber: subscriber
- });
- }
- else {
- for (var idx = 0; idx < length; idx++) {
- var key = keys[idx];
- subscriber.next([key, this.obj[key]]);
- }
- subscriber.complete();
- }
- };
- return PairsObservable;
- }(Observable));
-
- var pairs = PairsObservable.create;
-
- Observable.pairs = pairs;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var RangeObservable = (function (_super) {
- __extends(RangeObservable, _super);
- function RangeObservable(start, count, scheduler) {
- _super.call(this);
- this.start = start;
- this._count = count;
- this.scheduler = scheduler;
- }
- /**
- * Creates an Observable that emits a sequence of numbers within a specified
- * range.
- *
- * <span class="informal">Emits a sequence of numbers in a range.</span>
- *
- * <img src="./img/range.png" width="100%">
- *
- * `range` operator emits a range of sequential integers, in order, where you
- * select the `start` of the range and its `length`. By default, uses no
- * IScheduler and just delivers the notifications synchronously, but may use
- * an optional IScheduler to regulate those deliveries.
- *
- * @example <caption>Emits the numbers 1 to 10</caption>
- * var numbers = Rx.Observable.range(1, 10);
- * numbers.subscribe(x => console.log(x));
- *
- * @see {@link timer}
- * @see {@link interval}
- *
- * @param {number} [start=0] The value of the first integer in the sequence.
- * @param {number} [count=0] The number of sequential integers to generate.
- * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
- * the emissions of the notifications.
- * @return {Observable} An Observable of numbers that emits a finite range of
- * sequential integers.
- * @static true
- * @name range
- * @owner Observable
- */
- RangeObservable.create = function (start, count, scheduler) {
- if (start === void 0) { start = 0; }
- if (count === void 0) { count = 0; }
- return new RangeObservable(start, count, scheduler);
- };
- RangeObservable.dispatch = function (state) {
- var start = state.start, index = state.index, count = state.count, subscriber = state.subscriber;
- if (index >= count) {
- subscriber.complete();
- return;
- }
- subscriber.next(start);
- if (subscriber.closed) {
- return;
- }
- state.index = index + 1;
- state.start = start + 1;
- this.schedule(state);
- };
- /** @deprecated internal use only */ RangeObservable.prototype._subscribe = function (subscriber) {
- var index = 0;
- var start = this.start;
- var count = this._count;
- var scheduler = this.scheduler;
- if (scheduler) {
- return scheduler.schedule(RangeObservable.dispatch, 0, {
- index: index, count: count, start: start, subscriber: subscriber
- });
- }
- else {
- do {
- if (index++ >= count) {
- subscriber.complete();
- break;
- }
- subscriber.next(start++);
- if (subscriber.closed) {
- break;
- }
- } while (true);
- }
- };
- return RangeObservable;
- }(Observable));
-
- var range = RangeObservable.create;
-
- Observable.range = range;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var UsingObservable = (function (_super) {
- __extends(UsingObservable, _super);
- function UsingObservable(resourceFactory, observableFactory) {
- _super.call(this);
- this.resourceFactory = resourceFactory;
- this.observableFactory = observableFactory;
- }
- UsingObservable.create = function (resourceFactory, observableFactory) {
- return new UsingObservable(resourceFactory, observableFactory);
- };
- /** @deprecated internal use only */ UsingObservable.prototype._subscribe = function (subscriber) {
- var _a = this, resourceFactory = _a.resourceFactory, observableFactory = _a.observableFactory;
- var resource;
- try {
- resource = resourceFactory();
- return new UsingSubscriber(subscriber, resource, observableFactory);
- }
- catch (err) {
- subscriber.error(err);
- }
- };
- return UsingObservable;
- }(Observable));
- var UsingSubscriber = (function (_super) {
- __extends(UsingSubscriber, _super);
- function UsingSubscriber(destination, resource, observableFactory) {
- _super.call(this, destination);
- this.resource = resource;
- this.observableFactory = observableFactory;
- destination.add(resource);
- this.tryUse();
- }
- UsingSubscriber.prototype.tryUse = function () {
- try {
- var source = this.observableFactory.call(this, this.resource);
- if (source) {
- this.add(subscribeToResult(this, source));
- }
- }
- catch (err) {
- this._error(err);
- }
- };
- return UsingSubscriber;
- }(OuterSubscriber));
-
- var using = UsingObservable.create;
-
- Observable.using = using;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var ErrorObservable = (function (_super) {
- __extends(ErrorObservable, _super);
- function ErrorObservable(error, scheduler) {
- _super.call(this);
- this.error = error;
- this.scheduler = scheduler;
- }
- /**
- * Creates an Observable that emits no items to the Observer and immediately
- * emits an error notification.
- *
- * <span class="informal">Just emits 'error', and nothing else.
- * </span>
- *
- * <img src="./img/throw.png" width="100%">
- *
- * This static operator is useful for creating a simple Observable that only
- * emits the error notification. It can be used for composing with other
- * Observables, such as in a {@link mergeMap}.
- *
- * @example <caption>Emit the number 7, then emit an error.</caption>
- * var result = Rx.Observable.throw(new Error('oops!')).startWith(7);
- * result.subscribe(x => console.log(x), e => console.error(e));
- *
- * @example <caption>Map and flatten numbers to the sequence 'a', 'b', 'c', but throw an error for 13</caption>
- * var interval = Rx.Observable.interval(1000);
- * var result = interval.mergeMap(x =>
- * x === 13 ?
- * Rx.Observable.throw('Thirteens are bad') :
- * Rx.Observable.of('a', 'b', 'c')
- * );
- * result.subscribe(x => console.log(x), e => console.error(e));
- *
- * @see {@link create}
- * @see {@link empty}
- * @see {@link never}
- * @see {@link of}
- *
- * @param {any} error The particular Error to pass to the error notification.
- * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
- * the emission of the error notification.
- * @return {Observable} An error Observable: emits only the error notification
- * using the given error argument.
- * @static true
- * @name throw
- * @owner Observable
- */
- ErrorObservable.create = function (error, scheduler) {
- return new ErrorObservable(error, scheduler);
- };
- ErrorObservable.dispatch = function (arg) {
- var error = arg.error, subscriber = arg.subscriber;
- subscriber.error(error);
- };
- /** @deprecated internal use only */ ErrorObservable.prototype._subscribe = function (subscriber) {
- var error = this.error;
- var scheduler = this.scheduler;
- subscriber.syncErrorThrowable = true;
- if (scheduler) {
- return scheduler.schedule(ErrorObservable.dispatch, 0, {
- error: error, subscriber: subscriber
- });
- }
- else {
- subscriber.error(error);
- }
- };
- return ErrorObservable;
- }(Observable));
-
- var _throw = ErrorObservable.create;
-
- Observable.throw = _throw;
-
- function isDate(value) {
- return value instanceof Date && !isNaN(+value);
- }
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var TimerObservable = (function (_super) {
- __extends(TimerObservable, _super);
- function TimerObservable(dueTime, period, scheduler) {
- if (dueTime === void 0) { dueTime = 0; }
- _super.call(this);
- this.period = -1;
- this.dueTime = 0;
- if (isNumeric(period)) {
- this.period = Number(period) < 1 && 1 || Number(period);
- }
- else if (isScheduler(period)) {
- scheduler = period;
- }
- if (!isScheduler(scheduler)) {
- scheduler = async;
- }
- this.scheduler = scheduler;
- this.dueTime = isDate(dueTime) ?
- (+dueTime - this.scheduler.now()) :
- dueTime;
- }
- /**
- * Creates an Observable that starts emitting after an `initialDelay` and
- * emits ever increasing numbers after each `period` of time thereafter.
- *
- * <span class="informal">Its like {@link interval}, but you can specify when
- * should the emissions start.</span>
- *
- * <img src="./img/timer.png" width="100%">
- *
- * `timer` returns an Observable that emits an infinite sequence of ascending
- * integers, with a constant interval of time, `period` of your choosing
- * between those emissions. The first emission happens after the specified
- * `initialDelay`. The initial delay may be a {@link Date}. By default, this
- * operator uses the `async` IScheduler to provide a notion of time, but you
- * may pass any IScheduler to it. If `period` is not specified, the output
- * Observable emits only one value, `0`. Otherwise, it emits an infinite
- * sequence.
- *
- * @example <caption>Emits ascending numbers, one every second (1000ms), starting after 3 seconds</caption>
- * var numbers = Rx.Observable.timer(3000, 1000);
- * numbers.subscribe(x => console.log(x));
- *
- * @example <caption>Emits one number after five seconds</caption>
- * var numbers = Rx.Observable.timer(5000);
- * numbers.subscribe(x => console.log(x));
- *
- * @see {@link interval}
- * @see {@link delay}
- *
- * @param {number|Date} initialDelay The initial delay time to wait before
- * emitting the first value of `0`.
- * @param {number} [period] The period of time between emissions of the
- * subsequent numbers.
- * @param {Scheduler} [scheduler=async] The IScheduler to use for scheduling
- * the emission of values, and providing a notion of "time".
- * @return {Observable} An Observable that emits a `0` after the
- * `initialDelay` and ever increasing numbers after each `period` of time
- * thereafter.
- * @static true
- * @name timer
- * @owner Observable
- */
- TimerObservable.create = function (initialDelay, period, scheduler) {
- if (initialDelay === void 0) { initialDelay = 0; }
- return new TimerObservable(initialDelay, period, scheduler);
- };
- TimerObservable.dispatch = function (state) {
- var index = state.index, period = state.period, subscriber = state.subscriber;
- var action = this;
- subscriber.next(index);
- if (subscriber.closed) {
- return;
- }
- else if (period === -1) {
- return subscriber.complete();
- }
- state.index = index + 1;
- action.schedule(state, period);
- };
- /** @deprecated internal use only */ TimerObservable.prototype._subscribe = function (subscriber) {
- var index = 0;
- var _a = this, period = _a.period, dueTime = _a.dueTime, scheduler = _a.scheduler;
- return scheduler.schedule(TimerObservable.dispatch, dueTime, {
- index: index, period: period, subscriber: subscriber
- });
- };
- return TimerObservable;
- }(Observable));
-
- var timer = TimerObservable.create;
-
- Observable.timer = timer;
-
- /* tslint:enable:max-line-length */
- /**
- * @param observables
- * @return {Observable<R>}
- * @method zip
- * @owner Observable
- */
- function zip$1() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return function zipOperatorFunction(source) {
- return source.lift.call(zipStatic.apply(void 0, [source].concat(observables)));
- };
- }
- /* tslint:enable:max-line-length */
- /**
- * Combines multiple Observables to create an Observable whose values are calculated from the values, in order, of each
- * of its input Observables.
- *
- * If the latest parameter is a function, this function is used to compute the created value from the input values.
- * Otherwise, an array of the input values is returned.
- *
- * @example <caption>Combine age and name from different sources</caption>
- *
- * let age$ = Observable.of<number>(27, 25, 29);
- * let name$ = Observable.of<string>('Foo', 'Bar', 'Beer');
- * let isDev$ = Observable.of<boolean>(true, true, false);
- *
- * Observable
- * .zip(age$,
- * name$,
- * isDev$,
- * (age: number, name: string, isDev: boolean) => ({ age, name, isDev }))
- * .subscribe(x => console.log(x));
- *
- * // outputs
- * // { age: 27, name: 'Foo', isDev: true }
- * // { age: 25, name: 'Bar', isDev: true }
- * // { age: 29, name: 'Beer', isDev: false }
- *
- * @param observables
- * @return {Observable<R>}
- * @static true
- * @name zip
- * @owner Observable
- */
- function zipStatic() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- var project = observables[observables.length - 1];
- if (typeof project === 'function') {
- observables.pop();
- }
- return new ArrayObservable(observables).lift(new ZipOperator(project));
- }
- var ZipOperator = (function () {
- function ZipOperator(project) {
- this.project = project;
- }
- ZipOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ZipSubscriber(subscriber, this.project));
- };
- return ZipOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ZipSubscriber = (function (_super) {
- __extends(ZipSubscriber, _super);
- function ZipSubscriber(destination, project, values) {
- if (values === void 0) { values = Object.create(null); }
- _super.call(this, destination);
- this.iterators = [];
- this.active = 0;
- this.project = (typeof project === 'function') ? project : null;
- this.values = values;
- }
- ZipSubscriber.prototype._next = function (value) {
- var iterators = this.iterators;
- if (isArray(value)) {
- iterators.push(new StaticArrayIterator(value));
- }
- else if (typeof value[iterator] === 'function') {
- iterators.push(new StaticIterator(value[iterator]()));
- }
- else {
- iterators.push(new ZipBufferIterator(this.destination, this, value));
- }
- };
- ZipSubscriber.prototype._complete = function () {
- var iterators = this.iterators;
- var len = iterators.length;
- if (len === 0) {
- this.destination.complete();
- return;
- }
- this.active = len;
- for (var i = 0; i < len; i++) {
- var iterator$$1 = iterators[i];
- if (iterator$$1.stillUnsubscribed) {
- this.add(iterator$$1.subscribe(iterator$$1, i));
- }
- else {
- this.active--; // not an observable
- }
- }
- };
- ZipSubscriber.prototype.notifyInactive = function () {
- this.active--;
- if (this.active === 0) {
- this.destination.complete();
- }
- };
- ZipSubscriber.prototype.checkIterators = function () {
- var iterators = this.iterators;
- var len = iterators.length;
- var destination = this.destination;
- // abort if not all of them have values
- for (var i = 0; i < len; i++) {
- var iterator$$1 = iterators[i];
- if (typeof iterator$$1.hasValue === 'function' && !iterator$$1.hasValue()) {
- return;
- }
- }
- var shouldComplete = false;
- var args = [];
- for (var i = 0; i < len; i++) {
- var iterator$$1 = iterators[i];
- var result = iterator$$1.next();
- // check to see if it's completed now that you've gotten
- // the next value.
- if (iterator$$1.hasCompleted()) {
- shouldComplete = true;
- }
- if (result.done) {
- destination.complete();
- return;
- }
- args.push(result.value);
- }
- if (this.project) {
- this._tryProject(args);
- }
- else {
- destination.next(args);
- }
- if (shouldComplete) {
- destination.complete();
- }
- };
- ZipSubscriber.prototype._tryProject = function (args) {
- var result;
- try {
- result = this.project.apply(this, args);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.destination.next(result);
- };
- return ZipSubscriber;
- }(Subscriber));
- var StaticIterator = (function () {
- function StaticIterator(iterator$$1) {
- this.iterator = iterator$$1;
- this.nextResult = iterator$$1.next();
- }
- StaticIterator.prototype.hasValue = function () {
- return true;
- };
- StaticIterator.prototype.next = function () {
- var result = this.nextResult;
- this.nextResult = this.iterator.next();
- return result;
- };
- StaticIterator.prototype.hasCompleted = function () {
- var nextResult = this.nextResult;
- return nextResult && nextResult.done;
- };
- return StaticIterator;
- }());
- var StaticArrayIterator = (function () {
- function StaticArrayIterator(array) {
- this.array = array;
- this.index = 0;
- this.length = 0;
- this.length = array.length;
- }
- StaticArrayIterator.prototype[iterator] = function () {
- return this;
- };
- StaticArrayIterator.prototype.next = function (value) {
- var i = this.index++;
- var array = this.array;
- return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
- };
- StaticArrayIterator.prototype.hasValue = function () {
- return this.array.length > this.index;
- };
- StaticArrayIterator.prototype.hasCompleted = function () {
- return this.array.length === this.index;
- };
- return StaticArrayIterator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ZipBufferIterator = (function (_super) {
- __extends(ZipBufferIterator, _super);
- function ZipBufferIterator(destination, parent, observable) {
- _super.call(this, destination);
- this.parent = parent;
- this.observable = observable;
- this.stillUnsubscribed = true;
- this.buffer = [];
- this.isComplete = false;
- }
- ZipBufferIterator.prototype[iterator] = function () {
- return this;
- };
- // NOTE: there is actually a name collision here with Subscriber.next and Iterator.next
- // this is legit because `next()` will never be called by a subscription in this case.
- ZipBufferIterator.prototype.next = function () {
- var buffer = this.buffer;
- if (buffer.length === 0 && this.isComplete) {
- return { value: null, done: true };
- }
- else {
- return { value: buffer.shift(), done: false };
- }
- };
- ZipBufferIterator.prototype.hasValue = function () {
- return this.buffer.length > 0;
- };
- ZipBufferIterator.prototype.hasCompleted = function () {
- return this.buffer.length === 0 && this.isComplete;
- };
- ZipBufferIterator.prototype.notifyComplete = function () {
- if (this.buffer.length > 0) {
- this.isComplete = true;
- this.parent.notifyInactive();
- }
- else {
- this.destination.complete();
- }
- };
- ZipBufferIterator.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.buffer.push(innerValue);
- this.parent.checkIterators();
- };
- ZipBufferIterator.prototype.subscribe = function (value, index) {
- return subscribeToResult(this, this.observable, this, index);
- };
- return ZipBufferIterator;
- }(OuterSubscriber));
-
- var zip$$1 = zipStatic;
-
- Observable.zip = zip$$1;
-
- /**
- * Applies a given `project` function to each value emitted by the source
- * Observable, and emits the resulting values as an Observable.
- *
- * <span class="informal">Like [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map),
- * it passes each source value through a transformation function to get
- * corresponding output values.</span>
- *
- * <img src="./img/map.png" width="100%">
- *
- * Similar to the well known `Array.prototype.map` function, this operator
- * applies a projection to each value and emits that projection in the output
- * Observable.
- *
- * @example <caption>Map every click to the clientX position of that click</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var positions = clicks.map(ev => ev.clientX);
- * positions.subscribe(x => console.log(x));
- *
- * @see {@link mapTo}
- * @see {@link pluck}
- *
- * @param {function(value: T, index: number): R} project The function to apply
- * to each `value` emitted by the source Observable. The `index` parameter is
- * the number `i` for the i-th emission that has happened since the
- * subscription, starting from the number `0`.
- * @param {any} [thisArg] An optional argument to define what `this` is in the
- * `project` function.
- * @return {Observable<R>} An Observable that emits the values from the source
- * Observable transformed by the given `project` function.
- * @method map
- * @owner Observable
- */
- function map(project, thisArg) {
- return function mapOperation(source) {
- if (typeof project !== 'function') {
- throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
- }
- return source.lift(new MapOperator(project, thisArg));
- };
- }
- var MapOperator = (function () {
- function MapOperator(project, thisArg) {
- this.project = project;
- this.thisArg = thisArg;
- }
- MapOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
- };
- return MapOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var MapSubscriber = (function (_super) {
- __extends(MapSubscriber, _super);
- function MapSubscriber(destination, project, thisArg) {
- _super.call(this, destination);
- this.project = project;
- this.count = 0;
- this.thisArg = thisArg || this;
- }
- // NOTE: This looks unoptimized, but it's actually purposefully NOT
- // using try/catch optimizations.
- MapSubscriber.prototype._next = function (value) {
- var result;
- try {
- result = this.project.call(this.thisArg, value, this.count++);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.destination.next(result);
- };
- return MapSubscriber;
- }(Subscriber));
-
- function getCORSRequest() {
- if (_root.XMLHttpRequest) {
- return new _root.XMLHttpRequest();
- }
- else if (!!_root.XDomainRequest) {
- return new _root.XDomainRequest();
- }
- else {
- throw new Error('CORS is not supported by your browser');
- }
- }
- function getXMLHttpRequest() {
- if (_root.XMLHttpRequest) {
- return new _root.XMLHttpRequest();
- }
- else {
- var progId = void 0;
- try {
- var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
- for (var i = 0; i < 3; i++) {
- try {
- progId = progIds[i];
- if (new _root.ActiveXObject(progId)) {
- break;
- }
- }
- catch (e) {
- }
- }
- return new _root.ActiveXObject(progId);
- }
- catch (e) {
- throw new Error('XMLHttpRequest is not supported by your browser');
- }
- }
- }
- function ajaxGet(url, headers) {
- if (headers === void 0) { headers = null; }
- return new AjaxObservable({ method: 'GET', url: url, headers: headers });
- }
-
- function ajaxPost(url, body, headers) {
- return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers });
- }
-
- function ajaxDelete(url, headers) {
- return new AjaxObservable({ method: 'DELETE', url: url, headers: headers });
- }
-
- function ajaxPut(url, body, headers) {
- return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers });
- }
-
- function ajaxPatch(url, body, headers) {
- return new AjaxObservable({ method: 'PATCH', url: url, body: body, headers: headers });
- }
-
- var mapResponse = map(function (x, index) { return x.response; });
- function ajaxGetJSON(url, headers) {
- return mapResponse(new AjaxObservable({
- method: 'GET',
- url: url,
- responseType: 'json',
- headers: headers
- }));
- }
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var AjaxObservable = (function (_super) {
- __extends(AjaxObservable, _super);
- function AjaxObservable(urlOrRequest) {
- _super.call(this);
- var request = {
- async: true,
- createXHR: function () {
- return this.crossDomain ? getCORSRequest.call(this) : getXMLHttpRequest();
- },
- crossDomain: false,
- withCredentials: false,
- headers: {},
- method: 'GET',
- responseType: 'json',
- timeout: 0
- };
- if (typeof urlOrRequest === 'string') {
- request.url = urlOrRequest;
- }
- else {
- for (var prop in urlOrRequest) {
- if (urlOrRequest.hasOwnProperty(prop)) {
- request[prop] = urlOrRequest[prop];
- }
- }
- }
- this.request = request;
- }
- /** @deprecated internal use only */ AjaxObservable.prototype._subscribe = function (subscriber) {
- return new AjaxSubscriber(subscriber, this.request);
- };
- /**
- * Creates an observable for an Ajax request with either a request object with
- * url, headers, etc or a string for a URL.
- *
- * @example
- * source = Rx.Observable.ajax('/products');
- * source = Rx.Observable.ajax({ url: 'products', method: 'GET' });
- *
- * @param {string|Object} request Can be one of the following:
- * A string of the URL to make the Ajax call.
- * An object with the following properties
- * - url: URL of the request
- * - body: The body of the request
- * - method: Method of the request, such as GET, POST, PUT, PATCH, DELETE
- * - async: Whether the request is async
- * - headers: Optional headers
- * - crossDomain: true if a cross domain request, else false
- * - createXHR: a function to override if you need to use an alternate
- * XMLHttpRequest implementation.
- * - resultSelector: a function to use to alter the output value type of
- * the Observable. Gets {@link AjaxResponse} as an argument.
- * @return {Observable} An observable sequence containing the XMLHttpRequest.
- * @static true
- * @name ajax
- * @owner Observable
- */
- AjaxObservable.create = (function () {
- var create = function (urlOrRequest) {
- return new AjaxObservable(urlOrRequest);
- };
- create.get = ajaxGet;
- create.post = ajaxPost;
- create.delete = ajaxDelete;
- create.put = ajaxPut;
- create.patch = ajaxPatch;
- create.getJSON = ajaxGetJSON;
- return create;
- })();
- return AjaxObservable;
- }(Observable));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var AjaxSubscriber = (function (_super) {
- __extends(AjaxSubscriber, _super);
- function AjaxSubscriber(destination, request) {
- _super.call(this, destination);
- this.request = request;
- this.done = false;
- var headers = request.headers = request.headers || {};
- // force CORS if requested
- if (!request.crossDomain && !headers['X-Requested-With']) {
- headers['X-Requested-With'] = 'XMLHttpRequest';
- }
- // ensure content type is set
- if (!('Content-Type' in headers) && !(_root.FormData && request.body instanceof _root.FormData) && typeof request.body !== 'undefined') {
- headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
- }
- // properly serialize body
- request.body = this.serializeBody(request.body, request.headers['Content-Type']);
- this.send();
- }
- AjaxSubscriber.prototype.next = function (e) {
- this.done = true;
- var _a = this, xhr = _a.xhr, request = _a.request, destination = _a.destination;
- var response = new AjaxResponse(e, xhr, request);
- destination.next(response);
- };
- AjaxSubscriber.prototype.send = function () {
- 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;
- var createXHR = request.createXHR;
- var xhr = tryCatch(createXHR).call(request);
- if (xhr === errorObject) {
- this.error(errorObject.e);
- }
- else {
- this.xhr = xhr;
- // set up the events before open XHR
- // https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
- // You need to add the event listeners before calling open() on the request.
- // Otherwise the progress events will not fire.
- this.setupEvents(xhr, request);
- // open XHR
- var result = void 0;
- if (user) {
- result = tryCatch(xhr.open).call(xhr, method, url, async, user, password);
- }
- else {
- result = tryCatch(xhr.open).call(xhr, method, url, async);
- }
- if (result === errorObject) {
- this.error(errorObject.e);
- return null;
- }
- // timeout, responseType and withCredentials can be set once the XHR is open
- if (async) {
- xhr.timeout = request.timeout;
- xhr.responseType = request.responseType;
- }
- if ('withCredentials' in xhr) {
- xhr.withCredentials = !!request.withCredentials;
- }
- // set headers
- this.setHeaders(xhr, headers);
- // finally send the request
- result = body ? tryCatch(xhr.send).call(xhr, body) : tryCatch(xhr.send).call(xhr);
- if (result === errorObject) {
- this.error(errorObject.e);
- return null;
- }
- }
- return xhr;
- };
- AjaxSubscriber.prototype.serializeBody = function (body, contentType) {
- if (!body || typeof body === 'string') {
- return body;
- }
- else if (_root.FormData && body instanceof _root.FormData) {
- return body;
- }
- if (contentType) {
- var splitIndex = contentType.indexOf(';');
- if (splitIndex !== -1) {
- contentType = contentType.substring(0, splitIndex);
- }
- }
- switch (contentType) {
- case 'application/x-www-form-urlencoded':
- return Object.keys(body).map(function (key) { return (encodeURI(key) + "=" + encodeURI(body[key])); }).join('&');
- case 'application/json':
- return JSON.stringify(body);
- default:
- return body;
- }
- };
- AjaxSubscriber.prototype.setHeaders = function (xhr, headers) {
- for (var key in headers) {
- if (headers.hasOwnProperty(key)) {
- xhr.setRequestHeader(key, headers[key]);
- }
- }
- };
- AjaxSubscriber.prototype.setupEvents = function (xhr, request) {
- var progressSubscriber = request.progressSubscriber;
- function xhrTimeout(e) {
- var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
- if (progressSubscriber) {
- progressSubscriber.error(e);
- }
- subscriber.error(new AjaxTimeoutError(this, request)); //TODO: Make betterer.
- }
-
- xhr.ontimeout = xhrTimeout;
- xhrTimeout.request = request;
- xhrTimeout.subscriber = this;
- xhrTimeout.progressSubscriber = progressSubscriber;
- if (xhr.upload && 'withCredentials' in xhr) {
- if (progressSubscriber) {
- var xhrProgress_1;
- xhrProgress_1 = function (e) {
- var progressSubscriber = xhrProgress_1.progressSubscriber;
- progressSubscriber.next(e);
- };
- if (_root.XDomainRequest) {
- xhr.onprogress = xhrProgress_1;
- }
- else {
- xhr.upload.onprogress = xhrProgress_1;
- }
- xhrProgress_1.progressSubscriber = progressSubscriber;
- }
- var xhrError_1;
- xhrError_1 = function (e) {
- var _a = xhrError_1, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request;
- if (progressSubscriber) {
- progressSubscriber.error(e);
- }
- subscriber.error(new AjaxError('ajax error', this, request));
- };
- xhr.onerror = xhrError_1;
- xhrError_1.request = request;
- xhrError_1.subscriber = this;
- xhrError_1.progressSubscriber = progressSubscriber;
- }
- function xhrReadyStateChange(e) {
- var _a = xhrReadyStateChange, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
- if (this.readyState === 4) {
- // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
- var status_1 = this.status === 1223 ? 204 : this.status;
- var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response);
- // fix status code when it is 0 (0 status is undocumented).
- // Occurs when accessing file resources or on Android 4.1 stock browser
- // while retrieving files from application cache.
- if (status_1 === 0) {
- status_1 = response ? 200 : 0;
- }
- if (200 <= status_1 && status_1 < 300) {
- if (progressSubscriber) {
- progressSubscriber.complete();
- }
- subscriber.next(e);
- subscriber.complete();
- }
- else {
- if (progressSubscriber) {
- progressSubscriber.error(e);
- }
- subscriber.error(new AjaxError('ajax error ' + status_1, this, request));
- }
- }
- }
-
- xhr.onreadystatechange = xhrReadyStateChange;
- xhrReadyStateChange.subscriber = this;
- xhrReadyStateChange.progressSubscriber = progressSubscriber;
- xhrReadyStateChange.request = request;
- };
- AjaxSubscriber.prototype.unsubscribe = function () {
- var _a = this, done = _a.done, xhr = _a.xhr;
- if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') {
- xhr.abort();
- }
- _super.prototype.unsubscribe.call(this);
- };
- return AjaxSubscriber;
- }(Subscriber));
- /**
- * A normalized AJAX response.
- *
- * @see {@link ajax}
- *
- * @class AjaxResponse
- */
- var AjaxResponse = (function () {
- function AjaxResponse(originalEvent, xhr, request) {
- this.originalEvent = originalEvent;
- this.xhr = xhr;
- this.request = request;
- this.status = xhr.status;
- this.responseType = xhr.responseType || request.responseType;
- this.response = parseXhrResponse(this.responseType, xhr);
- }
- return AjaxResponse;
- }());
- /**
- * A normalized AJAX error.
- *
- * @see {@link ajax}
- *
- * @class AjaxError
- */
- var AjaxError = (function (_super) {
- __extends(AjaxError, _super);
- function AjaxError(message, xhr, request) {
- _super.call(this, message);
- this.message = message;
- this.xhr = xhr;
- this.request = request;
- this.status = xhr.status;
- this.responseType = xhr.responseType || request.responseType;
- this.response = parseXhrResponse(this.responseType, xhr);
- }
- return AjaxError;
- }(Error));
- function parseXhrResponse(responseType, xhr) {
- switch (responseType) {
- case 'json':
- if ('response' in xhr) {
- //IE does not support json as responseType, parse it internally
- return xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
- }
- else {
- // HACK(benlesh): TypeScript shennanigans
- // tslint:disable-next-line:no-any latest TS seems to think xhr is "never" here.
- return JSON.parse(xhr.responseText || 'null');
- }
- case 'xml':
- return xhr.responseXML;
- case 'text':
- default:
- // HACK(benlesh): TypeScript shennanigans
- // tslint:disable-next-line:no-any latest TS seems to think xhr is "never" here.
- return ('response' in xhr) ? xhr.response : xhr.responseText;
- }
- }
- /**
- * @see {@link ajax}
- *
- * @class AjaxTimeoutError
- */
- var AjaxTimeoutError = (function (_super) {
- __extends(AjaxTimeoutError, _super);
- function AjaxTimeoutError(xhr, request) {
- _super.call(this, 'ajax timeout', xhr, request);
- }
- return AjaxTimeoutError;
- }(AjaxError));
-
- var ajax = AjaxObservable.create;
-
- Observable.ajax = ajax;
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var QueueAction = (function (_super) {
- __extends(QueueAction, _super);
- function QueueAction(scheduler, work) {
- _super.call(this, scheduler, work);
- this.scheduler = scheduler;
- this.work = work;
- }
- QueueAction.prototype.schedule = function (state, delay) {
- if (delay === void 0) { delay = 0; }
- if (delay > 0) {
- return _super.prototype.schedule.call(this, state, delay);
- }
- this.delay = delay;
- this.state = state;
- this.scheduler.flush(this);
- return this;
- };
- QueueAction.prototype.execute = function (state, delay) {
- return (delay > 0 || this.closed) ?
- _super.prototype.execute.call(this, state, delay) :
- this._execute(state, delay);
- };
- QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- // If delay exists and is greater than 0, or if the delay is null (the
- // action wasn't rescheduled) but was originally scheduled as an async
- // action, then recycle as an async action.
- if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
- return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
- }
- // Otherwise flush the scheduler starting with this action.
- return scheduler.flush(this);
- };
- return QueueAction;
- }(AsyncAction));
-
- var QueueScheduler = (function (_super) {
- __extends(QueueScheduler, _super);
- function QueueScheduler() {
- _super.apply(this, arguments);
- }
- return QueueScheduler;
- }(AsyncScheduler));
-
- /**
- *
- * Queue Scheduler
- *
- * <span class="informal">Put every next task on a queue, instead of executing it immediately</span>
- *
- * `queue` scheduler, when used with delay, behaves the same as {@link async} scheduler.
- *
- * When used without delay, it schedules given task synchronously - executes it right when
- * it is scheduled. However when called recursively, that is when inside the scheduled task,
- * another task is scheduled with queue scheduler, instead of executing immediately as well,
- * that task will be put on a queue and wait for current one to finish.
- *
- * This means that when you execute task with `queue` scheduler, you are sure it will end
- * before any other task scheduled with that scheduler will start.
- *
- * @examples <caption>Schedule recursively first, then do something</caption>
- *
- * Rx.Scheduler.queue.schedule(() => {
- * Rx.Scheduler.queue.schedule(() => console.log('second')); // will not happen now, but will be put on a queue
- *
- * console.log('first');
- * });
- *
- * // Logs:
- * // "first"
- * // "second"
- *
- *
- * @example <caption>Reschedule itself recursively</caption>
- *
- * Rx.Scheduler.queue.schedule(function(state) {
- * if (state !== 0) {
- * console.log('before', state);
- * this.schedule(state - 1); // `this` references currently executing Action,
- * // which we reschedule with new state
- * console.log('after', state);
- * }
- * }, 0, 3);
- *
- * // In scheduler that runs recursively, you would expect:
- * // "before", 3
- * // "before", 2
- * // "before", 1
- * // "after", 1
- * // "after", 2
- * // "after", 3
- *
- * // But with queue it logs:
- * // "before", 3
- * // "after", 3
- * // "before", 2
- * // "after", 2
- * // "before", 1
- * // "after", 1
- *
- *
- * @static true
- * @name queue
- * @owner Scheduler
- */
- var queue = new QueueScheduler(QueueAction);
-
- /**
- * @class ReplaySubject<T>
- */
- var ReplaySubject = (function (_super) {
- __extends(ReplaySubject, _super);
- function ReplaySubject(bufferSize, windowTime, scheduler) {
- if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; }
- if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; }
- _super.call(this);
- this.scheduler = scheduler;
- this._events = [];
- this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
- this._windowTime = windowTime < 1 ? 1 : windowTime;
- }
- ReplaySubject.prototype.next = function (value) {
- var now = this._getNow();
- this._events.push(new ReplayEvent(now, value));
- this._trimBufferThenGetEvents();
- _super.prototype.next.call(this, value);
- };
- /** @deprecated internal use only */ ReplaySubject.prototype._subscribe = function (subscriber) {
- var _events = this._trimBufferThenGetEvents();
- var scheduler = this.scheduler;
- var subscription;
- if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- else if (this.hasError) {
- subscription = Subscription.EMPTY;
- }
- else if (this.isStopped) {
- subscription = Subscription.EMPTY;
- }
- else {
- this.observers.push(subscriber);
- subscription = new SubjectSubscription(this, subscriber);
- }
- if (scheduler) {
- subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
- }
- var len = _events.length;
- for (var i = 0; i < len && !subscriber.closed; i++) {
- subscriber.next(_events[i].value);
- }
- if (this.hasError) {
- subscriber.error(this.thrownError);
- }
- else if (this.isStopped) {
- subscriber.complete();
- }
- return subscription;
- };
- ReplaySubject.prototype._getNow = function () {
- return (this.scheduler || queue).now();
- };
- ReplaySubject.prototype._trimBufferThenGetEvents = function () {
- var now = this._getNow();
- var _bufferSize = this._bufferSize;
- var _windowTime = this._windowTime;
- var _events = this._events;
- var eventsCount = _events.length;
- var spliceCount = 0;
- // Trim events that fall out of the time window.
- // Start at the front of the list. Break early once
- // we encounter an event that falls within the window.
- while (spliceCount < eventsCount) {
- if ((now - _events[spliceCount].time) < _windowTime) {
- break;
- }
- spliceCount++;
- }
- if (eventsCount > _bufferSize) {
- spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
- }
- if (spliceCount > 0) {
- _events.splice(0, spliceCount);
- }
- return _events;
- };
- return ReplaySubject;
- }(Subject));
- var ReplayEvent = (function () {
- function ReplayEvent(time, value) {
- this.time = time;
- this.value = value;
- }
- return ReplayEvent;
- }());
-
- function assignImpl(target) {
- var sources = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- sources[_i - 1] = arguments[_i];
- }
- var len = sources.length;
- for (var i = 0; i < len; i++) {
- var source = sources[i];
- for (var k in source) {
- if (source.hasOwnProperty(k)) {
- target[k] = source[k];
- }
- }
- }
- return target;
- }
-
- function getAssign(root$$1) {
- return root$$1.Object.assign || assignImpl;
- }
- var assign = getAssign(_root);
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var WebSocketSubject = (function (_super) {
- __extends(WebSocketSubject, _super);
- function WebSocketSubject(urlConfigOrSource, destination) {
- if (urlConfigOrSource instanceof Observable) {
- _super.call(this, destination, urlConfigOrSource);
- }
- else {
- _super.call(this);
- this.WebSocketCtor = _root.WebSocket;
- this._output = new Subject();
- if (typeof urlConfigOrSource === 'string') {
- this.url = urlConfigOrSource;
- }
- else {
- // WARNING: config object could override important members here.
- assign(this, urlConfigOrSource);
- }
- if (!this.WebSocketCtor) {
- throw new Error('no WebSocket constructor can be found');
- }
- this.destination = new ReplaySubject();
- }
- }
- WebSocketSubject.prototype.resultSelector = function (e) {
- return JSON.parse(e.data);
- };
- /**
- * Wrapper around the w3c-compatible WebSocket object provided by the browser.
- *
- * @example <caption>Wraps browser WebSocket</caption>
- *
- * let socket$ = Observable.webSocket('ws://localhost:8081');
- *
- * socket$.subscribe(
- * (msg) => console.log('message received: ' + msg),
- * (err) => console.log(err),
- * () => console.log('complete')
- * );
- *
- * socket$.next(JSON.stringify({ op: 'hello' }));
- *
- * @example <caption>Wraps WebSocket from nodejs-websocket (using node.js)</caption>
- *
- * import { w3cwebsocket } from 'websocket';
- *
- * let socket$ = Observable.webSocket({
- * url: 'ws://localhost:8081',
- * WebSocketCtor: w3cwebsocket
- * });
- *
- * socket$.subscribe(
- * (msg) => console.log('message received: ' + msg),
- * (err) => console.log(err),
- * () => console.log('complete')
- * );
- *
- * socket$.next(JSON.stringify({ op: 'hello' }));
- *
- * @param {string | WebSocketSubjectConfig} urlConfigOrSource the source of the websocket as an url or a structure defining the websocket object
- * @return {WebSocketSubject}
- * @static true
- * @name webSocket
- * @owner Observable
- */
- WebSocketSubject.create = function (urlConfigOrSource) {
- return new WebSocketSubject(urlConfigOrSource);
- };
- WebSocketSubject.prototype.lift = function (operator) {
- var sock = new WebSocketSubject(this, this.destination);
- sock.operator = operator;
- return sock;
- };
- WebSocketSubject.prototype._resetState = function () {
- this.socket = null;
- if (!this.source) {
- this.destination = new ReplaySubject();
- }
- this._output = new Subject();
- };
- // TODO: factor this out to be a proper Operator/Subscriber implementation and eliminate closures
- WebSocketSubject.prototype.multiplex = function (subMsg, unsubMsg, messageFilter) {
- var self = this;
- return new Observable(function (observer) {
- var result = tryCatch(subMsg)();
- if (result === errorObject) {
- observer.error(errorObject.e);
- }
- else {
- self.next(result);
- }
- var subscription = self.subscribe(function (x) {
- var result = tryCatch(messageFilter)(x);
- if (result === errorObject) {
- observer.error(errorObject.e);
- }
- else if (result) {
- observer.next(x);
- }
- }, function (err) { return observer.error(err); }, function () { return observer.complete(); });
- return function () {
- var result = tryCatch(unsubMsg)();
- if (result === errorObject) {
- observer.error(errorObject.e);
- }
- else {
- self.next(result);
- }
- subscription.unsubscribe();
- };
- });
- };
- WebSocketSubject.prototype._connectSocket = function () {
- var _this = this;
- var WebSocketCtor = this.WebSocketCtor;
- var observer = this._output;
- var socket = null;
- try {
- socket = this.protocol ?
- new WebSocketCtor(this.url, this.protocol) :
- new WebSocketCtor(this.url);
- this.socket = socket;
- if (this.binaryType) {
- this.socket.binaryType = this.binaryType;
- }
- }
- catch (e) {
- observer.error(e);
- return;
- }
- var subscription = new Subscription(function () {
- _this.socket = null;
- if (socket && socket.readyState === 1) {
- socket.close();
- }
- });
- socket.onopen = function (e) {
- var openObserver = _this.openObserver;
- if (openObserver) {
- openObserver.next(e);
- }
- var queue = _this.destination;
- _this.destination = Subscriber.create(function (x) { return socket.readyState === 1 && socket.send(x); }, function (e) {
- var closingObserver = _this.closingObserver;
- if (closingObserver) {
- closingObserver.next(undefined);
- }
- if (e && e.code) {
- socket.close(e.code, e.reason);
- }
- else {
- observer.error(new TypeError('WebSocketSubject.error must be called with an object with an error code, ' +
- 'and an optional reason: { code: number, reason: string }'));
- }
- _this._resetState();
- }, function () {
- var closingObserver = _this.closingObserver;
- if (closingObserver) {
- closingObserver.next(undefined);
- }
- socket.close();
- _this._resetState();
- });
- if (queue && queue instanceof ReplaySubject) {
- subscription.add(queue.subscribe(_this.destination));
- }
- };
- socket.onerror = function (e) {
- _this._resetState();
- observer.error(e);
- };
- socket.onclose = function (e) {
- _this._resetState();
- var closeObserver = _this.closeObserver;
- if (closeObserver) {
- closeObserver.next(e);
- }
- if (e.wasClean) {
- observer.complete();
- }
- else {
- observer.error(e);
- }
- };
- socket.onmessage = function (e) {
- var result = tryCatch(_this.resultSelector)(e);
- if (result === errorObject) {
- observer.error(errorObject.e);
- }
- else {
- observer.next(result);
- }
- };
- };
- /** @deprecated internal use only */ WebSocketSubject.prototype._subscribe = function (subscriber) {
- var _this = this;
- var source = this.source;
- if (source) {
- return source.subscribe(subscriber);
- }
- if (!this.socket) {
- this._connectSocket();
- }
- var subscription = new Subscription();
- subscription.add(this._output.subscribe(subscriber));
- subscription.add(function () {
- var socket = _this.socket;
- if (_this._output.observers.length === 0) {
- if (socket && socket.readyState === 1) {
- socket.close();
- }
- _this._resetState();
- }
- });
- return subscription;
- };
- WebSocketSubject.prototype.unsubscribe = function () {
- var _a = this, source = _a.source, socket = _a.socket;
- if (socket && socket.readyState === 1) {
- socket.close();
- this._resetState();
- }
- _super.prototype.unsubscribe.call(this);
- if (!source) {
- this.destination = new ReplaySubject();
- }
- };
- return WebSocketSubject;
- }(AnonymousSubject));
-
- var webSocket = WebSocketSubject.create;
-
- Observable.webSocket = webSocket;
-
- /**
- * Buffers the source Observable values until `closingNotifier` emits.
- *
- * <span class="informal">Collects values from the past as an array, and emits
- * that array only when another Observable emits.</span>
- *
- * <img src="./img/buffer.png" width="100%">
- *
- * Buffers the incoming Observable values until the given `closingNotifier`
- * Observable emits a value, at which point it emits the buffer on the output
- * Observable and starts a new buffer internally, awaiting the next time
- * `closingNotifier` emits.
- *
- * @example <caption>On every click, emit array of most recent interval events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var interval = Rx.Observable.interval(1000);
- * var buffered = interval.buffer(clicks);
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link bufferCount}
- * @see {@link bufferTime}
- * @see {@link bufferToggle}
- * @see {@link bufferWhen}
- * @see {@link window}
- *
- * @param {Observable<any>} closingNotifier An Observable that signals the
- * buffer to be emitted on the output Observable.
- * @return {Observable<T[]>} An Observable of buffers, which are arrays of
- * values.
- * @method buffer
- * @owner Observable
- */
- function buffer$1(closingNotifier) {
- return function bufferOperatorFunction(source) {
- return source.lift(new BufferOperator(closingNotifier));
- };
- }
- var BufferOperator = (function () {
- function BufferOperator(closingNotifier) {
- this.closingNotifier = closingNotifier;
- }
- BufferOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new BufferSubscriber(subscriber, this.closingNotifier));
- };
- return BufferOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var BufferSubscriber = (function (_super) {
- __extends(BufferSubscriber, _super);
- function BufferSubscriber(destination, closingNotifier) {
- _super.call(this, destination);
- this.buffer = [];
- this.add(subscribeToResult(this, closingNotifier));
- }
- BufferSubscriber.prototype._next = function (value) {
- this.buffer.push(value);
- };
- BufferSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var buffer = this.buffer;
- this.buffer = [];
- this.destination.next(buffer);
- };
- return BufferSubscriber;
- }(OuterSubscriber));
-
- /**
- * Buffers the source Observable values until `closingNotifier` emits.
- *
- * <span class="informal">Collects values from the past as an array, and emits
- * that array only when another Observable emits.</span>
- *
- * <img src="./img/buffer.png" width="100%">
- *
- * Buffers the incoming Observable values until the given `closingNotifier`
- * Observable emits a value, at which point it emits the buffer on the output
- * Observable and starts a new buffer internally, awaiting the next time
- * `closingNotifier` emits.
- *
- * @example <caption>On every click, emit array of most recent interval events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var interval = Rx.Observable.interval(1000);
- * var buffered = interval.buffer(clicks);
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link bufferCount}
- * @see {@link bufferTime}
- * @see {@link bufferToggle}
- * @see {@link bufferWhen}
- * @see {@link window}
- *
- * @param {Observable<any>} closingNotifier An Observable that signals the
- * buffer to be emitted on the output Observable.
- * @return {Observable<T[]>} An Observable of buffers, which are arrays of
- * values.
- * @method buffer
- * @owner Observable
- */
- function buffer$$1(closingNotifier) {
- return buffer$1(closingNotifier)(this);
- }
-
- Observable.prototype.buffer = buffer$$1;
-
- /**
- * Buffers the source Observable values until the size hits the maximum
- * `bufferSize` given.
- *
- * <span class="informal">Collects values from the past as an array, and emits
- * that array only when its size reaches `bufferSize`.</span>
- *
- * <img src="./img/bufferCount.png" width="100%">
- *
- * Buffers a number of values from the source Observable by `bufferSize` then
- * emits the buffer and clears it, and starts a new buffer each
- * `startBufferEvery` values. If `startBufferEvery` is not provided or is
- * `null`, then new buffers are started immediately at the start of the source
- * and when each buffer closes and is emitted.
- *
- * @example <caption>Emit the last two click events as an array</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferCount(2);
- * buffered.subscribe(x => console.log(x));
- *
- * @example <caption>On every click, emit the last two click events as an array</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferCount(2, 1);
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferTime}
- * @see {@link bufferToggle}
- * @see {@link bufferWhen}
- * @see {@link pairwise}
- * @see {@link windowCount}
- *
- * @param {number} bufferSize The maximum size of the buffer emitted.
- * @param {number} [startBufferEvery] Interval at which to start a new buffer.
- * For example if `startBufferEvery` is `2`, then a new buffer will be started
- * on every other value from the source. A new buffer is started at the
- * beginning of the source by default.
- * @return {Observable<T[]>} An Observable of arrays of buffered values.
- * @method bufferCount
- * @owner Observable
- */
- function bufferCount$1(bufferSize, startBufferEvery) {
- if (startBufferEvery === void 0) { startBufferEvery = null; }
- return function bufferCountOperatorFunction(source) {
- return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
- };
- }
- var BufferCountOperator = (function () {
- function BufferCountOperator(bufferSize, startBufferEvery) {
- this.bufferSize = bufferSize;
- this.startBufferEvery = startBufferEvery;
- if (!startBufferEvery || bufferSize === startBufferEvery) {
- this.subscriberClass = BufferCountSubscriber;
- }
- else {
- this.subscriberClass = BufferSkipCountSubscriber;
- }
- }
- BufferCountOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
- };
- return BufferCountOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var BufferCountSubscriber = (function (_super) {
- __extends(BufferCountSubscriber, _super);
- function BufferCountSubscriber(destination, bufferSize) {
- _super.call(this, destination);
- this.bufferSize = bufferSize;
- this.buffer = [];
- }
- BufferCountSubscriber.prototype._next = function (value) {
- var buffer = this.buffer;
- buffer.push(value);
- if (buffer.length == this.bufferSize) {
- this.destination.next(buffer);
- this.buffer = [];
- }
- };
- BufferCountSubscriber.prototype._complete = function () {
- var buffer = this.buffer;
- if (buffer.length > 0) {
- this.destination.next(buffer);
- }
- _super.prototype._complete.call(this);
- };
- return BufferCountSubscriber;
- }(Subscriber));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var BufferSkipCountSubscriber = (function (_super) {
- __extends(BufferSkipCountSubscriber, _super);
- function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
- _super.call(this, destination);
- this.bufferSize = bufferSize;
- this.startBufferEvery = startBufferEvery;
- this.buffers = [];
- this.count = 0;
- }
- BufferSkipCountSubscriber.prototype._next = function (value) {
- var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
- this.count++;
- if (count % startBufferEvery === 0) {
- buffers.push([]);
- }
- for (var i = buffers.length; i--;) {
- var buffer = buffers[i];
- buffer.push(value);
- if (buffer.length === bufferSize) {
- buffers.splice(i, 1);
- this.destination.next(buffer);
- }
- }
- };
- BufferSkipCountSubscriber.prototype._complete = function () {
- var _a = this, buffers = _a.buffers, destination = _a.destination;
- while (buffers.length > 0) {
- var buffer = buffers.shift();
- if (buffer.length > 0) {
- destination.next(buffer);
- }
- }
- _super.prototype._complete.call(this);
- };
- return BufferSkipCountSubscriber;
- }(Subscriber));
-
- /**
- * Buffers the source Observable values until the size hits the maximum
- * `bufferSize` given.
- *
- * <span class="informal">Collects values from the past as an array, and emits
- * that array only when its size reaches `bufferSize`.</span>
- *
- * <img src="./img/bufferCount.png" width="100%">
- *
- * Buffers a number of values from the source Observable by `bufferSize` then
- * emits the buffer and clears it, and starts a new buffer each
- * `startBufferEvery` values. If `startBufferEvery` is not provided or is
- * `null`, then new buffers are started immediately at the start of the source
- * and when each buffer closes and is emitted.
- *
- * @example <caption>Emit the last two click events as an array</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferCount(2);
- * buffered.subscribe(x => console.log(x));
- *
- * @example <caption>On every click, emit the last two click events as an array</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferCount(2, 1);
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferTime}
- * @see {@link bufferToggle}
- * @see {@link bufferWhen}
- * @see {@link pairwise}
- * @see {@link windowCount}
- *
- * @param {number} bufferSize The maximum size of the buffer emitted.
- * @param {number} [startBufferEvery] Interval at which to start a new buffer.
- * For example if `startBufferEvery` is `2`, then a new buffer will be started
- * on every other value from the source. A new buffer is started at the
- * beginning of the source by default.
- * @return {Observable<T[]>} An Observable of arrays of buffered values.
- * @method bufferCount
- * @owner Observable
- */
- function bufferCount$$1(bufferSize, startBufferEvery) {
- if (startBufferEvery === void 0) { startBufferEvery = null; }
- return bufferCount$1(bufferSize, startBufferEvery)(this);
- }
-
- Observable.prototype.bufferCount = bufferCount$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Buffers the source Observable values for a specific time period.
- *
- * <span class="informal">Collects values from the past as an array, and emits
- * those arrays periodically in time.</span>
- *
- * <img src="./img/bufferTime.png" width="100%">
- *
- * Buffers values from the source for a specific time duration `bufferTimeSpan`.
- * Unless the optional argument `bufferCreationInterval` is given, it emits and
- * resets the buffer every `bufferTimeSpan` milliseconds. If
- * `bufferCreationInterval` is given, this operator opens the buffer every
- * `bufferCreationInterval` milliseconds and closes (emits and resets) the
- * buffer every `bufferTimeSpan` milliseconds. When the optional argument
- * `maxBufferSize` is specified, the buffer will be closed either after
- * `bufferTimeSpan` milliseconds or when it contains `maxBufferSize` elements.
- *
- * @example <caption>Every second, emit an array of the recent click events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferTime(1000);
- * buffered.subscribe(x => console.log(x));
- *
- * @example <caption>Every 5 seconds, emit the click events from the next 2 seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferTime(2000, 5000);
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- * @see {@link bufferToggle}
- * @see {@link bufferWhen}
- * @see {@link windowTime}
- *
- * @param {number} bufferTimeSpan The amount of time to fill each buffer array.
- * @param {number} [bufferCreationInterval] The interval at which to start new
- * buffers.
- * @param {number} [maxBufferSize] The maximum buffer size.
- * @param {Scheduler} [scheduler=async] The scheduler on which to schedule the
- * intervals that determine buffer boundaries.
- * @return {Observable<T[]>} An observable of arrays of buffered values.
- * @method bufferTime
- * @owner Observable
- */
- function bufferTime$1(bufferTimeSpan) {
- var length = arguments.length;
- var scheduler = async;
- if (isScheduler(arguments[arguments.length - 1])) {
- scheduler = arguments[arguments.length - 1];
- length--;
- }
- var bufferCreationInterval = null;
- if (length >= 2) {
- bufferCreationInterval = arguments[1];
- }
- var maxBufferSize = Number.POSITIVE_INFINITY;
- if (length >= 3) {
- maxBufferSize = arguments[2];
- }
- return function bufferTimeOperatorFunction(source) {
- return source.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler));
- };
- }
- var BufferTimeOperator = (function () {
- function BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
- this.bufferTimeSpan = bufferTimeSpan;
- this.bufferCreationInterval = bufferCreationInterval;
- this.maxBufferSize = maxBufferSize;
- this.scheduler = scheduler;
- }
- BufferTimeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new BufferTimeSubscriber(subscriber, this.bufferTimeSpan, this.bufferCreationInterval, this.maxBufferSize, this.scheduler));
- };
- return BufferTimeOperator;
- }());
- var Context = (function () {
- function Context() {
- this.buffer = [];
- }
- return Context;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var BufferTimeSubscriber = (function (_super) {
- __extends(BufferTimeSubscriber, _super);
- function BufferTimeSubscriber(destination, bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
- _super.call(this, destination);
- this.bufferTimeSpan = bufferTimeSpan;
- this.bufferCreationInterval = bufferCreationInterval;
- this.maxBufferSize = maxBufferSize;
- this.scheduler = scheduler;
- this.contexts = [];
- var context = this.openContext();
- this.timespanOnly = bufferCreationInterval == null || bufferCreationInterval < 0;
- if (this.timespanOnly) {
- var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan };
- this.add(context.closeAction = scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
- }
- else {
- var closeState = { subscriber: this, context: context };
- var creationState = { bufferTimeSpan: bufferTimeSpan, bufferCreationInterval: bufferCreationInterval, subscriber: this, scheduler: scheduler };
- this.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, closeState));
- this.add(scheduler.schedule(dispatchBufferCreation, bufferCreationInterval, creationState));
- }
- }
- BufferTimeSubscriber.prototype._next = function (value) {
- var contexts = this.contexts;
- var len = contexts.length;
- var filledBufferContext;
- for (var i = 0; i < len; i++) {
- var context = contexts[i];
- var buffer = context.buffer;
- buffer.push(value);
- if (buffer.length == this.maxBufferSize) {
- filledBufferContext = context;
- }
- }
- if (filledBufferContext) {
- this.onBufferFull(filledBufferContext);
- }
- };
- BufferTimeSubscriber.prototype._error = function (err) {
- this.contexts.length = 0;
- _super.prototype._error.call(this, err);
- };
- BufferTimeSubscriber.prototype._complete = function () {
- var _a = this, contexts = _a.contexts, destination = _a.destination;
- while (contexts.length > 0) {
- var context = contexts.shift();
- destination.next(context.buffer);
- }
- _super.prototype._complete.call(this);
- };
- /** @deprecated internal use only */ BufferTimeSubscriber.prototype._unsubscribe = function () {
- this.contexts = null;
- };
- BufferTimeSubscriber.prototype.onBufferFull = function (context) {
- this.closeContext(context);
- var closeAction = context.closeAction;
- closeAction.unsubscribe();
- this.remove(closeAction);
- if (!this.closed && this.timespanOnly) {
- context = this.openContext();
- var bufferTimeSpan = this.bufferTimeSpan;
- var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan };
- this.add(context.closeAction = this.scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
- }
- };
- BufferTimeSubscriber.prototype.openContext = function () {
- var context = new Context();
- this.contexts.push(context);
- return context;
- };
- BufferTimeSubscriber.prototype.closeContext = function (context) {
- this.destination.next(context.buffer);
- var contexts = this.contexts;
- var spliceIndex = contexts ? contexts.indexOf(context) : -1;
- if (spliceIndex >= 0) {
- contexts.splice(contexts.indexOf(context), 1);
- }
- };
- return BufferTimeSubscriber;
- }(Subscriber));
- function dispatchBufferTimeSpanOnly(state) {
- var subscriber = state.subscriber;
- var prevContext = state.context;
- if (prevContext) {
- subscriber.closeContext(prevContext);
- }
- if (!subscriber.closed) {
- state.context = subscriber.openContext();
- state.context.closeAction = this.schedule(state, state.bufferTimeSpan);
- }
- }
- function dispatchBufferCreation(state) {
- var bufferCreationInterval = state.bufferCreationInterval, bufferTimeSpan = state.bufferTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler;
- var context = subscriber.openContext();
- var action = this;
- if (!subscriber.closed) {
- subscriber.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, { subscriber: subscriber, context: context }));
- action.schedule(state, bufferCreationInterval);
- }
- }
- function dispatchBufferClose(arg) {
- var subscriber = arg.subscriber, context = arg.context;
- subscriber.closeContext(context);
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Buffers the source Observable values for a specific time period.
- *
- * <span class="informal">Collects values from the past as an array, and emits
- * those arrays periodically in time.</span>
- *
- * <img src="./img/bufferTime.png" width="100%">
- *
- * Buffers values from the source for a specific time duration `bufferTimeSpan`.
- * Unless the optional argument `bufferCreationInterval` is given, it emits and
- * resets the buffer every `bufferTimeSpan` milliseconds. If
- * `bufferCreationInterval` is given, this operator opens the buffer every
- * `bufferCreationInterval` milliseconds and closes (emits and resets) the
- * buffer every `bufferTimeSpan` milliseconds. When the optional argument
- * `maxBufferSize` is specified, the buffer will be closed either after
- * `bufferTimeSpan` milliseconds or when it contains `maxBufferSize` elements.
- *
- * @example <caption>Every second, emit an array of the recent click events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferTime(1000);
- * buffered.subscribe(x => console.log(x));
- *
- * @example <caption>Every 5 seconds, emit the click events from the next 2 seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferTime(2000, 5000);
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- * @see {@link bufferToggle}
- * @see {@link bufferWhen}
- * @see {@link windowTime}
- *
- * @param {number} bufferTimeSpan The amount of time to fill each buffer array.
- * @param {number} [bufferCreationInterval] The interval at which to start new
- * buffers.
- * @param {number} [maxBufferSize] The maximum buffer size.
- * @param {Scheduler} [scheduler=async] The scheduler on which to schedule the
- * intervals that determine buffer boundaries.
- * @return {Observable<T[]>} An observable of arrays of buffered values.
- * @method bufferTime
- * @owner Observable
- */
- function bufferTime$$1(bufferTimeSpan) {
- var length = arguments.length;
- var scheduler = async;
- if (isScheduler(arguments[arguments.length - 1])) {
- scheduler = arguments[arguments.length - 1];
- length--;
- }
- var bufferCreationInterval = null;
- if (length >= 2) {
- bufferCreationInterval = arguments[1];
- }
- var maxBufferSize = Number.POSITIVE_INFINITY;
- if (length >= 3) {
- maxBufferSize = arguments[2];
- }
- return bufferTime$1(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler)(this);
- }
-
- Observable.prototype.bufferTime = bufferTime$$1;
-
- /**
- * Buffers the source Observable values starting from an emission from
- * `openings` and ending when the output of `closingSelector` emits.
- *
- * <span class="informal">Collects values from the past as an array. Starts
- * collecting only when `opening` emits, and calls the `closingSelector`
- * function to get an Observable that tells when to close the buffer.</span>
- *
- * <img src="./img/bufferToggle.png" width="100%">
- *
- * Buffers values from the source by opening the buffer via signals from an
- * Observable provided to `openings`, and closing and sending the buffers when
- * a Subscribable or Promise returned by the `closingSelector` function emits.
- *
- * @example <caption>Every other second, emit the click events from the next 500ms</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var openings = Rx.Observable.interval(1000);
- * var buffered = clicks.bufferToggle(openings, i =>
- * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
- * );
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- * @see {@link bufferTime}
- * @see {@link bufferWhen}
- * @see {@link windowToggle}
- *
- * @param {SubscribableOrPromise<O>} openings A Subscribable or Promise of notifications to start new
- * buffers.
- * @param {function(value: O): SubscribableOrPromise} closingSelector A function that takes
- * the value emitted by the `openings` observable and returns a Subscribable or Promise,
- * which, when it emits, signals that the associated buffer should be emitted
- * and cleared.
- * @return {Observable<T[]>} An observable of arrays of buffered values.
- * @method bufferToggle
- * @owner Observable
- */
- function bufferToggle$1(openings, closingSelector) {
- return function bufferToggleOperatorFunction(source) {
- return source.lift(new BufferToggleOperator(openings, closingSelector));
- };
- }
- var BufferToggleOperator = (function () {
- function BufferToggleOperator(openings, closingSelector) {
- this.openings = openings;
- this.closingSelector = closingSelector;
- }
- BufferToggleOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));
- };
- return BufferToggleOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var BufferToggleSubscriber = (function (_super) {
- __extends(BufferToggleSubscriber, _super);
- function BufferToggleSubscriber(destination, openings, closingSelector) {
- _super.call(this, destination);
- this.openings = openings;
- this.closingSelector = closingSelector;
- this.contexts = [];
- this.add(subscribeToResult(this, openings));
- }
- BufferToggleSubscriber.prototype._next = function (value) {
- var contexts = this.contexts;
- var len = contexts.length;
- for (var i = 0; i < len; i++) {
- contexts[i].buffer.push(value);
- }
- };
- BufferToggleSubscriber.prototype._error = function (err) {
- var contexts = this.contexts;
- while (contexts.length > 0) {
- var context = contexts.shift();
- context.subscription.unsubscribe();
- context.buffer = null;
- context.subscription = null;
- }
- this.contexts = null;
- _super.prototype._error.call(this, err);
- };
- BufferToggleSubscriber.prototype._complete = function () {
- var contexts = this.contexts;
- while (contexts.length > 0) {
- var context = contexts.shift();
- this.destination.next(context.buffer);
- context.subscription.unsubscribe();
- context.buffer = null;
- context.subscription = null;
- }
- this.contexts = null;
- _super.prototype._complete.call(this);
- };
- BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);
- };
- BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) {
- this.closeBuffer(innerSub.context);
- };
- BufferToggleSubscriber.prototype.openBuffer = function (value) {
- try {
- var closingSelector = this.closingSelector;
- var closingNotifier = closingSelector.call(this, value);
- if (closingNotifier) {
- this.trySubscribe(closingNotifier);
- }
- }
- catch (err) {
- this._error(err);
- }
- };
- BufferToggleSubscriber.prototype.closeBuffer = function (context) {
- var contexts = this.contexts;
- if (contexts && context) {
- var buffer = context.buffer, subscription = context.subscription;
- this.destination.next(buffer);
- contexts.splice(contexts.indexOf(context), 1);
- this.remove(subscription);
- subscription.unsubscribe();
- }
- };
- BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) {
- var contexts = this.contexts;
- var buffer = [];
- var subscription = new Subscription();
- var context = { buffer: buffer, subscription: subscription };
- contexts.push(context);
- var innerSubscription = subscribeToResult(this, closingNotifier, context);
- if (!innerSubscription || innerSubscription.closed) {
- this.closeBuffer(context);
- }
- else {
- innerSubscription.context = context;
- this.add(innerSubscription);
- subscription.add(innerSubscription);
- }
- };
- return BufferToggleSubscriber;
- }(OuterSubscriber));
-
- /**
- * Buffers the source Observable values starting from an emission from
- * `openings` and ending when the output of `closingSelector` emits.
- *
- * <span class="informal">Collects values from the past as an array. Starts
- * collecting only when `opening` emits, and calls the `closingSelector`
- * function to get an Observable that tells when to close the buffer.</span>
- *
- * <img src="./img/bufferToggle.png" width="100%">
- *
- * Buffers values from the source by opening the buffer via signals from an
- * Observable provided to `openings`, and closing and sending the buffers when
- * a Subscribable or Promise returned by the `closingSelector` function emits.
- *
- * @example <caption>Every other second, emit the click events from the next 500ms</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var openings = Rx.Observable.interval(1000);
- * var buffered = clicks.bufferToggle(openings, i =>
- * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
- * );
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- * @see {@link bufferTime}
- * @see {@link bufferWhen}
- * @see {@link windowToggle}
- *
- * @param {SubscribableOrPromise<O>} openings A Subscribable or Promise of notifications to start new
- * buffers.
- * @param {function(value: O): SubscribableOrPromise} closingSelector A function that takes
- * the value emitted by the `openings` observable and returns a Subscribable or Promise,
- * which, when it emits, signals that the associated buffer should be emitted
- * and cleared.
- * @return {Observable<T[]>} An observable of arrays of buffered values.
- * @method bufferToggle
- * @owner Observable
- */
- function bufferToggle$$1(openings, closingSelector) {
- return bufferToggle$1(openings, closingSelector)(this);
- }
-
- Observable.prototype.bufferToggle = bufferToggle$$1;
-
- /**
- * Buffers the source Observable values, using a factory function of closing
- * Observables to determine when to close, emit, and reset the buffer.
- *
- * <span class="informal">Collects values from the past as an array. When it
- * starts collecting values, it calls a function that returns an Observable that
- * tells when to close the buffer and restart collecting.</span>
- *
- * <img src="./img/bufferWhen.png" width="100%">
- *
- * Opens a buffer immediately, then closes the buffer when the observable
- * returned by calling `closingSelector` function emits a value. When it closes
- * the buffer, it immediately opens a new buffer and repeats the process.
- *
- * @example <caption>Emit an array of the last clicks every [1-5] random seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferWhen(() =>
- * Rx.Observable.interval(1000 + Math.random() * 4000)
- * );
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- * @see {@link bufferTime}
- * @see {@link bufferToggle}
- * @see {@link windowWhen}
- *
- * @param {function(): Observable} closingSelector A function that takes no
- * arguments and returns an Observable that signals buffer closure.
- * @return {Observable<T[]>} An observable of arrays of buffered values.
- * @method bufferWhen
- * @owner Observable
- */
- function bufferWhen$1(closingSelector) {
- return function (source) {
- return source.lift(new BufferWhenOperator(closingSelector));
- };
- }
- var BufferWhenOperator = (function () {
- function BufferWhenOperator(closingSelector) {
- this.closingSelector = closingSelector;
- }
- BufferWhenOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
- };
- return BufferWhenOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var BufferWhenSubscriber = (function (_super) {
- __extends(BufferWhenSubscriber, _super);
- function BufferWhenSubscriber(destination, closingSelector) {
- _super.call(this, destination);
- this.closingSelector = closingSelector;
- this.subscribing = false;
- this.openBuffer();
- }
- BufferWhenSubscriber.prototype._next = function (value) {
- this.buffer.push(value);
- };
- BufferWhenSubscriber.prototype._complete = function () {
- var buffer = this.buffer;
- if (buffer) {
- this.destination.next(buffer);
- }
- _super.prototype._complete.call(this);
- };
- /** @deprecated internal use only */ BufferWhenSubscriber.prototype._unsubscribe = function () {
- this.buffer = null;
- this.subscribing = false;
- };
- BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.openBuffer();
- };
- BufferWhenSubscriber.prototype.notifyComplete = function () {
- if (this.subscribing) {
- this.complete();
- }
- else {
- this.openBuffer();
- }
- };
- BufferWhenSubscriber.prototype.openBuffer = function () {
- var closingSubscription = this.closingSubscription;
- if (closingSubscription) {
- this.remove(closingSubscription);
- closingSubscription.unsubscribe();
- }
- var buffer = this.buffer;
- if (this.buffer) {
- this.destination.next(buffer);
- }
- this.buffer = [];
- var closingNotifier = tryCatch(this.closingSelector)();
- if (closingNotifier === errorObject) {
- this.error(errorObject.e);
- }
- else {
- closingSubscription = new Subscription();
- this.closingSubscription = closingSubscription;
- this.add(closingSubscription);
- this.subscribing = true;
- closingSubscription.add(subscribeToResult(this, closingNotifier));
- this.subscribing = false;
- }
- };
- return BufferWhenSubscriber;
- }(OuterSubscriber));
-
- /**
- * Buffers the source Observable values, using a factory function of closing
- * Observables to determine when to close, emit, and reset the buffer.
- *
- * <span class="informal">Collects values from the past as an array. When it
- * starts collecting values, it calls a function that returns an Observable that
- * tells when to close the buffer and restart collecting.</span>
- *
- * <img src="./img/bufferWhen.png" width="100%">
- *
- * Opens a buffer immediately, then closes the buffer when the observable
- * returned by calling `closingSelector` function emits a value. When it closes
- * the buffer, it immediately opens a new buffer and repeats the process.
- *
- * @example <caption>Emit an array of the last clicks every [1-5] random seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var buffered = clicks.bufferWhen(() =>
- * Rx.Observable.interval(1000 + Math.random() * 4000)
- * );
- * buffered.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- * @see {@link bufferTime}
- * @see {@link bufferToggle}
- * @see {@link windowWhen}
- *
- * @param {function(): Observable} closingSelector A function that takes no
- * arguments and returns an Observable that signals buffer closure.
- * @return {Observable<T[]>} An observable of arrays of buffered values.
- * @method bufferWhen
- * @owner Observable
- */
- function bufferWhen$$1(closingSelector) {
- return bufferWhen$1(closingSelector)(this);
- }
-
- Observable.prototype.bufferWhen = bufferWhen$$1;
-
- /**
- * Catches errors on the observable to be handled by returning a new observable or throwing an error.
- *
- * <img src="./img/catch.png" width="100%">
- *
- * @example <caption>Continues with a different Observable when there's an error</caption>
- *
- * Observable.of(1, 2, 3, 4, 5)
- * .map(n => {
- * if (n == 4) {
- * throw 'four!';
- * }
- * return n;
- * })
- * .catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))
- * .subscribe(x => console.log(x));
- * // 1, 2, 3, I, II, III, IV, V
- *
- * @example <caption>Retries the caught source Observable again in case of error, similar to retry() operator</caption>
- *
- * Observable.of(1, 2, 3, 4, 5)
- * .map(n => {
- * if (n === 4) {
- * throw 'four!';
- * }
- * return n;
- * })
- * .catch((err, caught) => caught)
- * .take(30)
- * .subscribe(x => console.log(x));
- * // 1, 2, 3, 1, 2, 3, ...
- *
- * @example <caption>Throws a new error when the source Observable throws an error</caption>
- *
- * Observable.of(1, 2, 3, 4, 5)
- * .map(n => {
- * if (n == 4) {
- * throw 'four!';
- * }
- * return n;
- * })
- * .catch(err => {
- * throw 'error in source. Details: ' + err;
- * })
- * .subscribe(
- * x => console.log(x),
- * err => console.log(err)
- * );
- * // 1, 2, 3, error in source. Details: four!
- *
- * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which
- * is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable
- * is returned by the `selector` will be used to continue the observable chain.
- * @return {Observable} An observable that originates from either the source or the observable returned by the
- * catch `selector` function.
- * @name catchError
- */
- function catchError(selector) {
- return function catchErrorOperatorFunction(source) {
- var operator = new CatchOperator(selector);
- var caught = source.lift(operator);
- return (operator.caught = caught);
- };
- }
- var CatchOperator = (function () {
- function CatchOperator(selector) {
- this.selector = selector;
- }
- CatchOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught));
- };
- return CatchOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var CatchSubscriber = (function (_super) {
- __extends(CatchSubscriber, _super);
- function CatchSubscriber(destination, selector, caught) {
- _super.call(this, destination);
- this.selector = selector;
- this.caught = caught;
- }
- // NOTE: overriding `error` instead of `_error` because we don't want
- // to have this flag this subscriber as `isStopped`. We can mimic the
- // behavior of the RetrySubscriber (from the `retry` operator), where
- // we unsubscribe from our source chain, reset our Subscriber flags,
- // then subscribe to the selector result.
- CatchSubscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- var result = void 0;
- try {
- result = this.selector(err, this.caught);
- }
- catch (err2) {
- _super.prototype.error.call(this, err2);
- return;
- }
- this._unsubscribeAndRecycle();
- this.add(subscribeToResult(this, result));
- }
- };
- return CatchSubscriber;
- }(OuterSubscriber));
-
- /**
- * Catches errors on the observable to be handled by returning a new observable or throwing an error.
- *
- * <img src="./img/catch.png" width="100%">
- *
- * @example <caption>Continues with a different Observable when there's an error</caption>
- *
- * Observable.of(1, 2, 3, 4, 5)
- * .map(n => {
- * if (n == 4) {
- * throw 'four!';
- * }
- * return n;
- * })
- * .catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))
- * .subscribe(x => console.log(x));
- * // 1, 2, 3, I, II, III, IV, V
- *
- * @example <caption>Retries the caught source Observable again in case of error, similar to retry() operator</caption>
- *
- * Observable.of(1, 2, 3, 4, 5)
- * .map(n => {
- * if (n === 4) {
- * throw 'four!';
- * }
- * return n;
- * })
- * .catch((err, caught) => caught)
- * .take(30)
- * .subscribe(x => console.log(x));
- * // 1, 2, 3, 1, 2, 3, ...
- *
- * @example <caption>Throws a new error when the source Observable throws an error</caption>
- *
- * Observable.of(1, 2, 3, 4, 5)
- * .map(n => {
- * if (n == 4) {
- * throw 'four!';
- * }
- * return n;
- * })
- * .catch(err => {
- * throw 'error in source. Details: ' + err;
- * })
- * .subscribe(
- * x => console.log(x),
- * err => console.log(err)
- * );
- * // 1, 2, 3, error in source. Details: four!
- *
- * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which
- * is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable
- * is returned by the `selector` will be used to continue the observable chain.
- * @return {Observable} An observable that originates from either the source or the observable returned by the
- * catch `selector` function.
- * @method catch
- * @name catch
- * @owner Observable
- */
- function _catch(selector) {
- return catchError(selector)(this);
- }
-
- Observable.prototype.catch = _catch;
- Observable.prototype._catch = _catch;
-
- function combineAll$1(project) {
- return function (source) { return source.lift(new CombineLatestOperator(project)); };
- }
-
- /**
- * Converts a higher-order Observable into a first-order Observable by waiting
- * for the outer Observable to complete, then applying {@link combineLatest}.
- *
- * <span class="informal">Flattens an Observable-of-Observables by applying
- * {@link combineLatest} when the Observable-of-Observables completes.</span>
- *
- * <img src="./img/combineAll.png" width="100%">
- *
- * Takes an Observable of Observables, and collects all Observables from it.
- * Once the outer Observable completes, it subscribes to all collected
- * Observables and combines their values using the {@link combineLatest}
- * strategy, such that:
- * - Every time an inner Observable emits, the output Observable emits.
- * - When the returned observable emits, it emits all of the latest values by:
- * - If a `project` function is provided, it is called with each recent value
- * from each inner Observable in whatever order they arrived, and the result
- * of the `project` function is what is emitted by the output Observable.
- * - If there is no `project` function, an array of all of the most recent
- * values is emitted by the output Observable.
- *
- * @example <caption>Map two click events to a finite interval Observable, then apply combineAll</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map(ev =>
- * Rx.Observable.interval(Math.random()*2000).take(3)
- * ).take(2);
- * var result = higherOrder.combineAll();
- * result.subscribe(x => console.log(x));
- *
- * @see {@link combineLatest}
- * @see {@link mergeAll}
- *
- * @param {function} [project] An optional function to map the most recent
- * values from each inner Observable into a new result. Takes each of the most
- * recent values from each collected inner Observable as arguments, in order.
- * @return {Observable} An Observable of projected results or arrays of recent
- * values.
- * @method combineAll
- * @owner Observable
- */
- function combineAll$$1(project) {
- return combineAll$1(project)(this);
- }
-
- Observable.prototype.combineAll = combineAll$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Combines multiple Observables to create an Observable whose values are
- * calculated from the latest values of each of its input Observables.
- *
- * <span class="informal">Whenever any input Observable emits a value, it
- * computes a formula using the latest values from all the inputs, then emits
- * the output of that formula.</span>
- *
- * <img src="./img/combineLatest.png" width="100%">
- *
- * `combineLatest` combines the values from this Observable with values from
- * Observables passed as arguments. This is done by subscribing to each
- * Observable, in order, and collecting an array of each of the most recent
- * values any time any of the input Observables emits, then either taking that
- * array and passing it as arguments to an optional `project` function and
- * emitting the return value of that, or just emitting the array of recent
- * values directly if there is no `project` function.
- *
- * @example <caption>Dynamically calculate the Body-Mass Index from an Observable of weight and one for height</caption>
- * var weight = Rx.Observable.of(70, 72, 76, 79, 75);
- * var height = Rx.Observable.of(1.76, 1.77, 1.78);
- * var bmi = weight.combineLatest(height, (w, h) => w / (h * h));
- * bmi.subscribe(x => console.log('BMI is ' + x));
- *
- * // With output to console:
- * // BMI is 24.212293388429753
- * // BMI is 23.93948099205209
- * // BMI is 23.671253629592222
- *
- * @see {@link combineAll}
- * @see {@link merge}
- * @see {@link withLatestFrom}
- *
- * @param {ObservableInput} other An input Observable to combine with the source
- * Observable. More than one input Observables may be given as argument.
- * @param {function} [project] An optional function to project the values from
- * the combined latest values into a new value on the output Observable.
- * @return {Observable} An Observable of projected values from the most recent
- * values from each input Observable, or an array of the most recent values from
- * each input Observable.
- * @method combineLatest
- * @owner Observable
- */
- function combineLatest$2() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return combineLatest$1.apply(void 0, observables)(this);
- }
-
- Observable.prototype.combineLatest = combineLatest$2;
-
- /* tslint:enable:max-line-length */
- /**
- * Creates an output Observable which sequentially emits all values from every
- * given input Observable after the current Observable.
- *
- * <span class="informal">Concatenates multiple Observables together by
- * sequentially emitting their values, one Observable after the other.</span>
- *
- * <img src="./img/concat.png" width="100%">
- *
- * Joins this Observable with multiple other Observables by subscribing to them
- * one at a time, starting with the source, and merging their results into the
- * output Observable. Will wait for each Observable to complete before moving
- * on to the next.
- *
- * @example <caption>Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10</caption>
- * var timer = Rx.Observable.interval(1000).take(4);
- * var sequence = Rx.Observable.range(1, 10);
- * var result = timer.concat(sequence);
- * result.subscribe(x => console.log(x));
- *
- * // results in:
- * // 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
- *
- * @example <caption>Concatenate 3 Observables</caption>
- * var timer1 = Rx.Observable.interval(1000).take(10);
- * var timer2 = Rx.Observable.interval(2000).take(6);
- * var timer3 = Rx.Observable.interval(500).take(10);
- * var result = timer1.concat(timer2, timer3);
- * result.subscribe(x => console.log(x));
- *
- * // results in the following:
- * // (Prints to console sequentially)
- * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
- * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
- * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9
- *
- * @see {@link concatAll}
- * @see {@link concatMap}
- * @see {@link concatMapTo}
- *
- * @param {ObservableInput} other An input Observable to concatenate after the source
- * Observable. More than one input Observables may be given as argument.
- * @param {Scheduler} [scheduler=null] An optional IScheduler to schedule each
- * Observable subscription on.
- * @return {Observable} All values of each passed Observable merged into a
- * single Observable, in order, in serial fashion.
- * @method concat
- * @owner Observable
- */
- function concat$2() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return function (source) { return source.lift.call(concat.apply(void 0, [source].concat(observables))); };
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Creates an output Observable which sequentially emits all values from every
- * given input Observable after the current Observable.
- *
- * <span class="informal">Concatenates multiple Observables together by
- * sequentially emitting their values, one Observable after the other.</span>
- *
- * <img src="./img/concat.png" width="100%">
- *
- * Joins this Observable with multiple other Observables by subscribing to them
- * one at a time, starting with the source, and merging their results into the
- * output Observable. Will wait for each Observable to complete before moving
- * on to the next.
- *
- * @example <caption>Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10</caption>
- * var timer = Rx.Observable.interval(1000).take(4);
- * var sequence = Rx.Observable.range(1, 10);
- * var result = timer.concat(sequence);
- * result.subscribe(x => console.log(x));
- *
- * // results in:
- * // 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
- *
- * @example <caption>Concatenate 3 Observables</caption>
- * var timer1 = Rx.Observable.interval(1000).take(10);
- * var timer2 = Rx.Observable.interval(2000).take(6);
- * var timer3 = Rx.Observable.interval(500).take(10);
- * var result = timer1.concat(timer2, timer3);
- * result.subscribe(x => console.log(x));
- *
- * // results in the following:
- * // (Prints to console sequentially)
- * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
- * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
- * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9
- *
- * @see {@link concatAll}
- * @see {@link concatMap}
- * @see {@link concatMapTo}
- *
- * @param {ObservableInput} other An input Observable to concatenate after the source
- * Observable. More than one input Observables may be given as argument.
- * @param {Scheduler} [scheduler=null] An optional IScheduler to schedule each
- * Observable subscription on.
- * @return {Observable} All values of each passed Observable merged into a
- * single Observable, in order, in serial fashion.
- * @method concat
- * @owner Observable
- */
- function concat$1() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return concat$2.apply(void 0, observables)(this);
- }
-
- Observable.prototype.concat = concat$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Converts a higher-order Observable into a first-order Observable by
- * concatenating the inner Observables in order.
- *
- * <span class="informal">Flattens an Observable-of-Observables by putting one
- * inner Observable after the other.</span>
- *
- * <img src="./img/concatAll.png" width="100%">
- *
- * Joins every Observable emitted by the source (a higher-order Observable), in
- * a serial fashion. It subscribes to each inner Observable only after the
- * previous inner Observable has completed, and merges all of their values into
- * the returned observable.
- *
- * __Warning:__ If the source Observable emits Observables quickly and
- * endlessly, and the inner Observables it emits generally complete slower than
- * the source emits, you can run into memory issues as the incoming Observables
- * collect in an unbounded buffer.
- *
- * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set
- * to `1`.
- *
- * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map(ev => Rx.Observable.interval(1000).take(4));
- * var firstOrder = higherOrder.concatAll();
- * firstOrder.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // (results are not concurrent)
- * // For every click on the "document" it will emit values 0 to 3 spaced
- * // on a 1000ms interval
- * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
- *
- * @see {@link combineAll}
- * @see {@link concat}
- * @see {@link concatMap}
- * @see {@link concatMapTo}
- * @see {@link exhaust}
- * @see {@link mergeAll}
- * @see {@link switch}
- * @see {@link zipAll}
- *
- * @return {Observable} An Observable emitting values from all the inner
- * Observables concatenated.
- * @method concatAll
- * @owner Observable
- */
- function concatAll$1() {
- return concatAll()(this);
- }
-
- Observable.prototype.concatAll = concatAll$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable, in a serialized fashion waiting for each one to complete before
- * merging the next.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link concatAll}.</span>
- *
- * <img src="./img/concatMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an (so-called "inner") Observable. Each new inner Observable is
- * concatenated with the previous inner Observable.
- *
- * __Warning:__ if source values arrive endlessly and faster than their
- * corresponding inner Observables can complete, it will result in memory issues
- * as inner Observables amass in an unbounded buffer waiting for their turn to
- * be subscribed to.
- *
- * Note: `concatMap` is equivalent to `mergeMap` with concurrency parameter set
- * to `1`.
- *
- * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.concatMap(ev => Rx.Observable.interval(1000).take(4));
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // (results are not concurrent)
- * // For every click on the "document" it will emit values 0 to 3 spaced
- * // on a 1000ms interval
- * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
- *
- * @see {@link concat}
- * @see {@link concatAll}
- * @see {@link concatMapTo}
- * @see {@link exhaustMap}
- * @see {@link mergeMap}
- * @see {@link switchMap}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable that emits the result of applying the
- * projection function (and the optional `resultSelector`) to each item emitted
- * by the source Observable and taking values from each projected inner
- * Observable sequentially.
- * @method concatMap
- * @owner Observable
- */
- function concatMap$1(project, resultSelector) {
- return mergeMap(project, resultSelector, 1);
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable, in a serialized fashion waiting for each one to complete before
- * merging the next.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link concatAll}.</span>
- *
- * <img src="./img/concatMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an (so-called "inner") Observable. Each new inner Observable is
- * concatenated with the previous inner Observable.
- *
- * __Warning:__ if source values arrive endlessly and faster than their
- * corresponding inner Observables can complete, it will result in memory issues
- * as inner Observables amass in an unbounded buffer waiting for their turn to
- * be subscribed to.
- *
- * Note: `concatMap` is equivalent to `mergeMap` with concurrency parameter set
- * to `1`.
- *
- * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.concatMap(ev => Rx.Observable.interval(1000).take(4));
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // (results are not concurrent)
- * // For every click on the "document" it will emit values 0 to 3 spaced
- * // on a 1000ms interval
- * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
- *
- * @see {@link concat}
- * @see {@link concatAll}
- * @see {@link concatMapTo}
- * @see {@link exhaustMap}
- * @see {@link mergeMap}
- * @see {@link switchMap}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable that emits the result of applying the
- * projection function (and the optional `resultSelector`) to each item emitted
- * by the source Observable and taking values from each projected inner
- * Observable sequentially.
- * @method concatMap
- * @owner Observable
- */
- function concatMap$$1(project, resultSelector) {
- return concatMap$1(project, resultSelector)(this);
- }
-
- Observable.prototype.concatMap = concatMap$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to the same Observable which is merged multiple
- * times in a serialized fashion on the output Observable.
- *
- * <span class="informal">It's like {@link concatMap}, but maps each value
- * always to the same inner Observable.</span>
- *
- * <img src="./img/concatMapTo.png" width="100%">
- *
- * Maps each source value to the given Observable `innerObservable` regardless
- * of the source value, and then flattens those resulting Observables into one
- * single Observable, which is the output Observable. Each new `innerObservable`
- * instance emitted on the output Observable is concatenated with the previous
- * `innerObservable` instance.
- *
- * __Warning:__ if source values arrive endlessly and faster than their
- * corresponding inner Observables can complete, it will result in memory issues
- * as inner Observables amass in an unbounded buffer waiting for their turn to
- * be subscribed to.
- *
- * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter
- * set to `1`.
- *
- * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.concatMapTo(Rx.Observable.interval(1000).take(4));
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // (results are not concurrent)
- * // For every click on the "document" it will emit values 0 to 3 spaced
- * // on a 1000ms interval
- * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
- *
- * @see {@link concat}
- * @see {@link concatAll}
- * @see {@link concatMap}
- * @see {@link mergeMapTo}
- * @see {@link switchMapTo}
- *
- * @param {ObservableInput} innerObservable An Observable to replace each value from
- * the source Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An observable of values merged together by joining the
- * passed observable with itself, one after the other, for each value emitted
- * from the source.
- * @method concatMapTo
- * @owner Observable
- */
- function concatMapTo$1(innerObservable, resultSelector) {
- return concatMap$1(function () { return innerObservable; }, resultSelector);
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to the same Observable which is merged multiple
- * times in a serialized fashion on the output Observable.
- *
- * <span class="informal">It's like {@link concatMap}, but maps each value
- * always to the same inner Observable.</span>
- *
- * <img src="./img/concatMapTo.png" width="100%">
- *
- * Maps each source value to the given Observable `innerObservable` regardless
- * of the source value, and then flattens those resulting Observables into one
- * single Observable, which is the output Observable. Each new `innerObservable`
- * instance emitted on the output Observable is concatenated with the previous
- * `innerObservable` instance.
- *
- * __Warning:__ if source values arrive endlessly and faster than their
- * corresponding inner Observables can complete, it will result in memory issues
- * as inner Observables amass in an unbounded buffer waiting for their turn to
- * be subscribed to.
- *
- * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter
- * set to `1`.
- *
- * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.concatMapTo(Rx.Observable.interval(1000).take(4));
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // (results are not concurrent)
- * // For every click on the "document" it will emit values 0 to 3 spaced
- * // on a 1000ms interval
- * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
- *
- * @see {@link concat}
- * @see {@link concatAll}
- * @see {@link concatMap}
- * @see {@link mergeMapTo}
- * @see {@link switchMapTo}
- *
- * @param {ObservableInput} innerObservable An Observable to replace each value from
- * the source Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An observable of values merged together by joining the
- * passed observable with itself, one after the other, for each value emitted
- * from the source.
- * @method concatMapTo
- * @owner Observable
- */
- function concatMapTo$$1(innerObservable, resultSelector) {
- return concatMapTo$1(innerObservable, resultSelector)(this);
- }
-
- Observable.prototype.concatMapTo = concatMapTo$$1;
-
- /**
- * Counts the number of emissions on the source and emits that number when the
- * source completes.
- *
- * <span class="informal">Tells how many values were emitted, when the source
- * completes.</span>
- *
- * <img src="./img/count.png" width="100%">
- *
- * `count` transforms an Observable that emits values into an Observable that
- * emits a single value that represents the number of values emitted by the
- * source Observable. If the source Observable terminates with an error, `count`
- * will pass this error notification along without emitting a value first. If
- * the source Observable does not terminate at all, `count` will neither emit
- * a value nor terminate. This operator takes an optional `predicate` function
- * as argument, in which case the output emission will represent the number of
- * source values that matched `true` with the `predicate`.
- *
- * @example <caption>Counts how many seconds have passed before the first click happened</caption>
- * var seconds = Rx.Observable.interval(1000);
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var secondsBeforeClick = seconds.takeUntil(clicks);
- * var result = secondsBeforeClick.count();
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Counts how many odd numbers are there between 1 and 7</caption>
- * var numbers = Rx.Observable.range(1, 7);
- * var result = numbers.count(i => i % 2 === 1);
- * result.subscribe(x => console.log(x));
- *
- * // Results in:
- * // 4
- *
- * @see {@link max}
- * @see {@link min}
- * @see {@link reduce}
- *
- * @param {function(value: T, i: number, source: Observable<T>): boolean} [predicate] A
- * boolean function to select what values are to be counted. It is provided with
- * arguments of:
- * - `value`: the value from the source Observable.
- * - `index`: the (zero-based) "index" of the value from the source Observable.
- * - `source`: the source Observable instance itself.
- * @return {Observable} An Observable of one number that represents the count as
- * described above.
- * @method count
- * @owner Observable
- */
- function count$1(predicate) {
- return function (source) { return source.lift(new CountOperator(predicate, source)); };
- }
- var CountOperator = (function () {
- function CountOperator(predicate, source) {
- this.predicate = predicate;
- this.source = source;
- }
- CountOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new CountSubscriber(subscriber, this.predicate, this.source));
- };
- return CountOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var CountSubscriber = (function (_super) {
- __extends(CountSubscriber, _super);
- function CountSubscriber(destination, predicate, source) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.source = source;
- this.count = 0;
- this.index = 0;
- }
- CountSubscriber.prototype._next = function (value) {
- if (this.predicate) {
- this._tryPredicate(value);
- }
- else {
- this.count++;
- }
- };
- CountSubscriber.prototype._tryPredicate = function (value) {
- var result;
- try {
- result = this.predicate(value, this.index++, this.source);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- if (result) {
- this.count++;
- }
- };
- CountSubscriber.prototype._complete = function () {
- this.destination.next(this.count);
- this.destination.complete();
- };
- return CountSubscriber;
- }(Subscriber));
-
- /**
- * Counts the number of emissions on the source and emits that number when the
- * source completes.
- *
- * <span class="informal">Tells how many values were emitted, when the source
- * completes.</span>
- *
- * <img src="./img/count.png" width="100%">
- *
- * `count` transforms an Observable that emits values into an Observable that
- * emits a single value that represents the number of values emitted by the
- * source Observable. If the source Observable terminates with an error, `count`
- * will pass this error notification along without emitting a value first. If
- * the source Observable does not terminate at all, `count` will neither emit
- * a value nor terminate. This operator takes an optional `predicate` function
- * as argument, in which case the output emission will represent the number of
- * source values that matched `true` with the `predicate`.
- *
- * @example <caption>Counts how many seconds have passed before the first click happened</caption>
- * var seconds = Rx.Observable.interval(1000);
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var secondsBeforeClick = seconds.takeUntil(clicks);
- * var result = secondsBeforeClick.count();
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Counts how many odd numbers are there between 1 and 7</caption>
- * var numbers = Rx.Observable.range(1, 7);
- * var result = numbers.count(i => i % 2 === 1);
- * result.subscribe(x => console.log(x));
- *
- * // Results in:
- * // 4
- *
- * @see {@link max}
- * @see {@link min}
- * @see {@link reduce}
- *
- * @param {function(value: T, i: number, source: Observable<T>): boolean} [predicate] A
- * boolean function to select what values are to be counted. It is provided with
- * arguments of:
- * - `value`: the value from the source Observable.
- * - `index`: the (zero-based) "index" of the value from the source Observable.
- * - `source`: the source Observable instance itself.
- * @return {Observable} An Observable of one number that represents the count as
- * described above.
- * @method count
- * @owner Observable
- */
- function count$$1(predicate) {
- return count$1(predicate)(this);
- }
-
- Observable.prototype.count = count$$1;
-
- /**
- * Converts an Observable of {@link Notification} objects into the emissions
- * that they represent.
- *
- * <span class="informal">Unwraps {@link Notification} objects as actual `next`,
- * `error` and `complete` emissions. The opposite of {@link materialize}.</span>
- *
- * <img src="./img/dematerialize.png" width="100%">
- *
- * `dematerialize` is assumed to operate an Observable that only emits
- * {@link Notification} objects as `next` emissions, and does not emit any
- * `error`. Such Observable is the output of a `materialize` operation. Those
- * notifications are then unwrapped using the metadata they contain, and emitted
- * as `next`, `error`, and `complete` on the output Observable.
- *
- * Use this operator in conjunction with {@link materialize}.
- *
- * @example <caption>Convert an Observable of Notifications to an actual Observable</caption>
- * var notifA = new Rx.Notification('N', 'A');
- * var notifB = new Rx.Notification('N', 'B');
- * var notifE = new Rx.Notification('E', void 0,
- * new TypeError('x.toUpperCase is not a function')
- * );
- * var materialized = Rx.Observable.of(notifA, notifB, notifE);
- * var upperCase = materialized.dematerialize();
- * upperCase.subscribe(x => console.log(x), e => console.error(e));
- *
- * // Results in:
- * // A
- * // B
- * // TypeError: x.toUpperCase is not a function
- *
- * @see {@link Notification}
- * @see {@link materialize}
- *
- * @return {Observable} An Observable that emits items and notifications
- * embedded in Notification objects emitted by the source Observable.
- * @method dematerialize
- * @owner Observable
- */
- function dematerialize$1() {
- return function dematerializeOperatorFunction(source) {
- return source.lift(new DeMaterializeOperator());
- };
- }
- var DeMaterializeOperator = (function () {
- function DeMaterializeOperator() {
- }
- DeMaterializeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DeMaterializeSubscriber(subscriber));
- };
- return DeMaterializeOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DeMaterializeSubscriber = (function (_super) {
- __extends(DeMaterializeSubscriber, _super);
- function DeMaterializeSubscriber(destination) {
- _super.call(this, destination);
- }
- DeMaterializeSubscriber.prototype._next = function (value) {
- value.observe(this.destination);
- };
- return DeMaterializeSubscriber;
- }(Subscriber));
-
- /**
- * Converts an Observable of {@link Notification} objects into the emissions
- * that they represent.
- *
- * <span class="informal">Unwraps {@link Notification} objects as actual `next`,
- * `error` and `complete` emissions. The opposite of {@link materialize}.</span>
- *
- * <img src="./img/dematerialize.png" width="100%">
- *
- * `dematerialize` is assumed to operate an Observable that only emits
- * {@link Notification} objects as `next` emissions, and does not emit any
- * `error`. Such Observable is the output of a `materialize` operation. Those
- * notifications are then unwrapped using the metadata they contain, and emitted
- * as `next`, `error`, and `complete` on the output Observable.
- *
- * Use this operator in conjunction with {@link materialize}.
- *
- * @example <caption>Convert an Observable of Notifications to an actual Observable</caption>
- * var notifA = new Rx.Notification('N', 'A');
- * var notifB = new Rx.Notification('N', 'B');
- * var notifE = new Rx.Notification('E', void 0,
- * new TypeError('x.toUpperCase is not a function')
- * );
- * var materialized = Rx.Observable.of(notifA, notifB, notifE);
- * var upperCase = materialized.dematerialize();
- * upperCase.subscribe(x => console.log(x), e => console.error(e));
- *
- * // Results in:
- * // A
- * // B
- * // TypeError: x.toUpperCase is not a function
- *
- * @see {@link Notification}
- * @see {@link materialize}
- *
- * @return {Observable} An Observable that emits items and notifications
- * embedded in Notification objects emitted by the source Observable.
- * @method dematerialize
- * @owner Observable
- */
- function dematerialize$$1() {
- return dematerialize$1()(this);
- }
-
- Observable.prototype.dematerialize = dematerialize$$1;
-
- /**
- * Emits a value from the source Observable only after a particular time span
- * determined by another Observable has passed without another source emission.
- *
- * <span class="informal">It's like {@link debounceTime}, but the time span of
- * emission silence is determined by a second Observable.</span>
- *
- * <img src="./img/debounce.png" width="100%">
- *
- * `debounce` delays values emitted by the source Observable, but drops previous
- * pending delayed emissions if a new value arrives on the source Observable.
- * This operator keeps track of the most recent value from the source
- * Observable, and spawns a duration Observable by calling the
- * `durationSelector` function. The value is emitted only when the duration
- * Observable emits a value or completes, and if no other value was emitted on
- * the source Observable since the duration Observable was spawned. If a new
- * value appears before the duration Observable emits, the previous value will
- * be dropped and will not be emitted on the output Observable.
- *
- * Like {@link debounceTime}, this is a rate-limiting operator, and also a
- * delay-like operator since output emissions do not necessarily occur at the
- * same time as they did on the source Observable.
- *
- * @example <caption>Emit the most recent click after a burst of clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.debounce(() => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounceTime}
- * @see {@link delayWhen}
- * @see {@link throttle}
- *
- * @param {function(value: T): SubscribableOrPromise} durationSelector A function
- * that receives a value from the source Observable, for computing the timeout
- * duration for each source value, returned as an Observable or a Promise.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by the specified duration Observable returned by
- * `durationSelector`, and may drop some values if they occur too frequently.
- * @method debounce
- * @owner Observable
- */
- function debounce$1(durationSelector) {
- return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
- }
- var DebounceOperator = (function () {
- function DebounceOperator(durationSelector) {
- this.durationSelector = durationSelector;
- }
- DebounceOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
- };
- return DebounceOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DebounceSubscriber = (function (_super) {
- __extends(DebounceSubscriber, _super);
- function DebounceSubscriber(destination, durationSelector) {
- _super.call(this, destination);
- this.durationSelector = durationSelector;
- this.hasValue = false;
- this.durationSubscription = null;
- }
- DebounceSubscriber.prototype._next = function (value) {
- try {
- var result = this.durationSelector.call(this, value);
- if (result) {
- this._tryNext(value, result);
- }
- }
- catch (err) {
- this.destination.error(err);
- }
- };
- DebounceSubscriber.prototype._complete = function () {
- this.emitValue();
- this.destination.complete();
- };
- DebounceSubscriber.prototype._tryNext = function (value, duration) {
- var subscription = this.durationSubscription;
- this.value = value;
- this.hasValue = true;
- if (subscription) {
- subscription.unsubscribe();
- this.remove(subscription);
- }
- subscription = subscribeToResult(this, duration);
- if (!subscription.closed) {
- this.add(this.durationSubscription = subscription);
- }
- };
- DebounceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.emitValue();
- };
- DebounceSubscriber.prototype.notifyComplete = function () {
- this.emitValue();
- };
- DebounceSubscriber.prototype.emitValue = function () {
- if (this.hasValue) {
- var value = this.value;
- var subscription = this.durationSubscription;
- if (subscription) {
- this.durationSubscription = null;
- subscription.unsubscribe();
- this.remove(subscription);
- }
- this.value = null;
- this.hasValue = false;
- _super.prototype._next.call(this, value);
- }
- };
- return DebounceSubscriber;
- }(OuterSubscriber));
-
- /**
- * Emits a value from the source Observable only after a particular time span
- * determined by another Observable has passed without another source emission.
- *
- * <span class="informal">It's like {@link debounceTime}, but the time span of
- * emission silence is determined by a second Observable.</span>
- *
- * <img src="./img/debounce.png" width="100%">
- *
- * `debounce` delays values emitted by the source Observable, but drops previous
- * pending delayed emissions if a new value arrives on the source Observable.
- * This operator keeps track of the most recent value from the source
- * Observable, and spawns a duration Observable by calling the
- * `durationSelector` function. The value is emitted only when the duration
- * Observable emits a value or completes, and if no other value was emitted on
- * the source Observable since the duration Observable was spawned. If a new
- * value appears before the duration Observable emits, the previous value will
- * be dropped and will not be emitted on the output Observable.
- *
- * Like {@link debounceTime}, this is a rate-limiting operator, and also a
- * delay-like operator since output emissions do not necessarily occur at the
- * same time as they did on the source Observable.
- *
- * @example <caption>Emit the most recent click after a burst of clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.debounce(() => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounceTime}
- * @see {@link delayWhen}
- * @see {@link throttle}
- *
- * @param {function(value: T): SubscribableOrPromise} durationSelector A function
- * that receives a value from the source Observable, for computing the timeout
- * duration for each source value, returned as an Observable or a Promise.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by the specified duration Observable returned by
- * `durationSelector`, and may drop some values if they occur too frequently.
- * @method debounce
- * @owner Observable
- */
- function debounce$$1(durationSelector) {
- return debounce$1(durationSelector)(this);
- }
-
- Observable.prototype.debounce = debounce$$1;
-
- /**
- * Emits a value from the source Observable only after a particular time span
- * has passed without another source emission.
- *
- * <span class="informal">It's like {@link delay}, but passes only the most
- * recent value from each burst of emissions.</span>
- *
- * <img src="./img/debounceTime.png" width="100%">
- *
- * `debounceTime` delays values emitted by the source Observable, but drops
- * previous pending delayed emissions if a new value arrives on the source
- * Observable. This operator keeps track of the most recent value from the
- * source Observable, and emits that only when `dueTime` enough time has passed
- * without any other value appearing on the source Observable. If a new value
- * appears before `dueTime` silence occurs, the previous value will be dropped
- * and will not be emitted on the output Observable.
- *
- * This is a rate-limiting operator, because it is impossible for more than one
- * value to be emitted in any time window of duration `dueTime`, but it is also
- * a delay-like operator since output emissions do not occur at the same time as
- * they did on the source Observable. Optionally takes a {@link IScheduler} for
- * managing timers.
- *
- * @example <caption>Emit the most recent click after a burst of clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.debounceTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounce}
- * @see {@link delay}
- * @see {@link sampleTime}
- * @see {@link throttleTime}
- *
- * @param {number} dueTime The timeout duration in milliseconds (or the time
- * unit determined internally by the optional `scheduler`) for the window of
- * time required to wait for emission silence before emitting the most recent
- * source value.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the timeout for each value.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by the specified `dueTime`, and may drop some values if they occur
- * too frequently.
- * @method debounceTime
- * @owner Observable
- */
- function debounceTime$1(dueTime, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return function (source) { return source.lift(new DebounceTimeOperator(dueTime, scheduler)); };
- }
- var DebounceTimeOperator = (function () {
- function DebounceTimeOperator(dueTime, scheduler) {
- this.dueTime = dueTime;
- this.scheduler = scheduler;
- }
- DebounceTimeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
- };
- return DebounceTimeOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DebounceTimeSubscriber = (function (_super) {
- __extends(DebounceTimeSubscriber, _super);
- function DebounceTimeSubscriber(destination, dueTime, scheduler) {
- _super.call(this, destination);
- this.dueTime = dueTime;
- this.scheduler = scheduler;
- this.debouncedSubscription = null;
- this.lastValue = null;
- this.hasValue = false;
- }
- DebounceTimeSubscriber.prototype._next = function (value) {
- this.clearDebounce();
- this.lastValue = value;
- this.hasValue = true;
- this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext$3, this.dueTime, this));
- };
- DebounceTimeSubscriber.prototype._complete = function () {
- this.debouncedNext();
- this.destination.complete();
- };
- DebounceTimeSubscriber.prototype.debouncedNext = function () {
- this.clearDebounce();
- if (this.hasValue) {
- this.destination.next(this.lastValue);
- this.lastValue = null;
- this.hasValue = false;
- }
- };
- DebounceTimeSubscriber.prototype.clearDebounce = function () {
- var debouncedSubscription = this.debouncedSubscription;
- if (debouncedSubscription !== null) {
- this.remove(debouncedSubscription);
- debouncedSubscription.unsubscribe();
- this.debouncedSubscription = null;
- }
- };
- return DebounceTimeSubscriber;
- }(Subscriber));
- function dispatchNext$3(subscriber) {
- subscriber.debouncedNext();
- }
-
- /**
- * Emits a value from the source Observable only after a particular time span
- * has passed without another source emission.
- *
- * <span class="informal">It's like {@link delay}, but passes only the most
- * recent value from each burst of emissions.</span>
- *
- * <img src="./img/debounceTime.png" width="100%">
- *
- * `debounceTime` delays values emitted by the source Observable, but drops
- * previous pending delayed emissions if a new value arrives on the source
- * Observable. This operator keeps track of the most recent value from the
- * source Observable, and emits that only when `dueTime` enough time has passed
- * without any other value appearing on the source Observable. If a new value
- * appears before `dueTime` silence occurs, the previous value will be dropped
- * and will not be emitted on the output Observable.
- *
- * This is a rate-limiting operator, because it is impossible for more than one
- * value to be emitted in any time window of duration `dueTime`, but it is also
- * a delay-like operator since output emissions do not occur at the same time as
- * they did on the source Observable. Optionally takes a {@link IScheduler} for
- * managing timers.
- *
- * @example <caption>Emit the most recent click after a burst of clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.debounceTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounce}
- * @see {@link delay}
- * @see {@link sampleTime}
- * @see {@link throttleTime}
- *
- * @param {number} dueTime The timeout duration in milliseconds (or the time
- * unit determined internally by the optional `scheduler`) for the window of
- * time required to wait for emission silence before emitting the most recent
- * source value.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the timeout for each value.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by the specified `dueTime`, and may drop some values if they occur
- * too frequently.
- * @method debounceTime
- * @owner Observable
- */
- function debounceTime$$1(dueTime, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return debounceTime$1(dueTime, scheduler)(this);
- }
-
- Observable.prototype.debounceTime = debounceTime$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Emits a given value if the source Observable completes without emitting any
- * `next` value, otherwise mirrors the source Observable.
- *
- * <span class="informal">If the source Observable turns out to be empty, then
- * this operator will emit a default value.</span>
- *
- * <img src="./img/defaultIfEmpty.png" width="100%">
- *
- * `defaultIfEmpty` emits the values emitted by the source Observable or a
- * specified default value if the source Observable is empty (completes without
- * having emitted any `next` value).
- *
- * @example <caption>If no clicks happen in 5 seconds, then emit "no clicks"</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var clicksBeforeFive = clicks.takeUntil(Rx.Observable.interval(5000));
- * var result = clicksBeforeFive.defaultIfEmpty('no clicks');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link empty}
- * @see {@link last}
- *
- * @param {any} [defaultValue=null] The default value used if the source
- * Observable is empty.
- * @return {Observable} An Observable that emits either the specified
- * `defaultValue` if the source Observable emits no items, or the values emitted
- * by the source Observable.
- * @method defaultIfEmpty
- * @owner Observable
- */
- function defaultIfEmpty$1(defaultValue) {
- if (defaultValue === void 0) { defaultValue = null; }
- return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
- }
- var DefaultIfEmptyOperator = (function () {
- function DefaultIfEmptyOperator(defaultValue) {
- this.defaultValue = defaultValue;
- }
- DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
- };
- return DefaultIfEmptyOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DefaultIfEmptySubscriber = (function (_super) {
- __extends(DefaultIfEmptySubscriber, _super);
- function DefaultIfEmptySubscriber(destination, defaultValue) {
- _super.call(this, destination);
- this.defaultValue = defaultValue;
- this.isEmpty = true;
- }
- DefaultIfEmptySubscriber.prototype._next = function (value) {
- this.isEmpty = false;
- this.destination.next(value);
- };
- DefaultIfEmptySubscriber.prototype._complete = function () {
- if (this.isEmpty) {
- this.destination.next(this.defaultValue);
- }
- this.destination.complete();
- };
- return DefaultIfEmptySubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Emits a given value if the source Observable completes without emitting any
- * `next` value, otherwise mirrors the source Observable.
- *
- * <span class="informal">If the source Observable turns out to be empty, then
- * this operator will emit a default value.</span>
- *
- * <img src="./img/defaultIfEmpty.png" width="100%">
- *
- * `defaultIfEmpty` emits the values emitted by the source Observable or a
- * specified default value if the source Observable is empty (completes without
- * having emitted any `next` value).
- *
- * @example <caption>If no clicks happen in 5 seconds, then emit "no clicks"</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var clicksBeforeFive = clicks.takeUntil(Rx.Observable.interval(5000));
- * var result = clicksBeforeFive.defaultIfEmpty('no clicks');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link empty}
- * @see {@link last}
- *
- * @param {any} [defaultValue=null] The default value used if the source
- * Observable is empty.
- * @return {Observable} An Observable that emits either the specified
- * `defaultValue` if the source Observable emits no items, or the values emitted
- * by the source Observable.
- * @method defaultIfEmpty
- * @owner Observable
- */
- function defaultIfEmpty$$1(defaultValue) {
- if (defaultValue === void 0) { defaultValue = null; }
- return defaultIfEmpty$1(defaultValue)(this);
- }
-
- Observable.prototype.defaultIfEmpty = defaultIfEmpty$$1;
-
- /**
- * Delays the emission of items from the source Observable by a given timeout or
- * until a given Date.
- *
- * <span class="informal">Time shifts each item by some specified amount of
- * milliseconds.</span>
- *
- * <img src="./img/delay.png" width="100%">
- *
- * If the delay argument is a Number, this operator time shifts the source
- * Observable by that amount of time expressed in milliseconds. The relative
- * time intervals between the values are preserved.
- *
- * If the delay argument is a Date, this operator time shifts the start of the
- * Observable execution until the given date occurs.
- *
- * @example <caption>Delay each click by one second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var delayedClicks = clicks.delay(1000); // each click emitted after 1 second
- * delayedClicks.subscribe(x => console.log(x));
- *
- * @example <caption>Delay all clicks until a future date happens</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var date = new Date('March 15, 2050 12:00:00'); // in the future
- * var delayedClicks = clicks.delay(date); // click emitted only after that date
- * delayedClicks.subscribe(x => console.log(x));
- *
- * @see {@link debounceTime}
- * @see {@link delayWhen}
- *
- * @param {number|Date} delay The delay duration in milliseconds (a `number`) or
- * a `Date` until which the emission of the source items is delayed.
- * @param {Scheduler} [scheduler=async] The IScheduler to use for
- * managing the timers that handle the time-shift for each item.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by the specified timeout or Date.
- * @method delay
- * @owner Observable
- */
- function delay$1(delay, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- var absoluteDelay = isDate(delay);
- var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
- return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
- }
- var DelayOperator = (function () {
- function DelayOperator(delay, scheduler) {
- this.delay = delay;
- this.scheduler = scheduler;
- }
- DelayOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
- };
- return DelayOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DelaySubscriber = (function (_super) {
- __extends(DelaySubscriber, _super);
- function DelaySubscriber(destination, delay, scheduler) {
- _super.call(this, destination);
- this.delay = delay;
- this.scheduler = scheduler;
- this.queue = [];
- this.active = false;
- this.errored = false;
- }
- DelaySubscriber.dispatch = function (state) {
- var source = state.source;
- var queue = source.queue;
- var scheduler = state.scheduler;
- var destination = state.destination;
- while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
- queue.shift().notification.observe(destination);
- }
- if (queue.length > 0) {
- var delay_1 = Math.max(0, queue[0].time - scheduler.now());
- this.schedule(state, delay_1);
- }
- else {
- this.unsubscribe();
- source.active = false;
- }
- };
- DelaySubscriber.prototype._schedule = function (scheduler) {
- this.active = true;
- this.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
- source: this, destination: this.destination, scheduler: scheduler
- }));
- };
- DelaySubscriber.prototype.scheduleNotification = function (notification) {
- if (this.errored === true) {
- return;
- }
- var scheduler = this.scheduler;
- var message = new DelayMessage(scheduler.now() + this.delay, notification);
- this.queue.push(message);
- if (this.active === false) {
- this._schedule(scheduler);
- }
- };
- DelaySubscriber.prototype._next = function (value) {
- this.scheduleNotification(Notification.createNext(value));
- };
- DelaySubscriber.prototype._error = function (err) {
- this.errored = true;
- this.queue = [];
- this.destination.error(err);
- };
- DelaySubscriber.prototype._complete = function () {
- this.scheduleNotification(Notification.createComplete());
- };
- return DelaySubscriber;
- }(Subscriber));
- var DelayMessage = (function () {
- function DelayMessage(time, notification) {
- this.time = time;
- this.notification = notification;
- }
- return DelayMessage;
- }());
-
- /**
- * Delays the emission of items from the source Observable by a given timeout or
- * until a given Date.
- *
- * <span class="informal">Time shifts each item by some specified amount of
- * milliseconds.</span>
- *
- * <img src="./img/delay.png" width="100%">
- *
- * If the delay argument is a Number, this operator time shifts the source
- * Observable by that amount of time expressed in milliseconds. The relative
- * time intervals between the values are preserved.
- *
- * If the delay argument is a Date, this operator time shifts the start of the
- * Observable execution until the given date occurs.
- *
- * @example <caption>Delay each click by one second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var delayedClicks = clicks.delay(1000); // each click emitted after 1 second
- * delayedClicks.subscribe(x => console.log(x));
- *
- * @example <caption>Delay all clicks until a future date happens</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var date = new Date('March 15, 2050 12:00:00'); // in the future
- * var delayedClicks = clicks.delay(date); // click emitted only after that date
- * delayedClicks.subscribe(x => console.log(x));
- *
- * @see {@link debounceTime}
- * @see {@link delayWhen}
- *
- * @param {number|Date} delay The delay duration in milliseconds (a `number`) or
- * a `Date` until which the emission of the source items is delayed.
- * @param {Scheduler} [scheduler=async] The IScheduler to use for
- * managing the timers that handle the time-shift for each item.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by the specified timeout or Date.
- * @method delay
- * @owner Observable
- */
- function delay$$1(delay$$1, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return delay$1(delay$$1, scheduler)(this);
- }
-
- Observable.prototype.delay = delay$$1;
-
- /**
- * Delays the emission of items from the source Observable by a given time span
- * determined by the emissions of another Observable.
- *
- * <span class="informal">It's like {@link delay}, but the time span of the
- * delay duration is determined by a second Observable.</span>
- *
- * <img src="./img/delayWhen.png" width="100%">
- *
- * `delayWhen` time shifts each emitted value from the source Observable by a
- * time span determined by another Observable. When the source emits a value,
- * the `delayDurationSelector` function is called with the source value as
- * argument, and should return an Observable, called the "duration" Observable.
- * The source value is emitted on the output Observable only when the duration
- * Observable emits a value or completes.
- *
- * Optionally, `delayWhen` takes a second argument, `subscriptionDelay`, which
- * is an Observable. When `subscriptionDelay` emits its first value or
- * completes, the source Observable is subscribed to and starts behaving like
- * described in the previous paragraph. If `subscriptionDelay` is not provided,
- * `delayWhen` will subscribe to the source Observable as soon as the output
- * Observable is subscribed.
- *
- * @example <caption>Delay each click by a random amount of time, between 0 and 5 seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var delayedClicks = clicks.delayWhen(event =>
- * Rx.Observable.interval(Math.random() * 5000)
- * );
- * delayedClicks.subscribe(x => console.log(x));
- *
- * @see {@link debounce}
- * @see {@link delay}
- *
- * @param {function(value: T): Observable} delayDurationSelector A function that
- * returns an Observable for each value emitted by the source Observable, which
- * is then used to delay the emission of that item on the output Observable
- * until the Observable returned from this function emits a value.
- * @param {Observable} subscriptionDelay An Observable that triggers the
- * subscription to the source Observable once it emits any value.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by an amount of time specified by the Observable returned by
- * `delayDurationSelector`.
- * @method delayWhen
- * @owner Observable
- */
- function delayWhen$1(delayDurationSelector, subscriptionDelay) {
- if (subscriptionDelay) {
- return function (source) {
- return new SubscriptionDelayObservable(source, subscriptionDelay)
- .lift(new DelayWhenOperator(delayDurationSelector));
- };
- }
- return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
- }
- var DelayWhenOperator = (function () {
- function DelayWhenOperator(delayDurationSelector) {
- this.delayDurationSelector = delayDurationSelector;
- }
- DelayWhenOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
- };
- return DelayWhenOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DelayWhenSubscriber = (function (_super) {
- __extends(DelayWhenSubscriber, _super);
- function DelayWhenSubscriber(destination, delayDurationSelector) {
- _super.call(this, destination);
- this.delayDurationSelector = delayDurationSelector;
- this.completed = false;
- this.delayNotifierSubscriptions = [];
- this.values = [];
- }
- DelayWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.destination.next(outerValue);
- this.removeSubscription(innerSub);
- this.tryComplete();
- };
- DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) {
- this._error(error);
- };
- DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) {
- var value = this.removeSubscription(innerSub);
- if (value) {
- this.destination.next(value);
- }
- this.tryComplete();
- };
- DelayWhenSubscriber.prototype._next = function (value) {
- try {
- var delayNotifier = this.delayDurationSelector(value);
- if (delayNotifier) {
- this.tryDelay(delayNotifier, value);
- }
- }
- catch (err) {
- this.destination.error(err);
- }
- };
- DelayWhenSubscriber.prototype._complete = function () {
- this.completed = true;
- this.tryComplete();
- };
- DelayWhenSubscriber.prototype.removeSubscription = function (subscription) {
- subscription.unsubscribe();
- var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription);
- var value = null;
- if (subscriptionIdx !== -1) {
- value = this.values[subscriptionIdx];
- this.delayNotifierSubscriptions.splice(subscriptionIdx, 1);
- this.values.splice(subscriptionIdx, 1);
- }
- return value;
- };
- DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) {
- var notifierSubscription = subscribeToResult(this, delayNotifier, value);
- if (notifierSubscription && !notifierSubscription.closed) {
- this.add(notifierSubscription);
- this.delayNotifierSubscriptions.push(notifierSubscription);
- }
- this.values.push(value);
- };
- DelayWhenSubscriber.prototype.tryComplete = function () {
- if (this.completed && this.delayNotifierSubscriptions.length === 0) {
- this.destination.complete();
- }
- };
- return DelayWhenSubscriber;
- }(OuterSubscriber));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SubscriptionDelayObservable = (function (_super) {
- __extends(SubscriptionDelayObservable, _super);
- function SubscriptionDelayObservable(/** @deprecated internal use only */ source, subscriptionDelay) {
- _super.call(this);
- this.source = source;
- this.subscriptionDelay = subscriptionDelay;
- }
- /** @deprecated internal use only */ SubscriptionDelayObservable.prototype._subscribe = function (subscriber) {
- this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source));
- };
- return SubscriptionDelayObservable;
- }(Observable));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SubscriptionDelaySubscriber = (function (_super) {
- __extends(SubscriptionDelaySubscriber, _super);
- function SubscriptionDelaySubscriber(parent, source) {
- _super.call(this);
- this.parent = parent;
- this.source = source;
- this.sourceSubscribed = false;
- }
- SubscriptionDelaySubscriber.prototype._next = function (unused) {
- this.subscribeToSource();
- };
- SubscriptionDelaySubscriber.prototype._error = function (err) {
- this.unsubscribe();
- this.parent.error(err);
- };
- SubscriptionDelaySubscriber.prototype._complete = function () {
- this.subscribeToSource();
- };
- SubscriptionDelaySubscriber.prototype.subscribeToSource = function () {
- if (!this.sourceSubscribed) {
- this.sourceSubscribed = true;
- this.unsubscribe();
- this.source.subscribe(this.parent);
- }
- };
- return SubscriptionDelaySubscriber;
- }(Subscriber));
-
- /**
- * Delays the emission of items from the source Observable by a given time span
- * determined by the emissions of another Observable.
- *
- * <span class="informal">It's like {@link delay}, but the time span of the
- * delay duration is determined by a second Observable.</span>
- *
- * <img src="./img/delayWhen.png" width="100%">
- *
- * `delayWhen` time shifts each emitted value from the source Observable by a
- * time span determined by another Observable. When the source emits a value,
- * the `delayDurationSelector` function is called with the source value as
- * argument, and should return an Observable, called the "duration" Observable.
- * The source value is emitted on the output Observable only when the duration
- * Observable emits a value or completes.
- *
- * Optionally, `delayWhen` takes a second argument, `subscriptionDelay`, which
- * is an Observable. When `subscriptionDelay` emits its first value or
- * completes, the source Observable is subscribed to and starts behaving like
- * described in the previous paragraph. If `subscriptionDelay` is not provided,
- * `delayWhen` will subscribe to the source Observable as soon as the output
- * Observable is subscribed.
- *
- * @example <caption>Delay each click by a random amount of time, between 0 and 5 seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var delayedClicks = clicks.delayWhen(event =>
- * Rx.Observable.interval(Math.random() * 5000)
- * );
- * delayedClicks.subscribe(x => console.log(x));
- *
- * @see {@link debounce}
- * @see {@link delay}
- *
- * @param {function(value: T): Observable} delayDurationSelector A function that
- * returns an Observable for each value emitted by the source Observable, which
- * is then used to delay the emission of that item on the output Observable
- * until the Observable returned from this function emits a value.
- * @param {Observable} subscriptionDelay An Observable that triggers the
- * subscription to the source Observable once it emits any value.
- * @return {Observable} An Observable that delays the emissions of the source
- * Observable by an amount of time specified by the Observable returned by
- * `delayDurationSelector`.
- * @method delayWhen
- * @owner Observable
- */
- function delayWhen$$1(delayDurationSelector, subscriptionDelay) {
- return delayWhen$1(delayDurationSelector, subscriptionDelay)(this);
- }
-
- Observable.prototype.delayWhen = delayWhen$$1;
-
- function minimalSetImpl() {
- // THIS IS NOT a full impl of Set, this is just the minimum
- // bits of functionality we need for this library.
- return (function () {
- function MinimalSet() {
- this._values = [];
- }
- MinimalSet.prototype.add = function (value) {
- if (!this.has(value)) {
- this._values.push(value);
- }
- };
- MinimalSet.prototype.has = function (value) {
- return this._values.indexOf(value) !== -1;
- };
- Object.defineProperty(MinimalSet.prototype, "size", {
- get: function () {
- return this._values.length;
- },
- enumerable: true,
- configurable: true
- });
- MinimalSet.prototype.clear = function () {
- this._values.length = 0;
- };
- return MinimalSet;
- }());
- }
- var Set = _root.Set || minimalSetImpl();
-
- /**
- * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
- *
- * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will
- * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the
- * source observable directly with an equality check against previous values.
- *
- * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
- *
- * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
- * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
- * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
- * that the internal `Set` can be "flushed", basically clearing it of values.
- *
- * @example <caption>A simple example with numbers</caption>
- * Observable.of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1)
- * .distinct()
- * .subscribe(x => console.log(x)); // 1, 2, 3, 4
- *
- * @example <caption>An example using a keySelector function</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo'})
- * .distinct((p: Person) => p.name)
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo' }
- * // { age: 7, name: 'Bar' }
- *
- * @see {@link distinctUntilChanged}
- * @see {@link distinctUntilKeyChanged}
- *
- * @param {function} [keySelector] Optional function to select which value you want to check as distinct.
- * @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
- * @return {Observable} An Observable that emits items from the source Observable with distinct values.
- * @method distinct
- * @owner Observable
- */
- function distinct$1(keySelector, flushes) {
- return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
- }
- var DistinctOperator = (function () {
- function DistinctOperator(keySelector, flushes) {
- this.keySelector = keySelector;
- this.flushes = flushes;
- }
- DistinctOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
- };
- return DistinctOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DistinctSubscriber = (function (_super) {
- __extends(DistinctSubscriber, _super);
- function DistinctSubscriber(destination, keySelector, flushes) {
- _super.call(this, destination);
- this.keySelector = keySelector;
- this.values = new Set();
- if (flushes) {
- this.add(subscribeToResult(this, flushes));
- }
- }
- DistinctSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.values.clear();
- };
- DistinctSubscriber.prototype.notifyError = function (error, innerSub) {
- this._error(error);
- };
- DistinctSubscriber.prototype._next = function (value) {
- if (this.keySelector) {
- this._useKeySelector(value);
- }
- else {
- this._finalizeNext(value, value);
- }
- };
- DistinctSubscriber.prototype._useKeySelector = function (value) {
- var key;
- var destination = this.destination;
- try {
- key = this.keySelector(value);
- }
- catch (err) {
- destination.error(err);
- return;
- }
- this._finalizeNext(key, value);
- };
- DistinctSubscriber.prototype._finalizeNext = function (key, value) {
- var values = this.values;
- if (!values.has(key)) {
- values.add(key);
- this.destination.next(value);
- }
- };
- return DistinctSubscriber;
- }(OuterSubscriber));
-
- /**
- * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
- *
- * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will
- * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the
- * source observable directly with an equality check against previous values.
- *
- * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
- *
- * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
- * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
- * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
- * that the internal `Set` can be "flushed", basically clearing it of values.
- *
- * @example <caption>A simple example with numbers</caption>
- * Observable.of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1)
- * .distinct()
- * .subscribe(x => console.log(x)); // 1, 2, 3, 4
- *
- * @example <caption>An example using a keySelector function</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo'})
- * .distinct((p: Person) => p.name)
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo' }
- * // { age: 7, name: 'Bar' }
- *
- * @see {@link distinctUntilChanged}
- * @see {@link distinctUntilKeyChanged}
- *
- * @param {function} [keySelector] Optional function to select which value you want to check as distinct.
- * @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
- * @return {Observable} An Observable that emits items from the source Observable with distinct values.
- * @method distinct
- * @owner Observable
- */
- function distinct$$1(keySelector, flushes) {
- return distinct$1(keySelector, flushes)(this);
- }
-
- Observable.prototype.distinct = distinct$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.
- *
- * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
- *
- * If a comparator function is not provided, an equality check is used by default.
- *
- * @example <caption>A simple example with numbers</caption>
- * Observable.of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4)
- * .distinctUntilChanged()
- * .subscribe(x => console.log(x)); // 1, 2, 1, 2, 3, 4
- *
- * @example <caption>An example using a compare function</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo'})
- * { age: 6, name: 'Foo'})
- * .distinctUntilChanged((p: Person, q: Person) => p.name === q.name)
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo' }
- * // { age: 7, name: 'Bar' }
- * // { age: 5, name: 'Foo' }
- *
- * @see {@link distinct}
- * @see {@link distinctUntilKeyChanged}
- *
- * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
- * @return {Observable} An Observable that emits items from the source Observable with distinct values.
- * @method distinctUntilChanged
- * @owner Observable
- */
- function distinctUntilChanged$1(compare, keySelector) {
- return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
- }
- var DistinctUntilChangedOperator = (function () {
- function DistinctUntilChangedOperator(compare, keySelector) {
- this.compare = compare;
- this.keySelector = keySelector;
- }
- DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
- };
- return DistinctUntilChangedOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DistinctUntilChangedSubscriber = (function (_super) {
- __extends(DistinctUntilChangedSubscriber, _super);
- function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
- _super.call(this, destination);
- this.keySelector = keySelector;
- this.hasKey = false;
- if (typeof compare === 'function') {
- this.compare = compare;
- }
- }
- DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
- return x === y;
- };
- DistinctUntilChangedSubscriber.prototype._next = function (value) {
- var keySelector = this.keySelector;
- var key = value;
- if (keySelector) {
- key = tryCatch(this.keySelector)(value);
- if (key === errorObject) {
- return this.destination.error(errorObject.e);
- }
- }
- var result = false;
- if (this.hasKey) {
- result = tryCatch(this.compare)(this.key, key);
- if (result === errorObject) {
- return this.destination.error(errorObject.e);
- }
- }
- else {
- this.hasKey = true;
- }
- if (Boolean(result) === false) {
- this.key = key;
- this.destination.next(value);
- }
- };
- return DistinctUntilChangedSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.
- *
- * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
- *
- * If a comparator function is not provided, an equality check is used by default.
- *
- * @example <caption>A simple example with numbers</caption>
- * Observable.of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4)
- * .distinctUntilChanged()
- * .subscribe(x => console.log(x)); // 1, 2, 1, 2, 3, 4
- *
- * @example <caption>An example using a compare function</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo'})
- * { age: 6, name: 'Foo'})
- * .distinctUntilChanged((p: Person, q: Person) => p.name === q.name)
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo' }
- * // { age: 7, name: 'Bar' }
- * // { age: 5, name: 'Foo' }
- *
- * @see {@link distinct}
- * @see {@link distinctUntilKeyChanged}
- *
- * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
- * @return {Observable} An Observable that emits items from the source Observable with distinct values.
- * @method distinctUntilChanged
- * @owner Observable
- */
- function distinctUntilChanged$$1(compare, keySelector) {
- return distinctUntilChanged$1(compare, keySelector)(this);
- }
-
- Observable.prototype.distinctUntilChanged = distinctUntilChanged$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item,
- * using a property accessed by using the key provided to check if the two items are distinct.
- *
- * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
- *
- * If a comparator function is not provided, an equality check is used by default.
- *
- * @example <caption>An example comparing the name of persons</caption>
- *
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo'},
- * { age: 6, name: 'Foo'})
- * .distinctUntilKeyChanged('name')
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo' }
- * // { age: 7, name: 'Bar' }
- * // { age: 5, name: 'Foo' }
- *
- * @example <caption>An example comparing the first letters of the name</caption>
- *
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo1'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo2'},
- * { age: 6, name: 'Foo3'})
- * .distinctUntilKeyChanged('name', (x: string, y: string) => x.substring(0, 3) === y.substring(0, 3))
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo1' }
- * // { age: 7, name: 'Bar' }
- * // { age: 5, name: 'Foo2' }
- *
- * @see {@link distinct}
- * @see {@link distinctUntilChanged}
- *
- * @param {string} key String key for object property lookup on each item.
- * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
- * @return {Observable} An Observable that emits items from the source Observable with distinct values based on the key specified.
- * @method distinctUntilKeyChanged
- * @owner Observable
- */
- function distinctUntilKeyChanged$1(key, compare) {
- return distinctUntilChanged$1(function (x, y) { return compare ? compare(x[key], y[key]) : x[key] === y[key]; });
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item,
- * using a property accessed by using the key provided to check if the two items are distinct.
- *
- * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
- *
- * If a comparator function is not provided, an equality check is used by default.
- *
- * @example <caption>An example comparing the name of persons</caption>
- *
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo'},
- * { age: 6, name: 'Foo'})
- * .distinctUntilKeyChanged('name')
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo' }
- * // { age: 7, name: 'Bar' }
- * // { age: 5, name: 'Foo' }
- *
- * @example <caption>An example comparing the first letters of the name</caption>
- *
- * interface Person {
- * age: number,
- * name: string
- * }
- *
- * Observable.of<Person>(
- * { age: 4, name: 'Foo1'},
- * { age: 7, name: 'Bar'},
- * { age: 5, name: 'Foo2'},
- * { age: 6, name: 'Foo3'})
- * .distinctUntilKeyChanged('name', (x: string, y: string) => x.substring(0, 3) === y.substring(0, 3))
- * .subscribe(x => console.log(x));
- *
- * // displays:
- * // { age: 4, name: 'Foo1' }
- * // { age: 7, name: 'Bar' }
- * // { age: 5, name: 'Foo2' }
- *
- * @see {@link distinct}
- * @see {@link distinctUntilChanged}
- *
- * @param {string} key String key for object property lookup on each item.
- * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
- * @return {Observable} An Observable that emits items from the source Observable with distinct values based on the key specified.
- * @method distinctUntilKeyChanged
- * @owner Observable
- */
- function distinctUntilKeyChanged$$1(key, compare) {
- return distinctUntilKeyChanged$1(key, compare)(this);
- }
-
- Observable.prototype.distinctUntilKeyChanged = distinctUntilKeyChanged$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Perform a side effect for every emission on the source Observable, but return
- * an Observable that is identical to the source.
- *
- * <span class="informal">Intercepts each emission on the source and runs a
- * function, but returns an output which is identical to the source as long as errors don't occur.</span>
- *
- * <img src="./img/do.png" width="100%">
- *
- * Returns a mirrored Observable of the source Observable, but modified so that
- * the provided Observer is called to perform a side effect for every value,
- * error, and completion emitted by the source. Any errors that are thrown in
- * the aforementioned Observer or handlers are safely sent down the error path
- * of the output Observable.
- *
- * This operator is useful for debugging your Observables for the correct values
- * or performing other side effects.
- *
- * Note: this is different to a `subscribe` on the Observable. If the Observable
- * returned by `do` is not subscribed, the side effects specified by the
- * Observer will never happen. `do` therefore simply spies on existing
- * execution, it does not trigger an execution to happen like `subscribe` does.
- *
- * @example <caption>Map every click to the clientX position of that click, while also logging the click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var positions = clicks
- * .do(ev => console.log(ev))
- * .map(ev => ev.clientX);
- * positions.subscribe(x => console.log(x));
- *
- * @see {@link map}
- * @see {@link subscribe}
- *
- * @param {Observer|function} [nextOrObserver] A normal Observer object or a
- * callback for `next`.
- * @param {function} [error] Callback for errors in the source.
- * @param {function} [complete] Callback for the completion of the source.
- * @return {Observable} An Observable identical to the source, but runs the
- * specified Observer or callback(s) for each item.
- * @name tap
- */
- function tap(nextOrObserver, error, complete) {
- return function tapOperatorFunction(source) {
- return source.lift(new DoOperator(nextOrObserver, error, complete));
- };
- }
- var DoOperator = (function () {
- function DoOperator(nextOrObserver, error, complete) {
- this.nextOrObserver = nextOrObserver;
- this.error = error;
- this.complete = complete;
- }
- DoOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DoSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
- };
- return DoOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var DoSubscriber = (function (_super) {
- __extends(DoSubscriber, _super);
- function DoSubscriber(destination, nextOrObserver, error, complete) {
- _super.call(this, destination);
- var safeSubscriber = new Subscriber(nextOrObserver, error, complete);
- safeSubscriber.syncErrorThrowable = true;
- this.add(safeSubscriber);
- this.safeSubscriber = safeSubscriber;
- }
- DoSubscriber.prototype._next = function (value) {
- var safeSubscriber = this.safeSubscriber;
- safeSubscriber.next(value);
- if (safeSubscriber.syncErrorThrown) {
- this.destination.error(safeSubscriber.syncErrorValue);
- }
- else {
- this.destination.next(value);
- }
- };
- DoSubscriber.prototype._error = function (err) {
- var safeSubscriber = this.safeSubscriber;
- safeSubscriber.error(err);
- if (safeSubscriber.syncErrorThrown) {
- this.destination.error(safeSubscriber.syncErrorValue);
- }
- else {
- this.destination.error(err);
- }
- };
- DoSubscriber.prototype._complete = function () {
- var safeSubscriber = this.safeSubscriber;
- safeSubscriber.complete();
- if (safeSubscriber.syncErrorThrown) {
- this.destination.error(safeSubscriber.syncErrorValue);
- }
- else {
- this.destination.complete();
- }
- };
- return DoSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Perform a side effect for every emission on the source Observable, but return
- * an Observable that is identical to the source.
- *
- * <span class="informal">Intercepts each emission on the source and runs a
- * function, but returns an output which is identical to the source as long as errors don't occur.</span>
- *
- * <img src="./img/do.png" width="100%">
- *
- * Returns a mirrored Observable of the source Observable, but modified so that
- * the provided Observer is called to perform a side effect for every value,
- * error, and completion emitted by the source. Any errors that are thrown in
- * the aforementioned Observer or handlers are safely sent down the error path
- * of the output Observable.
- *
- * This operator is useful for debugging your Observables for the correct values
- * or performing other side effects.
- *
- * Note: this is different to a `subscribe` on the Observable. If the Observable
- * returned by `do` is not subscribed, the side effects specified by the
- * Observer will never happen. `do` therefore simply spies on existing
- * execution, it does not trigger an execution to happen like `subscribe` does.
- *
- * @example <caption>Map every click to the clientX position of that click, while also logging the click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var positions = clicks
- * .do(ev => console.log(ev))
- * .map(ev => ev.clientX);
- * positions.subscribe(x => console.log(x));
- *
- * @see {@link map}
- * @see {@link subscribe}
- *
- * @param {Observer|function} [nextOrObserver] A normal Observer object or a
- * callback for `next`.
- * @param {function} [error] Callback for errors in the source.
- * @param {function} [complete] Callback for the completion of the source.
- * @return {Observable} An Observable identical to the source, but runs the
- * specified Observer or callback(s) for each item.
- * @method do
- * @name do
- * @owner Observable
- */
- function _do(nextOrObserver, error, complete) {
- return tap(nextOrObserver, error, complete)(this);
- }
-
- Observable.prototype.do = _do;
- Observable.prototype._do = _do;
-
- /**
- * Converts a higher-order Observable into a first-order Observable by dropping
- * inner Observables while the previous inner Observable has not yet completed.
- *
- * <span class="informal">Flattens an Observable-of-Observables by dropping the
- * next inner Observables while the current inner is still executing.</span>
- *
- * <img src="./img/exhaust.png" width="100%">
- *
- * `exhaust` subscribes to an Observable that emits Observables, also known as a
- * higher-order Observable. Each time it observes one of these emitted inner
- * Observables, the output Observable begins emitting the items emitted by that
- * inner Observable. So far, it behaves like {@link mergeAll}. However,
- * `exhaust` ignores every new inner Observable if the previous Observable has
- * not yet completed. Once that one completes, it will accept and flatten the
- * next inner Observable and repeat this process.
- *
- * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(5));
- * var result = higherOrder.exhaust();
- * result.subscribe(x => console.log(x));
- *
- * @see {@link combineAll}
- * @see {@link concatAll}
- * @see {@link switch}
- * @see {@link mergeAll}
- * @see {@link exhaustMap}
- * @see {@link zipAll}
- *
- * @return {Observable} An Observable that takes a source of Observables and propagates the first observable
- * exclusively until it completes before subscribing to the next.
- * @method exhaust
- * @owner Observable
- */
- function exhaust$1() {
- return function (source) { return source.lift(new SwitchFirstOperator()); };
- }
- var SwitchFirstOperator = (function () {
- function SwitchFirstOperator() {
- }
- SwitchFirstOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SwitchFirstSubscriber(subscriber));
- };
- return SwitchFirstOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SwitchFirstSubscriber = (function (_super) {
- __extends(SwitchFirstSubscriber, _super);
- function SwitchFirstSubscriber(destination) {
- _super.call(this, destination);
- this.hasCompleted = false;
- this.hasSubscription = false;
- }
- SwitchFirstSubscriber.prototype._next = function (value) {
- if (!this.hasSubscription) {
- this.hasSubscription = true;
- this.add(subscribeToResult(this, value));
- }
- };
- SwitchFirstSubscriber.prototype._complete = function () {
- this.hasCompleted = true;
- if (!this.hasSubscription) {
- this.destination.complete();
- }
- };
- SwitchFirstSubscriber.prototype.notifyComplete = function (innerSub) {
- this.remove(innerSub);
- this.hasSubscription = false;
- if (this.hasCompleted) {
- this.destination.complete();
- }
- };
- return SwitchFirstSubscriber;
- }(OuterSubscriber));
-
- /**
- * Converts a higher-order Observable into a first-order Observable by dropping
- * inner Observables while the previous inner Observable has not yet completed.
- *
- * <span class="informal">Flattens an Observable-of-Observables by dropping the
- * next inner Observables while the current inner is still executing.</span>
- *
- * <img src="./img/exhaust.png" width="100%">
- *
- * `exhaust` subscribes to an Observable that emits Observables, also known as a
- * higher-order Observable. Each time it observes one of these emitted inner
- * Observables, the output Observable begins emitting the items emitted by that
- * inner Observable. So far, it behaves like {@link mergeAll}. However,
- * `exhaust` ignores every new inner Observable if the previous Observable has
- * not yet completed. Once that one completes, it will accept and flatten the
- * next inner Observable and repeat this process.
- *
- * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(5));
- * var result = higherOrder.exhaust();
- * result.subscribe(x => console.log(x));
- *
- * @see {@link combineAll}
- * @see {@link concatAll}
- * @see {@link switch}
- * @see {@link mergeAll}
- * @see {@link exhaustMap}
- * @see {@link zipAll}
- *
- * @return {Observable} An Observable that takes a source of Observables and propagates the first observable
- * exclusively until it completes before subscribing to the next.
- * @method exhaust
- * @owner Observable
- */
- function exhaust$$1() {
- return exhaust$1()(this);
- }
-
- Observable.prototype.exhaust = exhaust$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable only if the previous projected Observable has completed.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link exhaust}.</span>
- *
- * <img src="./img/exhaustMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an (so-called "inner") Observable. When it projects a source value to
- * an Observable, the output Observable begins emitting the items emitted by
- * that projected Observable. However, `exhaustMap` ignores every new projected
- * Observable if the previous projected Observable has not yet completed. Once
- * that one completes, it will accept and flatten the next projected Observable
- * and repeat this process.
- *
- * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.exhaustMap((ev) => Rx.Observable.interval(1000).take(5));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMap}
- * @see {@link exhaust}
- * @see {@link mergeMap}
- * @see {@link switchMap}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable containing projected Observables
- * of each item of the source, ignoring projected Observables that start before
- * their preceding Observable has completed.
- * @method exhaustMap
- * @owner Observable
- */
- function exhaustMap$1(project, resultSelector) {
- return function (source) { return source.lift(new SwitchFirstMapOperator(project, resultSelector)); };
- }
- var SwitchFirstMapOperator = (function () {
- function SwitchFirstMapOperator(project, resultSelector) {
- this.project = project;
- this.resultSelector = resultSelector;
- }
- SwitchFirstMapOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SwitchFirstMapSubscriber(subscriber, this.project, this.resultSelector));
- };
- return SwitchFirstMapOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SwitchFirstMapSubscriber = (function (_super) {
- __extends(SwitchFirstMapSubscriber, _super);
- function SwitchFirstMapSubscriber(destination, project, resultSelector) {
- _super.call(this, destination);
- this.project = project;
- this.resultSelector = resultSelector;
- this.hasSubscription = false;
- this.hasCompleted = false;
- this.index = 0;
- }
- SwitchFirstMapSubscriber.prototype._next = function (value) {
- if (!this.hasSubscription) {
- this.tryNext(value);
- }
- };
- SwitchFirstMapSubscriber.prototype.tryNext = function (value) {
- var index = this.index++;
- var destination = this.destination;
- try {
- var result = this.project(value, index);
- this.hasSubscription = true;
- this.add(subscribeToResult(this, result, value, index));
- }
- catch (err) {
- destination.error(err);
- }
- };
- SwitchFirstMapSubscriber.prototype._complete = function () {
- this.hasCompleted = true;
- if (!this.hasSubscription) {
- this.destination.complete();
- }
- };
- SwitchFirstMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
- if (resultSelector) {
- this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex);
- }
- else {
- destination.next(innerValue);
- }
- };
- SwitchFirstMapSubscriber.prototype.trySelectResult = function (outerValue, innerValue, outerIndex, innerIndex) {
- var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
- try {
- var result = resultSelector(outerValue, innerValue, outerIndex, innerIndex);
- destination.next(result);
- }
- catch (err) {
- destination.error(err);
- }
- };
- SwitchFirstMapSubscriber.prototype.notifyError = function (err) {
- this.destination.error(err);
- };
- SwitchFirstMapSubscriber.prototype.notifyComplete = function (innerSub) {
- this.remove(innerSub);
- this.hasSubscription = false;
- if (this.hasCompleted) {
- this.destination.complete();
- }
- };
- return SwitchFirstMapSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable only if the previous projected Observable has completed.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link exhaust}.</span>
- *
- * <img src="./img/exhaustMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an (so-called "inner") Observable. When it projects a source value to
- * an Observable, the output Observable begins emitting the items emitted by
- * that projected Observable. However, `exhaustMap` ignores every new projected
- * Observable if the previous projected Observable has not yet completed. Once
- * that one completes, it will accept and flatten the next projected Observable
- * and repeat this process.
- *
- * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.exhaustMap((ev) => Rx.Observable.interval(1000).take(5));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMap}
- * @see {@link exhaust}
- * @see {@link mergeMap}
- * @see {@link switchMap}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable containing projected Observables
- * of each item of the source, ignoring projected Observables that start before
- * their preceding Observable has completed.
- * @method exhaustMap
- * @owner Observable
- */
- function exhaustMap$$1(project, resultSelector) {
- return exhaustMap$1(project, resultSelector)(this);
- }
-
- Observable.prototype.exhaustMap = exhaustMap$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Recursively projects each source value to an Observable which is merged in
- * the output Observable.
- *
- * <span class="informal">It's similar to {@link mergeMap}, but applies the
- * projection function to every source value as well as every output value.
- * It's recursive.</span>
- *
- * <img src="./img/expand.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an Observable, and then merging those resulting Observables and
- * emitting the results of this merger. *Expand* will re-emit on the output
- * Observable every source value. Then, each output value is given to the
- * `project` function which returns an inner Observable to be merged on the
- * output Observable. Those output values resulting from the projection are also
- * given to the `project` function to produce new output values. This is how
- * *expand* behaves recursively.
- *
- * @example <caption>Start emitting the powers of two on every click, at most 10 of them</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var powersOfTwo = clicks
- * .mapTo(1)
- * .expand(x => Rx.Observable.of(2 * x).delay(1000))
- * .take(10);
- * powersOfTwo.subscribe(x => console.log(x));
- *
- * @see {@link mergeMap}
- * @see {@link mergeScan}
- *
- * @param {function(value: T, index: number) => Observable} project A function
- * that, when applied to an item emitted by the source or the output Observable,
- * returns an Observable.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @param {Scheduler} [scheduler=null] The IScheduler to use for subscribing to
- * each projected inner Observable.
- * @return {Observable} An Observable that emits the source values and also
- * result of applying the projection function to each value emitted on the
- * output Observable and and merging the results of the Observables obtained
- * from this transformation.
- * @method expand
- * @owner Observable
- */
- function expand$1(project, concurrent, scheduler) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- if (scheduler === void 0) { scheduler = undefined; }
- concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
- return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
- }
- var ExpandOperator = (function () {
- function ExpandOperator(project, concurrent, scheduler) {
- this.project = project;
- this.concurrent = concurrent;
- this.scheduler = scheduler;
- }
- ExpandOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
- };
- return ExpandOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ExpandSubscriber = (function (_super) {
- __extends(ExpandSubscriber, _super);
- function ExpandSubscriber(destination, project, concurrent, scheduler) {
- _super.call(this, destination);
- this.project = project;
- this.concurrent = concurrent;
- this.scheduler = scheduler;
- this.index = 0;
- this.active = 0;
- this.hasCompleted = false;
- if (concurrent < Number.POSITIVE_INFINITY) {
- this.buffer = [];
- }
- }
- ExpandSubscriber.dispatch = function (arg) {
- var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
- subscriber.subscribeToProjection(result, value, index);
- };
- ExpandSubscriber.prototype._next = function (value) {
- var destination = this.destination;
- if (destination.closed) {
- this._complete();
- return;
- }
- var index = this.index++;
- if (this.active < this.concurrent) {
- destination.next(value);
- var result = tryCatch(this.project)(value, index);
- if (result === errorObject) {
- destination.error(errorObject.e);
- }
- else if (!this.scheduler) {
- this.subscribeToProjection(result, value, index);
- }
- else {
- var state = { subscriber: this, result: result, value: value, index: index };
- this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
- }
- }
- else {
- this.buffer.push(value);
- }
- };
- ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
- this.active++;
- this.add(subscribeToResult(this, result, value, index));
- };
- ExpandSubscriber.prototype._complete = function () {
- this.hasCompleted = true;
- if (this.hasCompleted && this.active === 0) {
- this.destination.complete();
- }
- };
- ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this._next(innerValue);
- };
- ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
- var buffer = this.buffer;
- this.remove(innerSub);
- this.active--;
- if (buffer && buffer.length > 0) {
- this._next(buffer.shift());
- }
- if (this.hasCompleted && this.active === 0) {
- this.destination.complete();
- }
- };
- return ExpandSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Recursively projects each source value to an Observable which is merged in
- * the output Observable.
- *
- * <span class="informal">It's similar to {@link mergeMap}, but applies the
- * projection function to every source value as well as every output value.
- * It's recursive.</span>
- *
- * <img src="./img/expand.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an Observable, and then merging those resulting Observables and
- * emitting the results of this merger. *Expand* will re-emit on the output
- * Observable every source value. Then, each output value is given to the
- * `project` function which returns an inner Observable to be merged on the
- * output Observable. Those output values resulting from the projection are also
- * given to the `project` function to produce new output values. This is how
- * *expand* behaves recursively.
- *
- * @example <caption>Start emitting the powers of two on every click, at most 10 of them</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var powersOfTwo = clicks
- * .mapTo(1)
- * .expand(x => Rx.Observable.of(2 * x).delay(1000))
- * .take(10);
- * powersOfTwo.subscribe(x => console.log(x));
- *
- * @see {@link mergeMap}
- * @see {@link mergeScan}
- *
- * @param {function(value: T, index: number) => Observable} project A function
- * that, when applied to an item emitted by the source or the output Observable,
- * returns an Observable.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @param {Scheduler} [scheduler=null] The IScheduler to use for subscribing to
- * each projected inner Observable.
- * @return {Observable} An Observable that emits the source values and also
- * result of applying the projection function to each value emitted on the
- * output Observable and and merging the results of the Observables obtained
- * from this transformation.
- * @method expand
- * @owner Observable
- */
- function expand$$1(project, concurrent, scheduler) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- if (scheduler === void 0) { scheduler = undefined; }
- concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
- return expand$1(project, concurrent, scheduler)(this);
- }
-
- Observable.prototype.expand = expand$$1;
-
- /**
- * An error thrown when an element was queried at a certain index of an
- * Observable, but no such index or position exists in that sequence.
- *
- * @see {@link elementAt}
- * @see {@link take}
- * @see {@link takeLast}
- *
- * @class ArgumentOutOfRangeError
- */
- var ArgumentOutOfRangeError = (function (_super) {
- __extends(ArgumentOutOfRangeError, _super);
- function ArgumentOutOfRangeError() {
- var err = _super.call(this, 'argument out of range');
- this.name = err.name = 'ArgumentOutOfRangeError';
- this.stack = err.stack;
- this.message = err.message;
- }
- return ArgumentOutOfRangeError;
- }(Error));
-
- /**
- * Emits the single value at the specified `index` in a sequence of emissions
- * from the source Observable.
- *
- * <span class="informal">Emits only the i-th value, then completes.</span>
- *
- * <img src="./img/elementAt.png" width="100%">
- *
- * `elementAt` returns an Observable that emits the item at the specified
- * `index` in the source Observable, or a default value if that `index` is out
- * of range and the `default` argument is provided. If the `default` argument is
- * not given and the `index` is out of range, the output Observable will emit an
- * `ArgumentOutOfRangeError` error.
- *
- * @example <caption>Emit only the third click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.elementAt(2);
- * result.subscribe(x => console.log(x));
- *
- * // Results in:
- * // click 1 = nothing
- * // click 2 = nothing
- * // click 3 = MouseEvent object logged to console
- *
- * @see {@link first}
- * @see {@link last}
- * @see {@link skip}
- * @see {@link single}
- * @see {@link take}
- *
- * @throws {ArgumentOutOfRangeError} When using `elementAt(i)`, it delivers an
- * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0` or the
- * Observable has completed before emitting the i-th `next` notification.
- *
- * @param {number} index Is the number `i` for the i-th source emission that has
- * happened since the subscription, starting from the number `0`.
- * @param {T} [defaultValue] The default value returned for missing indices.
- * @return {Observable} An Observable that emits a single item, if it is found.
- * Otherwise, will emit the default value if given. If not, then emits an error.
- * @method elementAt
- * @owner Observable
- */
- function elementAt$1(index, defaultValue) {
- return function (source) { return source.lift(new ElementAtOperator(index, defaultValue)); };
- }
- var ElementAtOperator = (function () {
- function ElementAtOperator(index, defaultValue) {
- this.index = index;
- this.defaultValue = defaultValue;
- if (index < 0) {
- throw new ArgumentOutOfRangeError;
- }
- }
- ElementAtOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ElementAtSubscriber(subscriber, this.index, this.defaultValue));
- };
- return ElementAtOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ElementAtSubscriber = (function (_super) {
- __extends(ElementAtSubscriber, _super);
- function ElementAtSubscriber(destination, index, defaultValue) {
- _super.call(this, destination);
- this.index = index;
- this.defaultValue = defaultValue;
- }
- ElementAtSubscriber.prototype._next = function (x) {
- if (this.index-- === 0) {
- this.destination.next(x);
- this.destination.complete();
- }
- };
- ElementAtSubscriber.prototype._complete = function () {
- var destination = this.destination;
- if (this.index >= 0) {
- if (typeof this.defaultValue !== 'undefined') {
- destination.next(this.defaultValue);
- }
- else {
- destination.error(new ArgumentOutOfRangeError);
- }
- }
- destination.complete();
- };
- return ElementAtSubscriber;
- }(Subscriber));
-
- /**
- * Emits the single value at the specified `index` in a sequence of emissions
- * from the source Observable.
- *
- * <span class="informal">Emits only the i-th value, then completes.</span>
- *
- * <img src="./img/elementAt.png" width="100%">
- *
- * `elementAt` returns an Observable that emits the item at the specified
- * `index` in the source Observable, or a default value if that `index` is out
- * of range and the `default` argument is provided. If the `default` argument is
- * not given and the `index` is out of range, the output Observable will emit an
- * `ArgumentOutOfRangeError` error.
- *
- * @example <caption>Emit only the third click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.elementAt(2);
- * result.subscribe(x => console.log(x));
- *
- * // Results in:
- * // click 1 = nothing
- * // click 2 = nothing
- * // click 3 = MouseEvent object logged to console
- *
- * @see {@link first}
- * @see {@link last}
- * @see {@link skip}
- * @see {@link single}
- * @see {@link take}
- *
- * @throws {ArgumentOutOfRangeError} When using `elementAt(i)`, it delivers an
- * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0` or the
- * Observable has completed before emitting the i-th `next` notification.
- *
- * @param {number} index Is the number `i` for the i-th source emission that has
- * happened since the subscription, starting from the number `0`.
- * @param {T} [defaultValue] The default value returned for missing indices.
- * @return {Observable} An Observable that emits a single item, if it is found.
- * Otherwise, will emit the default value if given. If not, then emits an error.
- * @method elementAt
- * @owner Observable
- */
- function elementAt$$1(index, defaultValue) {
- return elementAt$1(index, defaultValue)(this);
- }
-
- Observable.prototype.elementAt = elementAt$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Filter items emitted by the source Observable by only emitting those that
- * satisfy a specified predicate.
- *
- * <span class="informal">Like
- * [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
- * it only emits a value from the source if it passes a criterion function.</span>
- *
- * <img src="./img/filter.png" width="100%">
- *
- * Similar to the well-known `Array.prototype.filter` method, this operator
- * takes values from the source Observable, passes them through a `predicate`
- * function and only emits those values that yielded `true`.
- *
- * @example <caption>Emit only click events whose target was a DIV element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var clicksOnDivs = clicks.filter(ev => ev.target.tagName === 'DIV');
- * clicksOnDivs.subscribe(x => console.log(x));
- *
- * @see {@link distinct}
- * @see {@link distinctUntilChanged}
- * @see {@link distinctUntilKeyChanged}
- * @see {@link ignoreElements}
- * @see {@link partition}
- * @see {@link skip}
- *
- * @param {function(value: T, index: number): boolean} predicate A function that
- * evaluates each value emitted by the source Observable. If it returns `true`,
- * the value is emitted, if `false` the value is not passed to the output
- * Observable. The `index` parameter is the number `i` for the i-th source
- * emission that has happened since the subscription, starting from the number
- * `0`.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {Observable} An Observable of values from the source that were
- * allowed by the `predicate` function.
- * @method filter
- * @owner Observable
- */
- function filter$1(predicate, thisArg) {
- return function filterOperatorFunction(source) {
- return source.lift(new FilterOperator(predicate, thisArg));
- };
- }
- var FilterOperator = (function () {
- function FilterOperator(predicate, thisArg) {
- this.predicate = predicate;
- this.thisArg = thisArg;
- }
- FilterOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
- };
- return FilterOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var FilterSubscriber = (function (_super) {
- __extends(FilterSubscriber, _super);
- function FilterSubscriber(destination, predicate, thisArg) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.thisArg = thisArg;
- this.count = 0;
- }
- // the try catch block below is left specifically for
- // optimization and perf reasons. a tryCatcher is not necessary here.
- FilterSubscriber.prototype._next = function (value) {
- var result;
- try {
- result = this.predicate.call(this.thisArg, value, this.count++);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- if (result) {
- this.destination.next(value);
- }
- };
- return FilterSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Filter items emitted by the source Observable by only emitting those that
- * satisfy a specified predicate.
- *
- * <span class="informal">Like
- * [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
- * it only emits a value from the source if it passes a criterion function.</span>
- *
- * <img src="./img/filter.png" width="100%">
- *
- * Similar to the well-known `Array.prototype.filter` method, this operator
- * takes values from the source Observable, passes them through a `predicate`
- * function and only emits those values that yielded `true`.
- *
- * @example <caption>Emit only click events whose target was a DIV element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var clicksOnDivs = clicks.filter(ev => ev.target.tagName === 'DIV');
- * clicksOnDivs.subscribe(x => console.log(x));
- *
- * @see {@link distinct}
- * @see {@link distinctUntilChanged}
- * @see {@link distinctUntilKeyChanged}
- * @see {@link ignoreElements}
- * @see {@link partition}
- * @see {@link skip}
- *
- * @param {function(value: T, index: number): boolean} predicate A function that
- * evaluates each value emitted by the source Observable. If it returns `true`,
- * the value is emitted, if `false` the value is not passed to the output
- * Observable. The `index` parameter is the number `i` for the i-th source
- * emission that has happened since the subscription, starting from the number
- * `0`.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {Observable} An Observable of values from the source that were
- * allowed by the `predicate` function.
- * @method filter
- * @owner Observable
- */
- function filter$$1(predicate, thisArg) {
- return filter$1(predicate, thisArg)(this);
- }
-
- Observable.prototype.filter = filter$$1;
-
- /**
- * Returns an Observable that mirrors the source Observable, but will call a specified function when
- * the source terminates on complete or error.
- * @param {function} callback Function to be called when source terminates.
- * @return {Observable} An Observable that mirrors the source, but will call the specified function on termination.
- * @method finally
- * @owner Observable
- */
- function finalize(callback) {
- return function (source) { return source.lift(new FinallyOperator(callback)); };
- }
- var FinallyOperator = (function () {
- function FinallyOperator(callback) {
- this.callback = callback;
- }
- FinallyOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new FinallySubscriber(subscriber, this.callback));
- };
- return FinallyOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var FinallySubscriber = (function (_super) {
- __extends(FinallySubscriber, _super);
- function FinallySubscriber(destination, callback) {
- _super.call(this, destination);
- this.add(new Subscription(callback));
- }
- return FinallySubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that mirrors the source Observable, but will call a specified function when
- * the source terminates on complete or error.
- * @param {function} callback Function to be called when source terminates.
- * @return {Observable} An Observable that mirrors the source, but will call the specified function on termination.
- * @method finally
- * @owner Observable
- */
- function _finally(callback) {
- return finalize(callback)(this);
- }
-
- Observable.prototype.finally = _finally;
- Observable.prototype._finally = _finally;
-
- /**
- * Emits only the first value emitted by the source Observable that meets some
- * condition.
- *
- * <span class="informal">Finds the first value that passes some test and emits
- * that.</span>
- *
- * <img src="./img/find.png" width="100%">
- *
- * `find` searches for the first item in the source Observable that matches the
- * specified condition embodied by the `predicate`, and returns the first
- * occurrence in the source. Unlike {@link first}, the `predicate` is required
- * in `find`, and does not emit an error if a valid value is not found.
- *
- * @example <caption>Find and emit the first click that happens on a DIV element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.find(ev => ev.target.tagName === 'DIV');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link filter}
- * @see {@link first}
- * @see {@link findIndex}
- * @see {@link take}
- *
- * @param {function(value: T, index: number, source: Observable<T>): boolean} predicate
- * A function called with each item to test for condition matching.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {Observable<T>} An Observable of the first item that matches the
- * condition.
- * @method find
- * @owner Observable
- */
- function find$1(predicate, thisArg) {
- if (typeof predicate !== 'function') {
- throw new TypeError('predicate is not a function');
- }
- return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
- }
- var FindValueOperator = (function () {
- function FindValueOperator(predicate, source, yieldIndex, thisArg) {
- this.predicate = predicate;
- this.source = source;
- this.yieldIndex = yieldIndex;
- this.thisArg = thisArg;
- }
- FindValueOperator.prototype.call = function (observer, source) {
- return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
- };
- return FindValueOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var FindValueSubscriber = (function (_super) {
- __extends(FindValueSubscriber, _super);
- function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.source = source;
- this.yieldIndex = yieldIndex;
- this.thisArg = thisArg;
- this.index = 0;
- }
- FindValueSubscriber.prototype.notifyComplete = function (value) {
- var destination = this.destination;
- destination.next(value);
- destination.complete();
- };
- FindValueSubscriber.prototype._next = function (value) {
- var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
- var index = this.index++;
- try {
- var result = predicate.call(thisArg || this, value, index, this.source);
- if (result) {
- this.notifyComplete(this.yieldIndex ? index : value);
- }
- }
- catch (err) {
- this.destination.error(err);
- }
- };
- FindValueSubscriber.prototype._complete = function () {
- this.notifyComplete(this.yieldIndex ? -1 : undefined);
- };
- return FindValueSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Emits only the first value emitted by the source Observable that meets some
- * condition.
- *
- * <span class="informal">Finds the first value that passes some test and emits
- * that.</span>
- *
- * <img src="./img/find.png" width="100%">
- *
- * `find` searches for the first item in the source Observable that matches the
- * specified condition embodied by the `predicate`, and returns the first
- * occurrence in the source. Unlike {@link first}, the `predicate` is required
- * in `find`, and does not emit an error if a valid value is not found.
- *
- * @example <caption>Find and emit the first click that happens on a DIV element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.find(ev => ev.target.tagName === 'DIV');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link filter}
- * @see {@link first}
- * @see {@link findIndex}
- * @see {@link take}
- *
- * @param {function(value: T, index: number, source: Observable<T>): boolean} predicate
- * A function called with each item to test for condition matching.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {Observable<T>} An Observable of the first item that matches the
- * condition.
- * @method find
- * @owner Observable
- */
- function find$$1(predicate, thisArg) {
- return find$1(predicate, thisArg)(this);
- }
-
- Observable.prototype.find = find$$1;
-
- /**
- * Emits only the index of the first value emitted by the source Observable that
- * meets some condition.
- *
- * <span class="informal">It's like {@link find}, but emits the index of the
- * found value, not the value itself.</span>
- *
- * <img src="./img/findIndex.png" width="100%">
- *
- * `findIndex` searches for the first item in the source Observable that matches
- * the specified condition embodied by the `predicate`, and returns the
- * (zero-based) index of the first occurrence in the source. Unlike
- * {@link first}, the `predicate` is required in `findIndex`, and does not emit
- * an error if a valid value is not found.
- *
- * @example <caption>Emit the index of first click that happens on a DIV element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.findIndex(ev => ev.target.tagName === 'DIV');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link filter}
- * @see {@link find}
- * @see {@link first}
- * @see {@link take}
- *
- * @param {function(value: T, index: number, source: Observable<T>): boolean} predicate
- * A function called with each item to test for condition matching.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {Observable} An Observable of the index of the first item that
- * matches the condition.
- * @method find
- * @owner Observable
- */
- function findIndex$1(predicate, thisArg) {
- return function (source) { return source.lift(new FindValueOperator(predicate, source, true, thisArg)); };
- }
-
- /**
- * Emits only the index of the first value emitted by the source Observable that
- * meets some condition.
- *
- * <span class="informal">It's like {@link find}, but emits the index of the
- * found value, not the value itself.</span>
- *
- * <img src="./img/findIndex.png" width="100%">
- *
- * `findIndex` searches for the first item in the source Observable that matches
- * the specified condition embodied by the `predicate`, and returns the
- * (zero-based) index of the first occurrence in the source. Unlike
- * {@link first}, the `predicate` is required in `findIndex`, and does not emit
- * an error if a valid value is not found.
- *
- * @example <caption>Emit the index of first click that happens on a DIV element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.findIndex(ev => ev.target.tagName === 'DIV');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link filter}
- * @see {@link find}
- * @see {@link first}
- * @see {@link take}
- *
- * @param {function(value: T, index: number, source: Observable<T>): boolean} predicate
- * A function called with each item to test for condition matching.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {Observable} An Observable of the index of the first item that
- * matches the condition.
- * @method find
- * @owner Observable
- */
- function findIndex$$1(predicate, thisArg) {
- return findIndex$1(predicate, thisArg)(this);
- }
-
- Observable.prototype.findIndex = findIndex$$1;
-
- /**
- * An error thrown when an Observable or a sequence was queried but has no
- * elements.
- *
- * @see {@link first}
- * @see {@link last}
- * @see {@link single}
- *
- * @class EmptyError
- */
- var EmptyError = (function (_super) {
- __extends(EmptyError, _super);
- function EmptyError() {
- var err = _super.call(this, 'no elements in sequence');
- this.name = err.name = 'EmptyError';
- this.stack = err.stack;
- this.message = err.message;
- }
- return EmptyError;
- }(Error));
-
- /**
- * Emits only the first value (or the first value that meets some condition)
- * emitted by the source Observable.
- *
- * <span class="informal">Emits only the first value. Or emits only the first
- * value that passes some test.</span>
- *
- * <img src="./img/first.png" width="100%">
- *
- * If called with no arguments, `first` emits the first value of the source
- * Observable, then completes. If called with a `predicate` function, `first`
- * emits the first value of the source that matches the specified condition. It
- * may also take a `resultSelector` function to produce the output value from
- * the input value, and a `defaultValue` to emit in case the source completes
- * before it is able to emit a valid value. Throws an error if `defaultValue`
- * was not provided and a matching element is not found.
- *
- * @example <caption>Emit only the first click that happens on the DOM</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.first();
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Emits the first click that happens on a DIV</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.first(ev => ev.target.tagName === 'DIV');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link filter}
- * @see {@link find}
- * @see {@link take}
- *
- * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
- * callback if the Observable completes before any `next` notification was sent.
- *
- * @param {function(value: T, index: number, source: Observable<T>): boolean} [predicate]
- * An optional function called with each item to test for condition matching.
- * @param {function(value: T, index: number): R} [resultSelector] A function to
- * produce the value on the output Observable based on the values
- * and the indices of the source Observable. The arguments passed to this
- * function are:
- * - `value`: the value that was emitted on the source.
- * - `index`: the "index" of the value from the source.
- * @param {R} [defaultValue] The default value emitted in case no valid value
- * was found on the source.
- * @return {Observable<T|R>} An Observable of the first item that matches the
- * condition.
- * @method first
- * @owner Observable
- */
- function first$1(predicate, resultSelector, defaultValue) {
- return function (source) { return source.lift(new FirstOperator(predicate, resultSelector, defaultValue, source)); };
- }
- var FirstOperator = (function () {
- function FirstOperator(predicate, resultSelector, defaultValue, source) {
- this.predicate = predicate;
- this.resultSelector = resultSelector;
- this.defaultValue = defaultValue;
- this.source = source;
- }
- FirstOperator.prototype.call = function (observer, source) {
- return source.subscribe(new FirstSubscriber(observer, this.predicate, this.resultSelector, this.defaultValue, this.source));
- };
- return FirstOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var FirstSubscriber = (function (_super) {
- __extends(FirstSubscriber, _super);
- function FirstSubscriber(destination, predicate, resultSelector, defaultValue, source) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.resultSelector = resultSelector;
- this.defaultValue = defaultValue;
- this.source = source;
- this.index = 0;
- this.hasCompleted = false;
- this._emitted = false;
- }
- FirstSubscriber.prototype._next = function (value) {
- var index = this.index++;
- if (this.predicate) {
- this._tryPredicate(value, index);
- }
- else {
- this._emit(value, index);
- }
- };
- FirstSubscriber.prototype._tryPredicate = function (value, index) {
- var result;
- try {
- result = this.predicate(value, index, this.source);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- if (result) {
- this._emit(value, index);
- }
- };
- FirstSubscriber.prototype._emit = function (value, index) {
- if (this.resultSelector) {
- this._tryResultSelector(value, index);
- return;
- }
- this._emitFinal(value);
- };
- FirstSubscriber.prototype._tryResultSelector = function (value, index) {
- var result;
- try {
- result = this.resultSelector(value, index);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this._emitFinal(result);
- };
- FirstSubscriber.prototype._emitFinal = function (value) {
- var destination = this.destination;
- if (!this._emitted) {
- this._emitted = true;
- destination.next(value);
- destination.complete();
- this.hasCompleted = true;
- }
- };
- FirstSubscriber.prototype._complete = function () {
- var destination = this.destination;
- if (!this.hasCompleted && typeof this.defaultValue !== 'undefined') {
- destination.next(this.defaultValue);
- destination.complete();
- }
- else if (!this.hasCompleted) {
- destination.error(new EmptyError);
- }
- };
- return FirstSubscriber;
- }(Subscriber));
-
- /**
- * Emits only the first value (or the first value that meets some condition)
- * emitted by the source Observable.
- *
- * <span class="informal">Emits only the first value. Or emits only the first
- * value that passes some test.</span>
- *
- * <img src="./img/first.png" width="100%">
- *
- * If called with no arguments, `first` emits the first value of the source
- * Observable, then completes. If called with a `predicate` function, `first`
- * emits the first value of the source that matches the specified condition. It
- * may also take a `resultSelector` function to produce the output value from
- * the input value, and a `defaultValue` to emit in case the source completes
- * before it is able to emit a valid value. Throws an error if `defaultValue`
- * was not provided and a matching element is not found.
- *
- * @example <caption>Emit only the first click that happens on the DOM</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.first();
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Emits the first click that happens on a DIV</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.first(ev => ev.target.tagName === 'DIV');
- * result.subscribe(x => console.log(x));
- *
- * @see {@link filter}
- * @see {@link find}
- * @see {@link take}
- *
- * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
- * callback if the Observable completes before any `next` notification was sent.
- *
- * @param {function(value: T, index: number, source: Observable<T>): boolean} [predicate]
- * An optional function called with each item to test for condition matching.
- * @param {function(value: T, index: number): R} [resultSelector] A function to
- * produce the value on the output Observable based on the values
- * and the indices of the source Observable. The arguments passed to this
- * function are:
- * - `value`: the value that was emitted on the source.
- * - `index`: the "index" of the value from the source.
- * @param {R} [defaultValue] The default value emitted in case no valid value
- * was found on the source.
- * @return {Observable<T|R>} An Observable of the first item that matches the
- * condition.
- * @method first
- * @owner Observable
- */
- function first$$1(predicate, resultSelector, defaultValue) {
- return first$1(predicate, resultSelector, defaultValue)(this);
- }
-
- Observable.prototype.first = first$$1;
-
- var MapPolyfill = (function () {
- function MapPolyfill() {
- this.size = 0;
- this._values = [];
- this._keys = [];
- }
- MapPolyfill.prototype.get = function (key) {
- var i = this._keys.indexOf(key);
- return i === -1 ? undefined : this._values[i];
- };
- MapPolyfill.prototype.set = function (key, value) {
- var i = this._keys.indexOf(key);
- if (i === -1) {
- this._keys.push(key);
- this._values.push(value);
- this.size++;
- }
- else {
- this._values[i] = value;
- }
- return this;
- };
- MapPolyfill.prototype.delete = function (key) {
- var i = this._keys.indexOf(key);
- if (i === -1) {
- return false;
- }
- this._values.splice(i, 1);
- this._keys.splice(i, 1);
- this.size--;
- return true;
- };
- MapPolyfill.prototype.clear = function () {
- this._keys.length = 0;
- this._values.length = 0;
- this.size = 0;
- };
- MapPolyfill.prototype.forEach = function (cb, thisArg) {
- for (var i = 0; i < this.size; i++) {
- cb.call(thisArg, this._values[i], this._keys[i]);
- }
- };
- return MapPolyfill;
- }());
-
- var Map = _root.Map || (function () { return MapPolyfill; })();
-
- var FastMap = (function () {
- function FastMap() {
- this.values = {};
- }
- FastMap.prototype.delete = function (key) {
- this.values[key] = null;
- return true;
- };
- FastMap.prototype.set = function (key, value) {
- this.values[key] = value;
- return this;
- };
- FastMap.prototype.get = function (key) {
- return this.values[key];
- };
- FastMap.prototype.forEach = function (cb, thisArg) {
- var values = this.values;
- for (var key in values) {
- if (values.hasOwnProperty(key) && values[key] !== null) {
- cb.call(thisArg, values[key], key);
- }
- }
- };
- FastMap.prototype.clear = function () {
- this.values = {};
- };
- return FastMap;
- }());
-
- /* tslint:enable:max-line-length */
- /**
- * Groups the items emitted by an Observable according to a specified criterion,
- * and emits these grouped items as `GroupedObservables`, one
- * {@link GroupedObservable} per group.
- *
- * <img src="./img/groupBy.png" width="100%">
- *
- * @example <caption>Group objects by id and return as array</caption>
- * Observable.of<Obj>({id: 1, name: 'aze1'},
- * {id: 2, name: 'sf2'},
- * {id: 2, name: 'dg2'},
- * {id: 1, name: 'erg1'},
- * {id: 1, name: 'df1'},
- * {id: 2, name: 'sfqfb2'},
- * {id: 3, name: 'qfs3'},
- * {id: 2, name: 'qsgqsfg2'}
- * )
- * .groupBy(p => p.id)
- * .flatMap( (group$) => group$.reduce((acc, cur) => [...acc, cur], []))
- * .subscribe(p => console.log(p));
- *
- * // displays:
- * // [ { id: 1, name: 'aze1' },
- * // { id: 1, name: 'erg1' },
- * // { id: 1, name: 'df1' } ]
- * //
- * // [ { id: 2, name: 'sf2' },
- * // { id: 2, name: 'dg2' },
- * // { id: 2, name: 'sfqfb2' },
- * // { id: 2, name: 'qsgqsfg2' } ]
- * //
- * // [ { id: 3, name: 'qfs3' } ]
- *
- * @example <caption>Pivot data on the id field</caption>
- * Observable.of<Obj>({id: 1, name: 'aze1'},
- * {id: 2, name: 'sf2'},
- * {id: 2, name: 'dg2'},
- * {id: 1, name: 'erg1'},
- * {id: 1, name: 'df1'},
- * {id: 2, name: 'sfqfb2'},
- * {id: 3, name: 'qfs1'},
- * {id: 2, name: 'qsgqsfg2'}
- * )
- * .groupBy(p => p.id, p => p.name)
- * .flatMap( (group$) => group$.reduce((acc, cur) => [...acc, cur], ["" + group$.key]))
- * .map(arr => ({'id': parseInt(arr[0]), 'values': arr.slice(1)}))
- * .subscribe(p => console.log(p));
- *
- * // displays:
- * // { id: 1, values: [ 'aze1', 'erg1', 'df1' ] }
- * // { id: 2, values: [ 'sf2', 'dg2', 'sfqfb2', 'qsgqsfg2' ] }
- * // { id: 3, values: [ 'qfs1' ] }
- *
- * @param {function(value: T): K} keySelector A function that extracts the key
- * for each item.
- * @param {function(value: T): R} [elementSelector] A function that extracts the
- * return element for each item.
- * @param {function(grouped: GroupedObservable<K,R>): Observable<any>} [durationSelector]
- * A function that returns an Observable to determine how long each group should
- * exist.
- * @return {Observable<GroupedObservable<K,R>>} An Observable that emits
- * GroupedObservables, each of which corresponds to a unique key value and each
- * of which emits those items from the source Observable that share that key
- * value.
- * @method groupBy
- * @owner Observable
- */
- function groupBy$1(keySelector, elementSelector, durationSelector, subjectSelector) {
- return function (source) {
- return source.lift(new GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector));
- };
- }
- var GroupByOperator = (function () {
- function GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector) {
- this.keySelector = keySelector;
- this.elementSelector = elementSelector;
- this.durationSelector = durationSelector;
- this.subjectSelector = subjectSelector;
- }
- GroupByOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new GroupBySubscriber(subscriber, this.keySelector, this.elementSelector, this.durationSelector, this.subjectSelector));
- };
- return GroupByOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var GroupBySubscriber = (function (_super) {
- __extends(GroupBySubscriber, _super);
- function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector, subjectSelector) {
- _super.call(this, destination);
- this.keySelector = keySelector;
- this.elementSelector = elementSelector;
- this.durationSelector = durationSelector;
- this.subjectSelector = subjectSelector;
- this.groups = null;
- this.attemptedToUnsubscribe = false;
- this.count = 0;
- }
- GroupBySubscriber.prototype._next = function (value) {
- var key;
- try {
- key = this.keySelector(value);
- }
- catch (err) {
- this.error(err);
- return;
- }
- this._group(value, key);
- };
- GroupBySubscriber.prototype._group = function (value, key) {
- var groups = this.groups;
- if (!groups) {
- groups = this.groups = typeof key === 'string' ? new FastMap() : new Map();
- }
- var group = groups.get(key);
- var element;
- if (this.elementSelector) {
- try {
- element = this.elementSelector(value);
- }
- catch (err) {
- this.error(err);
- }
- }
- else {
- element = value;
- }
- if (!group) {
- group = this.subjectSelector ? this.subjectSelector() : new Subject();
- groups.set(key, group);
- var groupedObservable = new GroupedObservable(key, group, this);
- this.destination.next(groupedObservable);
- if (this.durationSelector) {
- var duration = void 0;
- try {
- duration = this.durationSelector(new GroupedObservable(key, group));
- }
- catch (err) {
- this.error(err);
- return;
- }
- this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this)));
- }
- }
- if (!group.closed) {
- group.next(element);
- }
- };
- GroupBySubscriber.prototype._error = function (err) {
- var groups = this.groups;
- if (groups) {
- groups.forEach(function (group, key) {
- group.error(err);
- });
- groups.clear();
- }
- this.destination.error(err);
- };
- GroupBySubscriber.prototype._complete = function () {
- var groups = this.groups;
- if (groups) {
- groups.forEach(function (group, key) {
- group.complete();
- });
- groups.clear();
- }
- this.destination.complete();
- };
- GroupBySubscriber.prototype.removeGroup = function (key) {
- this.groups.delete(key);
- };
- GroupBySubscriber.prototype.unsubscribe = function () {
- if (!this.closed) {
- this.attemptedToUnsubscribe = true;
- if (this.count === 0) {
- _super.prototype.unsubscribe.call(this);
- }
- }
- };
- return GroupBySubscriber;
- }(Subscriber));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var GroupDurationSubscriber = (function (_super) {
- __extends(GroupDurationSubscriber, _super);
- function GroupDurationSubscriber(key, group, parent) {
- _super.call(this, group);
- this.key = key;
- this.group = group;
- this.parent = parent;
- }
- GroupDurationSubscriber.prototype._next = function (value) {
- this.complete();
- };
- /** @deprecated internal use only */ GroupDurationSubscriber.prototype._unsubscribe = function () {
- var _a = this, parent = _a.parent, key = _a.key;
- this.key = this.parent = null;
- if (parent) {
- parent.removeGroup(key);
- }
- };
- return GroupDurationSubscriber;
- }(Subscriber));
- /**
- * An Observable representing values belonging to the same group represented by
- * a common key. The values emitted by a GroupedObservable come from the source
- * Observable. The common key is available as the field `key` on a
- * GroupedObservable instance.
- *
- * @class GroupedObservable<K, T>
- */
- var GroupedObservable = (function (_super) {
- __extends(GroupedObservable, _super);
- function GroupedObservable(key, groupSubject, refCountSubscription) {
- _super.call(this);
- this.key = key;
- this.groupSubject = groupSubject;
- this.refCountSubscription = refCountSubscription;
- }
- /** @deprecated internal use only */ GroupedObservable.prototype._subscribe = function (subscriber) {
- var subscription = new Subscription();
- var _a = this, refCountSubscription = _a.refCountSubscription, groupSubject = _a.groupSubject;
- if (refCountSubscription && !refCountSubscription.closed) {
- subscription.add(new InnerRefCountSubscription(refCountSubscription));
- }
- subscription.add(groupSubject.subscribe(subscriber));
- return subscription;
- };
- return GroupedObservable;
- }(Observable));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var InnerRefCountSubscription = (function (_super) {
- __extends(InnerRefCountSubscription, _super);
- function InnerRefCountSubscription(parent) {
- _super.call(this);
- this.parent = parent;
- parent.count++;
- }
- InnerRefCountSubscription.prototype.unsubscribe = function () {
- var parent = this.parent;
- if (!parent.closed && !this.closed) {
- _super.prototype.unsubscribe.call(this);
- parent.count -= 1;
- if (parent.count === 0 && parent.attemptedToUnsubscribe) {
- parent.unsubscribe();
- }
- }
- };
- return InnerRefCountSubscription;
- }(Subscription));
-
- /* tslint:enable:max-line-length */
- /**
- * Groups the items emitted by an Observable according to a specified criterion,
- * and emits these grouped items as `GroupedObservables`, one
- * {@link GroupedObservable} per group.
- *
- * <img src="./img/groupBy.png" width="100%">
- *
- * @example <caption>Group objects by id and return as array</caption>
- * Observable.of<Obj>({id: 1, name: 'aze1'},
- * {id: 2, name: 'sf2'},
- * {id: 2, name: 'dg2'},
- * {id: 1, name: 'erg1'},
- * {id: 1, name: 'df1'},
- * {id: 2, name: 'sfqfb2'},
- * {id: 3, name: 'qfs3'},
- * {id: 2, name: 'qsgqsfg2'}
- * )
- * .groupBy(p => p.id)
- * .flatMap( (group$) => group$.reduce((acc, cur) => [...acc, cur], []))
- * .subscribe(p => console.log(p));
- *
- * // displays:
- * // [ { id: 1, name: 'aze1' },
- * // { id: 1, name: 'erg1' },
- * // { id: 1, name: 'df1' } ]
- * //
- * // [ { id: 2, name: 'sf2' },
- * // { id: 2, name: 'dg2' },
- * // { id: 2, name: 'sfqfb2' },
- * // { id: 2, name: 'qsgqsfg2' } ]
- * //
- * // [ { id: 3, name: 'qfs3' } ]
- *
- * @example <caption>Pivot data on the id field</caption>
- * Observable.of<Obj>({id: 1, name: 'aze1'},
- * {id: 2, name: 'sf2'},
- * {id: 2, name: 'dg2'},
- * {id: 1, name: 'erg1'},
- * {id: 1, name: 'df1'},
- * {id: 2, name: 'sfqfb2'},
- * {id: 3, name: 'qfs1'},
- * {id: 2, name: 'qsgqsfg2'}
- * )
- * .groupBy(p => p.id, p => p.name)
- * .flatMap( (group$) => group$.reduce((acc, cur) => [...acc, cur], ["" + group$.key]))
- * .map(arr => ({'id': parseInt(arr[0]), 'values': arr.slice(1)}))
- * .subscribe(p => console.log(p));
- *
- * // displays:
- * // { id: 1, values: [ 'aze1', 'erg1', 'df1' ] }
- * // { id: 2, values: [ 'sf2', 'dg2', 'sfqfb2', 'qsgqsfg2' ] }
- * // { id: 3, values: [ 'qfs1' ] }
- *
- * @param {function(value: T): K} keySelector A function that extracts the key
- * for each item.
- * @param {function(value: T): R} [elementSelector] A function that extracts the
- * return element for each item.
- * @param {function(grouped: GroupedObservable<K,R>): Observable<any>} [durationSelector]
- * A function that returns an Observable to determine how long each group should
- * exist.
- * @return {Observable<GroupedObservable<K,R>>} An Observable that emits
- * GroupedObservables, each of which corresponds to a unique key value and each
- * of which emits those items from the source Observable that share that key
- * value.
- * @method groupBy
- * @owner Observable
- */
- function groupBy$$1(keySelector, elementSelector, durationSelector, subjectSelector) {
- return groupBy$1(keySelector, elementSelector, durationSelector, subjectSelector)(this);
- }
-
- Observable.prototype.groupBy = groupBy$$1;
-
- /**
- * Ignores all items emitted by the source Observable and only passes calls of `complete` or `error`.
- *
- * <img src="./img/ignoreElements.png" width="100%">
- *
- * @return {Observable} An empty Observable that only calls `complete`
- * or `error`, based on which one is called by the source Observable.
- * @method ignoreElements
- * @owner Observable
- */
- function ignoreElements$1() {
- return function ignoreElementsOperatorFunction(source) {
- return source.lift(new IgnoreElementsOperator());
- };
- }
- var IgnoreElementsOperator = (function () {
- function IgnoreElementsOperator() {
- }
- IgnoreElementsOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new IgnoreElementsSubscriber(subscriber));
- };
- return IgnoreElementsOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var IgnoreElementsSubscriber = (function (_super) {
- __extends(IgnoreElementsSubscriber, _super);
- function IgnoreElementsSubscriber() {
- _super.apply(this, arguments);
- }
- IgnoreElementsSubscriber.prototype._next = function (unused) {
- noop();
- };
- return IgnoreElementsSubscriber;
- }(Subscriber));
-
- /**
- * Ignores all items emitted by the source Observable and only passes calls of `complete` or `error`.
- *
- * <img src="./img/ignoreElements.png" width="100%">
- *
- * @return {Observable} An empty Observable that only calls `complete`
- * or `error`, based on which one is called by the source Observable.
- * @method ignoreElements
- * @owner Observable
- */
- function ignoreElements$$1() {
- return ignoreElements$1()(this);
- }
-
- Observable.prototype.ignoreElements = ignoreElements$$1;
-
- function isEmpty$1() {
- return function (source) { return source.lift(new IsEmptyOperator()); };
- }
- var IsEmptyOperator = (function () {
- function IsEmptyOperator() {
- }
- IsEmptyOperator.prototype.call = function (observer, source) {
- return source.subscribe(new IsEmptySubscriber(observer));
- };
- return IsEmptyOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var IsEmptySubscriber = (function (_super) {
- __extends(IsEmptySubscriber, _super);
- function IsEmptySubscriber(destination) {
- _super.call(this, destination);
- }
- IsEmptySubscriber.prototype.notifyComplete = function (isEmpty) {
- var destination = this.destination;
- destination.next(isEmpty);
- destination.complete();
- };
- IsEmptySubscriber.prototype._next = function (value) {
- this.notifyComplete(false);
- };
- IsEmptySubscriber.prototype._complete = function () {
- this.notifyComplete(true);
- };
- return IsEmptySubscriber;
- }(Subscriber));
-
- /**
- * If the source Observable is empty it returns an Observable that emits true, otherwise it emits false.
- *
- * <img src="./img/isEmpty.png" width="100%">
- *
- * @return {Observable} An Observable that emits a Boolean.
- * @method isEmpty
- * @owner Observable
- */
- function isEmpty$$1() {
- return isEmpty$1()(this);
- }
-
- Observable.prototype.isEmpty = isEmpty$$1;
-
- /**
- * Ignores source values for a duration determined by another Observable, then
- * emits the most recent value from the source Observable, then repeats this
- * process.
- *
- * <span class="informal">It's like {@link auditTime}, but the silencing
- * duration is determined by a second Observable.</span>
- *
- * <img src="./img/audit.png" width="100%">
- *
- * `audit` is similar to `throttle`, but emits the last value from the silenced
- * time window, instead of the first value. `audit` emits the most recent value
- * from the source Observable on the output Observable as soon as its internal
- * timer becomes disabled, and ignores source values while the timer is enabled.
- * Initially, the timer is disabled. As soon as the first source value arrives,
- * the timer is enabled by calling the `durationSelector` function with the
- * source value, which returns the "duration" Observable. When the duration
- * Observable emits a value or completes, the timer is disabled, then the most
- * recent source value is emitted on the output Observable, and this process
- * repeats for the next source value.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.audit(ev => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounce}
- * @see {@link delayWhen}
- * @see {@link sample}
- * @see {@link throttle}
- *
- * @param {function(value: T): SubscribableOrPromise} durationSelector A function
- * that receives a value from the source Observable, for computing the silencing
- * duration, returned as an Observable or a Promise.
- * @return {Observable<T>} An Observable that performs rate-limiting of
- * emissions from the source Observable.
- * @method audit
- * @owner Observable
- */
- function audit$1(durationSelector) {
- return function auditOperatorFunction(source) {
- return source.lift(new AuditOperator(durationSelector));
- };
- }
- var AuditOperator = (function () {
- function AuditOperator(durationSelector) {
- this.durationSelector = durationSelector;
- }
- AuditOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
- };
- return AuditOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var AuditSubscriber = (function (_super) {
- __extends(AuditSubscriber, _super);
- function AuditSubscriber(destination, durationSelector) {
- _super.call(this, destination);
- this.durationSelector = durationSelector;
- this.hasValue = false;
- }
- AuditSubscriber.prototype._next = function (value) {
- this.value = value;
- this.hasValue = true;
- if (!this.throttled) {
- var duration = tryCatch(this.durationSelector)(value);
- if (duration === errorObject) {
- this.destination.error(errorObject.e);
- }
- else {
- var innerSubscription = subscribeToResult(this, duration);
- if (innerSubscription.closed) {
- this.clearThrottle();
- }
- else {
- this.add(this.throttled = innerSubscription);
- }
- }
- }
- };
- AuditSubscriber.prototype.clearThrottle = function () {
- var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled;
- if (throttled) {
- this.remove(throttled);
- this.throttled = null;
- throttled.unsubscribe();
- }
- if (hasValue) {
- this.value = null;
- this.hasValue = false;
- this.destination.next(value);
- }
- };
- AuditSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
- this.clearThrottle();
- };
- AuditSubscriber.prototype.notifyComplete = function () {
- this.clearThrottle();
- };
- return AuditSubscriber;
- }(OuterSubscriber));
-
- /**
- * Ignores source values for a duration determined by another Observable, then
- * emits the most recent value from the source Observable, then repeats this
- * process.
- *
- * <span class="informal">It's like {@link auditTime}, but the silencing
- * duration is determined by a second Observable.</span>
- *
- * <img src="./img/audit.png" width="100%">
- *
- * `audit` is similar to `throttle`, but emits the last value from the silenced
- * time window, instead of the first value. `audit` emits the most recent value
- * from the source Observable on the output Observable as soon as its internal
- * timer becomes disabled, and ignores source values while the timer is enabled.
- * Initially, the timer is disabled. As soon as the first source value arrives,
- * the timer is enabled by calling the `durationSelector` function with the
- * source value, which returns the "duration" Observable. When the duration
- * Observable emits a value or completes, the timer is disabled, then the most
- * recent source value is emitted on the output Observable, and this process
- * repeats for the next source value.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.audit(ev => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounce}
- * @see {@link delayWhen}
- * @see {@link sample}
- * @see {@link throttle}
- *
- * @param {function(value: T): SubscribableOrPromise} durationSelector A function
- * that receives a value from the source Observable, for computing the silencing
- * duration, returned as an Observable or a Promise.
- * @return {Observable<T>} An Observable that performs rate-limiting of
- * emissions from the source Observable.
- * @method audit
- * @owner Observable
- */
- function audit$$1(durationSelector) {
- return audit$1(durationSelector)(this);
- }
-
- Observable.prototype.audit = audit$$1;
-
- /**
- * Ignores source values for `duration` milliseconds, then emits the most recent
- * value from the source Observable, then repeats this process.
- *
- * <span class="informal">When it sees a source values, it ignores that plus
- * the next ones for `duration` milliseconds, and then it emits the most recent
- * value from the source.</span>
- *
- * <img src="./img/auditTime.png" width="100%">
- *
- * `auditTime` is similar to `throttleTime`, but emits the last value from the
- * silenced time window, instead of the first value. `auditTime` emits the most
- * recent value from the source Observable on the output Observable as soon as
- * its internal timer becomes disabled, and ignores source values while the
- * timer is enabled. Initially, the timer is disabled. As soon as the first
- * source value arrives, the timer is enabled. After `duration` milliseconds (or
- * the time unit determined internally by the optional `scheduler`) has passed,
- * the timer is disabled, then the most recent source value is emitted on the
- * output Observable, and this process repeats for the next source value.
- * Optionally takes a {@link IScheduler} for managing timers.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.auditTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounceTime}
- * @see {@link delay}
- * @see {@link sampleTime}
- * @see {@link throttleTime}
- *
- * @param {number} duration Time to wait before emitting the most recent source
- * value, measured in milliseconds or the time unit determined internally
- * by the optional `scheduler`.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the rate-limiting behavior.
- * @return {Observable<T>} An Observable that performs rate-limiting of
- * emissions from the source Observable.
- * @method auditTime
- * @owner Observable
- */
- function auditTime$1(duration, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return audit$1(function () { return timer(duration, scheduler); });
- }
-
- /**
- * Ignores source values for `duration` milliseconds, then emits the most recent
- * value from the source Observable, then repeats this process.
- *
- * <span class="informal">When it sees a source values, it ignores that plus
- * the next ones for `duration` milliseconds, and then it emits the most recent
- * value from the source.</span>
- *
- * <img src="./img/auditTime.png" width="100%">
- *
- * `auditTime` is similar to `throttleTime`, but emits the last value from the
- * silenced time window, instead of the first value. `auditTime` emits the most
- * recent value from the source Observable on the output Observable as soon as
- * its internal timer becomes disabled, and ignores source values while the
- * timer is enabled. Initially, the timer is disabled. As soon as the first
- * source value arrives, the timer is enabled. After `duration` milliseconds (or
- * the time unit determined internally by the optional `scheduler`) has passed,
- * the timer is disabled, then the most recent source value is emitted on the
- * output Observable, and this process repeats for the next source value.
- * Optionally takes a {@link IScheduler} for managing timers.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.auditTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounceTime}
- * @see {@link delay}
- * @see {@link sampleTime}
- * @see {@link throttleTime}
- *
- * @param {number} duration Time to wait before emitting the most recent source
- * value, measured in milliseconds or the time unit determined internally
- * by the optional `scheduler`.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the rate-limiting behavior.
- * @return {Observable<T>} An Observable that performs rate-limiting of
- * emissions from the source Observable.
- * @method auditTime
- * @owner Observable
- */
- function auditTime$$1(duration, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return auditTime$1(duration, scheduler)(this);
- }
-
- Observable.prototype.auditTime = auditTime$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits only the last item emitted by the source Observable.
- * It optionally takes a predicate function as a parameter, in which case, rather than emitting
- * the last item from the source Observable, the resulting Observable will emit the last item
- * from the source Observable that satisfies the predicate.
- *
- * <img src="./img/last.png" width="100%">
- *
- * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
- * callback if the Observable completes before any `next` notification was sent.
- * @param {function} predicate - The condition any source emitted item has to satisfy.
- * @return {Observable} An Observable that emits only the last item satisfying the given condition
- * from the source, or an NoSuchElementException if no such items are emitted.
- * @throws - Throws if no items that match the predicate are emitted by the source Observable.
- * @method last
- * @owner Observable
- */
- function last$1(predicate, resultSelector, defaultValue) {
- return function (source) { return source.lift(new LastOperator(predicate, resultSelector, defaultValue, source)); };
- }
- var LastOperator = (function () {
- function LastOperator(predicate, resultSelector, defaultValue, source) {
- this.predicate = predicate;
- this.resultSelector = resultSelector;
- this.defaultValue = defaultValue;
- this.source = source;
- }
- LastOperator.prototype.call = function (observer, source) {
- return source.subscribe(new LastSubscriber(observer, this.predicate, this.resultSelector, this.defaultValue, this.source));
- };
- return LastOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var LastSubscriber = (function (_super) {
- __extends(LastSubscriber, _super);
- function LastSubscriber(destination, predicate, resultSelector, defaultValue, source) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.resultSelector = resultSelector;
- this.defaultValue = defaultValue;
- this.source = source;
- this.hasValue = false;
- this.index = 0;
- if (typeof defaultValue !== 'undefined') {
- this.lastValue = defaultValue;
- this.hasValue = true;
- }
- }
- LastSubscriber.prototype._next = function (value) {
- var index = this.index++;
- if (this.predicate) {
- this._tryPredicate(value, index);
- }
- else {
- if (this.resultSelector) {
- this._tryResultSelector(value, index);
- return;
- }
- this.lastValue = value;
- this.hasValue = true;
- }
- };
- LastSubscriber.prototype._tryPredicate = function (value, index) {
- var result;
- try {
- result = this.predicate(value, index, this.source);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- if (result) {
- if (this.resultSelector) {
- this._tryResultSelector(value, index);
- return;
- }
- this.lastValue = value;
- this.hasValue = true;
- }
- };
- LastSubscriber.prototype._tryResultSelector = function (value, index) {
- var result;
- try {
- result = this.resultSelector(value, index);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.lastValue = result;
- this.hasValue = true;
- };
- LastSubscriber.prototype._complete = function () {
- var destination = this.destination;
- if (this.hasValue) {
- destination.next(this.lastValue);
- destination.complete();
- }
- else {
- destination.error(new EmptyError);
- }
- };
- return LastSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits only the last item emitted by the source Observable.
- * It optionally takes a predicate function as a parameter, in which case, rather than emitting
- * the last item from the source Observable, the resulting Observable will emit the last item
- * from the source Observable that satisfies the predicate.
- *
- * <img src="./img/last.png" width="100%">
- *
- * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
- * callback if the Observable completes before any `next` notification was sent.
- * @param {function} predicate - The condition any source emitted item has to satisfy.
- * @return {Observable} An Observable that emits only the last item satisfying the given condition
- * from the source, or an NoSuchElementException if no such items are emitted.
- * @throws - Throws if no items that match the predicate are emitted by the source Observable.
- * @method last
- * @owner Observable
- */
- function last$$1(predicate, resultSelector, defaultValue) {
- return last$1(predicate, resultSelector, defaultValue)(this);
- }
-
- Observable.prototype.last = last$$1;
-
- /**
- * @param func
- * @return {Observable<R>}
- * @method let
- * @owner Observable
- */
- function letProto(func) {
- return func(this);
- }
-
- Observable.prototype.let = letProto;
- Observable.prototype.letBind = letProto;
-
- /**
- * Returns an Observable that emits whether or not every item of the source satisfies the condition specified.
- *
- * @example <caption>A simple example emitting true if all elements are less than 5, false otherwise</caption>
- * Observable.of(1, 2, 3, 4, 5, 6)
- * .every(x => x < 5)
- * .subscribe(x => console.log(x)); // -> false
- *
- * @param {function} predicate A function for determining if an item meets a specified condition.
- * @param {any} [thisArg] Optional object to use for `this` in the callback.
- * @return {Observable} An Observable of booleans that determines if all items of the source Observable meet the condition specified.
- * @method every
- * @owner Observable
- */
- function every$1(predicate, thisArg) {
- return function (source) { return source.lift(new EveryOperator(predicate, thisArg, source)); };
- }
- var EveryOperator = (function () {
- function EveryOperator(predicate, thisArg, source) {
- this.predicate = predicate;
- this.thisArg = thisArg;
- this.source = source;
- }
- EveryOperator.prototype.call = function (observer, source) {
- return source.subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source));
- };
- return EveryOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var EverySubscriber = (function (_super) {
- __extends(EverySubscriber, _super);
- function EverySubscriber(destination, predicate, thisArg, source) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.thisArg = thisArg;
- this.source = source;
- this.index = 0;
- this.thisArg = thisArg || this;
- }
- EverySubscriber.prototype.notifyComplete = function (everyValueMatch) {
- this.destination.next(everyValueMatch);
- this.destination.complete();
- };
- EverySubscriber.prototype._next = function (value) {
- var result = false;
- try {
- result = this.predicate.call(this.thisArg, value, this.index++, this.source);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- if (!result) {
- this.notifyComplete(false);
- }
- };
- EverySubscriber.prototype._complete = function () {
- this.notifyComplete(true);
- };
- return EverySubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that emits whether or not every item of the source satisfies the condition specified.
- *
- * @example <caption>A simple example emitting true if all elements are less than 5, false otherwise</caption>
- * Observable.of(1, 2, 3, 4, 5, 6)
- * .every(x => x < 5)
- * .subscribe(x => console.log(x)); // -> false
- *
- * @param {function} predicate A function for determining if an item meets a specified condition.
- * @param {any} [thisArg] Optional object to use for `this` in the callback.
- * @return {Observable} An Observable of booleans that determines if all items of the source Observable meet the condition specified.
- * @method every
- * @owner Observable
- */
- function every$$1(predicate, thisArg) {
- return every$1(predicate, thisArg)(this);
- }
-
- Observable.prototype.every = every$$1;
-
- /**
- * Applies a given `project` function to each value emitted by the source
- * Observable, and emits the resulting values as an Observable.
- *
- * <span class="informal">Like [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map),
- * it passes each source value through a transformation function to get
- * corresponding output values.</span>
- *
- * <img src="./img/map.png" width="100%">
- *
- * Similar to the well known `Array.prototype.map` function, this operator
- * applies a projection to each value and emits that projection in the output
- * Observable.
- *
- * @example <caption>Map every click to the clientX position of that click</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var positions = clicks.map(ev => ev.clientX);
- * positions.subscribe(x => console.log(x));
- *
- * @see {@link mapTo}
- * @see {@link pluck}
- *
- * @param {function(value: T, index: number): R} project The function to apply
- * to each `value` emitted by the source Observable. The `index` parameter is
- * the number `i` for the i-th emission that has happened since the
- * subscription, starting from the number `0`.
- * @param {any} [thisArg] An optional argument to define what `this` is in the
- * `project` function.
- * @return {Observable<R>} An Observable that emits the values from the source
- * Observable transformed by the given `project` function.
- * @method map
- * @owner Observable
- */
- function map$1(project, thisArg) {
- return map(project, thisArg)(this);
- }
-
- Observable.prototype.map = map$1;
-
- /**
- * Emits the given constant value on the output Observable every time the source
- * Observable emits a value.
- *
- * <span class="informal">Like {@link map}, but it maps every source value to
- * the same output value every time.</span>
- *
- * <img src="./img/mapTo.png" width="100%">
- *
- * Takes a constant `value` as argument, and emits that whenever the source
- * Observable emits a value. In other words, ignores the actual source value,
- * and simply uses the emission moment to know when to emit the given `value`.
- *
- * @example <caption>Map every click to the string 'Hi'</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var greetings = clicks.mapTo('Hi');
- * greetings.subscribe(x => console.log(x));
- *
- * @see {@link map}
- *
- * @param {any} value The value to map each source value to.
- * @return {Observable} An Observable that emits the given `value` every time
- * the source Observable emits something.
- * @method mapTo
- * @owner Observable
- */
- function mapTo$1(value) {
- return function (source) { return source.lift(new MapToOperator(value)); };
- }
- var MapToOperator = (function () {
- function MapToOperator(value) {
- this.value = value;
- }
- MapToOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new MapToSubscriber(subscriber, this.value));
- };
- return MapToOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var MapToSubscriber = (function (_super) {
- __extends(MapToSubscriber, _super);
- function MapToSubscriber(destination, value) {
- _super.call(this, destination);
- this.value = value;
- }
- MapToSubscriber.prototype._next = function (x) {
- this.destination.next(this.value);
- };
- return MapToSubscriber;
- }(Subscriber));
-
- /**
- * Emits the given constant value on the output Observable every time the source
- * Observable emits a value.
- *
- * <span class="informal">Like {@link map}, but it maps every source value to
- * the same output value every time.</span>
- *
- * <img src="./img/mapTo.png" width="100%">
- *
- * Takes a constant `value` as argument, and emits that whenever the source
- * Observable emits a value. In other words, ignores the actual source value,
- * and simply uses the emission moment to know when to emit the given `value`.
- *
- * @example <caption>Map every click to the string 'Hi'</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var greetings = clicks.mapTo('Hi');
- * greetings.subscribe(x => console.log(x));
- *
- * @see {@link map}
- *
- * @param {any} value The value to map each source value to.
- * @return {Observable} An Observable that emits the given `value` every time
- * the source Observable emits something.
- * @method mapTo
- * @owner Observable
- */
- function mapTo$$1(value) {
- return mapTo$1(value)(this);
- }
-
- Observable.prototype.mapTo = mapTo$$1;
-
- /**
- * Represents all of the notifications from the source Observable as `next`
- * emissions marked with their original types within {@link Notification}
- * objects.
- *
- * <span class="informal">Wraps `next`, `error` and `complete` emissions in
- * {@link Notification} objects, emitted as `next` on the output Observable.
- * </span>
- *
- * <img src="./img/materialize.png" width="100%">
- *
- * `materialize` returns an Observable that emits a `next` notification for each
- * `next`, `error`, or `complete` emission of the source Observable. When the
- * source Observable emits `complete`, the output Observable will emit `next` as
- * a Notification of type "complete", and then it will emit `complete` as well.
- * When the source Observable emits `error`, the output will emit `next` as a
- * Notification of type "error", and then `complete`.
- *
- * This operator is useful for producing metadata of the source Observable, to
- * be consumed as `next` emissions. Use it in conjunction with
- * {@link dematerialize}.
- *
- * @example <caption>Convert a faulty Observable to an Observable of Notifications</caption>
- * var letters = Rx.Observable.of('a', 'b', 13, 'd');
- * var upperCase = letters.map(x => x.toUpperCase());
- * var materialized = upperCase.materialize();
- * materialized.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // - Notification {kind: "N", value: "A", error: undefined, hasValue: true}
- * // - Notification {kind: "N", value: "B", error: undefined, hasValue: true}
- * // - Notification {kind: "E", value: undefined, error: TypeError:
- * // x.toUpperCase is not a function at MapSubscriber.letters.map.x
- * // [as project] (http://1…, hasValue: false}
- *
- * @see {@link Notification}
- * @see {@link dematerialize}
- *
- * @return {Observable<Notification<T>>} An Observable that emits
- * {@link Notification} objects that wrap the original emissions from the source
- * Observable with metadata.
- * @method materialize
- * @owner Observable
- */
- function materialize$1() {
- return function materializeOperatorFunction(source) {
- return source.lift(new MaterializeOperator());
- };
- }
- var MaterializeOperator = (function () {
- function MaterializeOperator() {
- }
- MaterializeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new MaterializeSubscriber(subscriber));
- };
- return MaterializeOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var MaterializeSubscriber = (function (_super) {
- __extends(MaterializeSubscriber, _super);
- function MaterializeSubscriber(destination) {
- _super.call(this, destination);
- }
- MaterializeSubscriber.prototype._next = function (value) {
- this.destination.next(Notification.createNext(value));
- };
- MaterializeSubscriber.prototype._error = function (err) {
- var destination = this.destination;
- destination.next(Notification.createError(err));
- destination.complete();
- };
- MaterializeSubscriber.prototype._complete = function () {
- var destination = this.destination;
- destination.next(Notification.createComplete());
- destination.complete();
- };
- return MaterializeSubscriber;
- }(Subscriber));
-
- /**
- * Represents all of the notifications from the source Observable as `next`
- * emissions marked with their original types within {@link Notification}
- * objects.
- *
- * <span class="informal">Wraps `next`, `error` and `complete` emissions in
- * {@link Notification} objects, emitted as `next` on the output Observable.
- * </span>
- *
- * <img src="./img/materialize.png" width="100%">
- *
- * `materialize` returns an Observable that emits a `next` notification for each
- * `next`, `error`, or `complete` emission of the source Observable. When the
- * source Observable emits `complete`, the output Observable will emit `next` as
- * a Notification of type "complete", and then it will emit `complete` as well.
- * When the source Observable emits `error`, the output will emit `next` as a
- * Notification of type "error", and then `complete`.
- *
- * This operator is useful for producing metadata of the source Observable, to
- * be consumed as `next` emissions. Use it in conjunction with
- * {@link dematerialize}.
- *
- * @example <caption>Convert a faulty Observable to an Observable of Notifications</caption>
- * var letters = Rx.Observable.of('a', 'b', 13, 'd');
- * var upperCase = letters.map(x => x.toUpperCase());
- * var materialized = upperCase.materialize();
- * materialized.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // - Notification {kind: "N", value: "A", error: undefined, hasValue: true}
- * // - Notification {kind: "N", value: "B", error: undefined, hasValue: true}
- * // - Notification {kind: "E", value: undefined, error: TypeError:
- * // x.toUpperCase is not a function at MapSubscriber.letters.map.x
- * // [as project] (http://1…, hasValue: false}
- *
- * @see {@link Notification}
- * @see {@link dematerialize}
- *
- * @return {Observable<Notification<T>>} An Observable that emits
- * {@link Notification} objects that wrap the original emissions from the source
- * Observable with metadata.
- * @method materialize
- * @owner Observable
- */
- function materialize$$1() {
- return materialize$1()(this);
- }
-
- Observable.prototype.materialize = materialize$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Applies an accumulator function over the source Observable, and returns each
- * intermediate result, with an optional seed value.
- *
- * <span class="informal">It's like {@link reduce}, but emits the current
- * accumulation whenever the source emits a value.</span>
- *
- * <img src="./img/scan.png" width="100%">
- *
- * Combines together all values emitted on the source, using an accumulator
- * function that knows how to join a new source value into the accumulation from
- * the past. Is similar to {@link reduce}, but emits the intermediate
- * accumulations.
- *
- * Returns an Observable that applies a specified `accumulator` function to each
- * item emitted by the source Observable. If a `seed` value is specified, then
- * that value will be used as the initial value for the accumulator. If no seed
- * value is specified, the first item of the source is used as the seed.
- *
- * @example <caption>Count the number of click events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var ones = clicks.mapTo(1);
- * var seed = 0;
- * var count = ones.scan((acc, one) => acc + one, seed);
- * count.subscribe(x => console.log(x));
- *
- * @see {@link expand}
- * @see {@link mergeScan}
- * @see {@link reduce}
- *
- * @param {function(acc: R, value: T, index: number): R} accumulator
- * The accumulator function called on each source value.
- * @param {T|R} [seed] The initial accumulation value.
- * @return {Observable<R>} An observable of the accumulated values.
- * @method scan
- * @owner Observable
- */
- function scan(accumulator, seed) {
- var hasSeed = false;
- // providing a seed of `undefined` *should* be valid and trigger
- // hasSeed! so don't use `seed !== undefined` checks!
- // For this reason, we have to check it here at the original call site
- // otherwise inside Operator/Subscriber we won't know if `undefined`
- // means they didn't provide anything or if they literally provided `undefined`
- if (arguments.length >= 2) {
- hasSeed = true;
- }
- return function scanOperatorFunction(source) {
- return source.lift(new ScanOperator(accumulator, seed, hasSeed));
- };
- }
- var ScanOperator = (function () {
- function ScanOperator(accumulator, seed, hasSeed) {
- if (hasSeed === void 0) { hasSeed = false; }
- this.accumulator = accumulator;
- this.seed = seed;
- this.hasSeed = hasSeed;
- }
- ScanOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
- };
- return ScanOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ScanSubscriber = (function (_super) {
- __extends(ScanSubscriber, _super);
- function ScanSubscriber(destination, accumulator, _seed, hasSeed) {
- _super.call(this, destination);
- this.accumulator = accumulator;
- this._seed = _seed;
- this.hasSeed = hasSeed;
- this.index = 0;
- }
- Object.defineProperty(ScanSubscriber.prototype, "seed", {
- get: function () {
- return this._seed;
- },
- set: function (value) {
- this.hasSeed = true;
- this._seed = value;
- },
- enumerable: true,
- configurable: true
- });
- ScanSubscriber.prototype._next = function (value) {
- if (!this.hasSeed) {
- this.seed = value;
- this.destination.next(value);
- }
- else {
- return this._tryNext(value);
- }
- };
- ScanSubscriber.prototype._tryNext = function (value) {
- var index = this.index++;
- var result;
- try {
- result = this.accumulator(this.seed, value, index);
- }
- catch (err) {
- this.destination.error(err);
- }
- this.seed = result;
- this.destination.next(result);
- };
- return ScanSubscriber;
- }(Subscriber));
-
- /**
- * Emits only the last `count` values emitted by the source Observable.
- *
- * <span class="informal">Remembers the latest `count` values, then emits those
- * only when the source completes.</span>
- *
- * <img src="./img/takeLast.png" width="100%">
- *
- * `takeLast` returns an Observable that emits at most the last `count` values
- * emitted by the source Observable. If the source emits fewer than `count`
- * values then all of its values are emitted. This operator must wait until the
- * `complete` notification emission from the source in order to emit the `next`
- * values on the output Observable, because otherwise it is impossible to know
- * whether or not more values will be emitted on the source. For this reason,
- * all values are emitted synchronously, followed by the complete notification.
- *
- * @example <caption>Take the last 3 values of an Observable with many values</caption>
- * var many = Rx.Observable.range(1, 100);
- * var lastThree = many.takeLast(3);
- * lastThree.subscribe(x => console.log(x));
- *
- * @see {@link take}
- * @see {@link takeUntil}
- * @see {@link takeWhile}
- * @see {@link skip}
- *
- * @throws {ArgumentOutOfRangeError} When using `takeLast(i)`, it delivers an
- * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
- *
- * @param {number} count The maximum number of values to emit from the end of
- * the sequence of values emitted by the source Observable.
- * @return {Observable<T>} An Observable that emits at most the last count
- * values emitted by the source Observable.
- * @method takeLast
- * @owner Observable
- */
- function takeLast(count) {
- return function takeLastOperatorFunction(source) {
- if (count === 0) {
- return new EmptyObservable();
- }
- else {
- return source.lift(new TakeLastOperator(count));
- }
- };
- }
- var TakeLastOperator = (function () {
- function TakeLastOperator(total) {
- this.total = total;
- if (this.total < 0) {
- throw new ArgumentOutOfRangeError;
- }
- }
- TakeLastOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
- };
- return TakeLastOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TakeLastSubscriber = (function (_super) {
- __extends(TakeLastSubscriber, _super);
- function TakeLastSubscriber(destination, total) {
- _super.call(this, destination);
- this.total = total;
- this.ring = new Array();
- this.count = 0;
- }
- TakeLastSubscriber.prototype._next = function (value) {
- var ring = this.ring;
- var total = this.total;
- var count = this.count++;
- if (ring.length < total) {
- ring.push(value);
- }
- else {
- var index = count % total;
- ring[index] = value;
- }
- };
- TakeLastSubscriber.prototype._complete = function () {
- var destination = this.destination;
- var count = this.count;
- if (count > 0) {
- var total = this.count >= this.total ? this.total : this.count;
- var ring = this.ring;
- for (var i = 0; i < total; i++) {
- var idx = (count++) % total;
- destination.next(ring[idx]);
- }
- }
- destination.complete();
- };
- return TakeLastSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Applies an accumulator function over the source Observable, and returns the
- * accumulated result when the source completes, given an optional seed value.
- *
- * <span class="informal">Combines together all values emitted on the source,
- * using an accumulator function that knows how to join a new source value into
- * the accumulation from the past.</span>
- *
- * <img src="./img/reduce.png" width="100%">
- *
- * Like
- * [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce),
- * `reduce` applies an `accumulator` function against an accumulation and each
- * value of the source Observable (from the past) to reduce it to a single
- * value, emitted on the output Observable. Note that `reduce` will only emit
- * one value, only when the source Observable completes. It is equivalent to
- * applying operator {@link scan} followed by operator {@link last}.
- *
- * Returns an Observable that applies a specified `accumulator` function to each
- * item emitted by the source Observable. If a `seed` value is specified, then
- * that value will be used as the initial value for the accumulator. If no seed
- * value is specified, the first item of the source is used as the seed.
- *
- * @example <caption>Count the number of click events that happened in 5 seconds</caption>
- * var clicksInFiveSeconds = Rx.Observable.fromEvent(document, 'click')
- * .takeUntil(Rx.Observable.interval(5000));
- * var ones = clicksInFiveSeconds.mapTo(1);
- * var seed = 0;
- * var count = ones.reduce((acc, one) => acc + one, seed);
- * count.subscribe(x => console.log(x));
- *
- * @see {@link count}
- * @see {@link expand}
- * @see {@link mergeScan}
- * @see {@link scan}
- *
- * @param {function(acc: R, value: T, index: number): R} accumulator The accumulator function
- * called on each source value.
- * @param {R} [seed] The initial accumulation value.
- * @return {Observable<R>} An Observable that emits a single value that is the
- * result of accumulating the values emitted by the source Observable.
- * @method reduce
- * @owner Observable
- */
- function reduce(accumulator, seed) {
- // providing a seed of `undefined` *should* be valid and trigger
- // hasSeed! so don't use `seed !== undefined` checks!
- // For this reason, we have to check it here at the original call site
- // otherwise inside Operator/Subscriber we won't know if `undefined`
- // means they didn't provide anything or if they literally provided `undefined`
- if (arguments.length >= 2) {
- return function reduceOperatorFunctionWithSeed(source) {
- return pipe(scan(accumulator, seed), takeLast(1), defaultIfEmpty$1(seed))(source);
- };
- }
- return function reduceOperatorFunction(source) {
- return pipe(scan(function (acc, value, index) {
- return accumulator(acc, value, index + 1);
- }), takeLast(1))(source);
- };
- }
-
- /**
- * The Max operator operates on an Observable that emits numbers (or items that can be compared with a provided function),
- * and when source Observable completes it emits a single item: the item with the largest value.
- *
- * <img src="./img/max.png" width="100%">
- *
- * @example <caption>Get the maximal value of a series of numbers</caption>
- * Rx.Observable.of(5, 4, 7, 2, 8)
- * .max()
- * .subscribe(x => console.log(x)); // -> 8
- *
- * @example <caption>Use a comparer function to get the maximal item</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- * Observable.of<Person>({age: 7, name: 'Foo'},
- * {age: 5, name: 'Bar'},
- * {age: 9, name: 'Beer'})
- * .max<Person>((a: Person, b: Person) => a.age < b.age ? -1 : 1)
- * .subscribe((x: Person) => console.log(x.name)); // -> 'Beer'
- * }
- *
- * @see {@link min}
- *
- * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the
- * value of two items.
- * @return {Observable} An Observable that emits item with the largest value.
- * @method max
- * @owner Observable
- */
- function max$1(comparer) {
- var max = (typeof comparer === 'function')
- ? function (x, y) { return comparer(x, y) > 0 ? x : y; }
- : function (x, y) { return x > y ? x : y; };
- return reduce(max);
- }
-
- /**
- * The Max operator operates on an Observable that emits numbers (or items that can be compared with a provided function),
- * and when source Observable completes it emits a single item: the item with the largest value.
- *
- * <img src="./img/max.png" width="100%">
- *
- * @example <caption>Get the maximal value of a series of numbers</caption>
- * Rx.Observable.of(5, 4, 7, 2, 8)
- * .max()
- * .subscribe(x => console.log(x)); // -> 8
- *
- * @example <caption>Use a comparer function to get the maximal item</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- * Observable.of<Person>({age: 7, name: 'Foo'},
- * {age: 5, name: 'Bar'},
- * {age: 9, name: 'Beer'})
- * .max<Person>((a: Person, b: Person) => a.age < b.age ? -1 : 1)
- * .subscribe((x: Person) => console.log(x.name)); // -> 'Beer'
- * }
- *
- * @see {@link min}
- *
- * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the
- * value of two items.
- * @return {Observable} An Observable that emits item with the largest value.
- * @method max
- * @owner Observable
- */
- function max$$1(comparer) {
- return max$1(comparer)(this);
- }
-
- Observable.prototype.max = max$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Creates an output Observable which concurrently emits all values from every
- * given input Observable.
- *
- * <span class="informal">Flattens multiple Observables together by blending
- * their values into one Observable.</span>
- *
- * <img src="./img/merge.png" width="100%">
- *
- * `merge` subscribes to each given input Observable (either the source or an
- * Observable given as argument), and simply forwards (without doing any
- * transformation) all the values from all the input Observables to the output
- * Observable. The output Observable only completes once all input Observables
- * have completed. Any error delivered by an input Observable will be immediately
- * emitted on the output Observable.
- *
- * @example <caption>Merge together two Observables: 1s interval and clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var timer = Rx.Observable.interval(1000);
- * var clicksOrTimer = clicks.merge(timer);
- * clicksOrTimer.subscribe(x => console.log(x));
- *
- * @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
- * var timer1 = Rx.Observable.interval(1000).take(10);
- * var timer2 = Rx.Observable.interval(2000).take(6);
- * var timer3 = Rx.Observable.interval(500).take(10);
- * var concurrent = 2; // the argument
- * var merged = timer1.merge(timer2, timer3, concurrent);
- * merged.subscribe(x => console.log(x));
- *
- * @see {@link mergeAll}
- * @see {@link mergeMap}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- *
- * @param {ObservableInput} other An input Observable to merge with the source
- * Observable. More than one input Observables may be given as argument.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @param {Scheduler} [scheduler=null] The IScheduler to use for managing
- * concurrency of input Observables.
- * @return {Observable} An Observable that emits items that are the result of
- * every input Observable.
- * @method merge
- * @owner Observable
- */
- function merge$2() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return function (source) { return source.lift.call(merge.apply(void 0, [source].concat(observables))); };
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Creates an output Observable which concurrently emits all values from every
- * given input Observable.
- *
- * <span class="informal">Flattens multiple Observables together by blending
- * their values into one Observable.</span>
- *
- * <img src="./img/merge.png" width="100%">
- *
- * `merge` subscribes to each given input Observable (either the source or an
- * Observable given as argument), and simply forwards (without doing any
- * transformation) all the values from all the input Observables to the output
- * Observable. The output Observable only completes once all input Observables
- * have completed. Any error delivered by an input Observable will be immediately
- * emitted on the output Observable.
- *
- * @example <caption>Merge together two Observables: 1s interval and clicks</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var timer = Rx.Observable.interval(1000);
- * var clicksOrTimer = clicks.merge(timer);
- * clicksOrTimer.subscribe(x => console.log(x));
- *
- * @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
- * var timer1 = Rx.Observable.interval(1000).take(10);
- * var timer2 = Rx.Observable.interval(2000).take(6);
- * var timer3 = Rx.Observable.interval(500).take(10);
- * var concurrent = 2; // the argument
- * var merged = timer1.merge(timer2, timer3, concurrent);
- * merged.subscribe(x => console.log(x));
- *
- * @see {@link mergeAll}
- * @see {@link mergeMap}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- *
- * @param {ObservableInput} other An input Observable to merge with the source
- * Observable. More than one input Observables may be given as argument.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @param {Scheduler} [scheduler=null] The IScheduler to use for managing
- * concurrency of input Observables.
- * @return {Observable} An Observable that emits items that are the result of
- * every input Observable.
- * @method merge
- * @owner Observable
- */
- function merge$1() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return merge$2.apply(void 0, observables)(this);
- }
-
- Observable.prototype.merge = merge$1;
-
- /**
- * Converts a higher-order Observable into a first-order Observable which
- * concurrently delivers all values that are emitted on the inner Observables.
- *
- * <span class="informal">Flattens an Observable-of-Observables.</span>
- *
- * <img src="./img/mergeAll.png" width="100%">
- *
- * `mergeAll` subscribes to an Observable that emits Observables, also known as
- * a higher-order Observable. Each time it observes one of these emitted inner
- * Observables, it subscribes to that and delivers all the values from the
- * inner Observable on the output Observable. The output Observable only
- * completes once all inner Observables have completed. Any error delivered by
- * a inner Observable will be immediately emitted on the output Observable.
- *
- * @example <caption>Spawn a new interval Observable for each click event, and blend their outputs as one Observable</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000));
- * var firstOrder = higherOrder.mergeAll();
- * firstOrder.subscribe(x => console.log(x));
- *
- * @example <caption>Count from 0 to 9 every second for each click, but only allow 2 concurrent timers</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(10));
- * var firstOrder = higherOrder.mergeAll(2);
- * firstOrder.subscribe(x => console.log(x));
- *
- * @see {@link combineAll}
- * @see {@link concatAll}
- * @see {@link exhaust}
- * @see {@link merge}
- * @see {@link mergeMap}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- * @see {@link switch}
- * @see {@link zipAll}
- *
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of inner
- * Observables being subscribed to concurrently.
- * @return {Observable} An Observable that emits values coming from all the
- * inner Observables emitted by the source Observable.
- * @method mergeAll
- * @owner Observable
- */
- function mergeAll$1(concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return mergeAll(concurrent)(this);
- }
-
- Observable.prototype.mergeAll = mergeAll$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link mergeAll}.</span>
- *
- * <img src="./img/mergeMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an Observable, and then merging those resulting Observables and
- * emitting the results of this merger.
- *
- * @example <caption>Map and flatten each letter to an Observable ticking every 1 second</caption>
- * var letters = Rx.Observable.of('a', 'b', 'c');
- * var result = letters.mergeMap(x =>
- * Rx.Observable.interval(1000).map(i => x+i)
- * );
- * result.subscribe(x => console.log(x));
- *
- * // Results in the following:
- * // a0
- * // b0
- * // c0
- * // a1
- * // b1
- * // c1
- * // continues to list a,b,c with respective ascending integers
- *
- * @see {@link concatMap}
- * @see {@link exhaustMap}
- * @see {@link merge}
- * @see {@link mergeAll}
- * @see {@link mergeMapTo}
- * @see {@link mergeScan}
- * @see {@link switchMap}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @return {Observable} An Observable that emits the result of applying the
- * projection function (and the optional `resultSelector`) to each item emitted
- * by the source Observable and merging the results of the Observables obtained
- * from this transformation.
- * @method mergeMap
- * @owner Observable
- */
- function mergeMap$1(project, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return mergeMap(project, resultSelector, concurrent)(this);
- }
-
- Observable.prototype.mergeMap = mergeMap$1;
- Observable.prototype.flatMap = mergeMap$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to the same Observable which is merged multiple
- * times in the output Observable.
- *
- * <span class="informal">It's like {@link mergeMap}, but maps each value always
- * to the same inner Observable.</span>
- *
- * <img src="./img/mergeMapTo.png" width="100%">
- *
- * Maps each source value to the given Observable `innerObservable` regardless
- * of the source value, and then merges those resulting Observables into one
- * single Observable, which is the output Observable.
- *
- * @example <caption>For each click event, start an interval Observable ticking every 1 second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.mergeMapTo(Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMapTo}
- * @see {@link merge}
- * @see {@link mergeAll}
- * @see {@link mergeMap}
- * @see {@link mergeScan}
- * @see {@link switchMapTo}
- *
- * @param {ObservableInput} innerObservable An Observable to replace each value from
- * the source Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @return {Observable} An Observable that emits items from the given
- * `innerObservable` (and optionally transformed through `resultSelector`) every
- * time a value is emitted on the source Observable.
- * @method mergeMapTo
- * @owner Observable
- */
- function mergeMapTo$1(innerObservable, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- if (typeof resultSelector === 'number') {
- concurrent = resultSelector;
- resultSelector = null;
- }
- return function (source) { return source.lift(new MergeMapToOperator(innerObservable, resultSelector, concurrent)); };
- }
- // TODO: Figure out correct signature here: an Operator<Observable<T>, R>
- // needs to implement call(observer: Subscriber<R>): Subscriber<Observable<T>>
- var MergeMapToOperator = (function () {
- function MergeMapToOperator(ish, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- this.ish = ish;
- this.resultSelector = resultSelector;
- this.concurrent = concurrent;
- }
- MergeMapToOperator.prototype.call = function (observer, source) {
- return source.subscribe(new MergeMapToSubscriber(observer, this.ish, this.resultSelector, this.concurrent));
- };
- return MergeMapToOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var MergeMapToSubscriber = (function (_super) {
- __extends(MergeMapToSubscriber, _super);
- function MergeMapToSubscriber(destination, ish, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- _super.call(this, destination);
- this.ish = ish;
- this.resultSelector = resultSelector;
- this.concurrent = concurrent;
- this.hasCompleted = false;
- this.buffer = [];
- this.active = 0;
- this.index = 0;
- }
- MergeMapToSubscriber.prototype._next = function (value) {
- if (this.active < this.concurrent) {
- var resultSelector = this.resultSelector;
- var index = this.index++;
- var ish = this.ish;
- var destination = this.destination;
- this.active++;
- this._innerSub(ish, destination, resultSelector, value, index);
- }
- else {
- this.buffer.push(value);
- }
- };
- MergeMapToSubscriber.prototype._innerSub = function (ish, destination, resultSelector, value, index) {
- this.add(subscribeToResult(this, ish, value, index));
- };
- MergeMapToSubscriber.prototype._complete = function () {
- this.hasCompleted = true;
- if (this.active === 0 && this.buffer.length === 0) {
- this.destination.complete();
- }
- };
- MergeMapToSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
- if (resultSelector) {
- this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex);
- }
- else {
- destination.next(innerValue);
- }
- };
- MergeMapToSubscriber.prototype.trySelectResult = function (outerValue, innerValue, outerIndex, innerIndex) {
- var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
- var result;
- try {
- result = resultSelector(outerValue, innerValue, outerIndex, innerIndex);
- }
- catch (err) {
- destination.error(err);
- return;
- }
- destination.next(result);
- };
- MergeMapToSubscriber.prototype.notifyError = function (err) {
- this.destination.error(err);
- };
- MergeMapToSubscriber.prototype.notifyComplete = function (innerSub) {
- var buffer = this.buffer;
- this.remove(innerSub);
- this.active--;
- if (buffer.length > 0) {
- this._next(buffer.shift());
- }
- else if (this.active === 0 && this.hasCompleted) {
- this.destination.complete();
- }
- };
- return MergeMapToSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to the same Observable which is merged multiple
- * times in the output Observable.
- *
- * <span class="informal">It's like {@link mergeMap}, but maps each value always
- * to the same inner Observable.</span>
- *
- * <img src="./img/mergeMapTo.png" width="100%">
- *
- * Maps each source value to the given Observable `innerObservable` regardless
- * of the source value, and then merges those resulting Observables into one
- * single Observable, which is the output Observable.
- *
- * @example <caption>For each click event, start an interval Observable ticking every 1 second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.mergeMapTo(Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMapTo}
- * @see {@link merge}
- * @see {@link mergeAll}
- * @see {@link mergeMap}
- * @see {@link mergeScan}
- * @see {@link switchMapTo}
- *
- * @param {ObservableInput} innerObservable An Observable to replace each value from
- * the source Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
- * Observables being subscribed to concurrently.
- * @return {Observable} An Observable that emits items from the given
- * `innerObservable` (and optionally transformed through `resultSelector`) every
- * time a value is emitted on the source Observable.
- * @method mergeMapTo
- * @owner Observable
- */
- function mergeMapTo$$1(innerObservable, resultSelector, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return mergeMapTo$1(innerObservable, resultSelector, concurrent)(this);
- }
-
- Observable.prototype.flatMapTo = mergeMapTo$$1;
- Observable.prototype.mergeMapTo = mergeMapTo$$1;
-
- /**
- * Applies an accumulator function over the source Observable where the
- * accumulator function itself returns an Observable, then each intermediate
- * Observable returned is merged into the output Observable.
- *
- * <span class="informal">It's like {@link scan}, but the Observables returned
- * by the accumulator are merged into the outer Observable.</span>
- *
- * @example <caption>Count the number of click events</caption>
- * const click$ = Rx.Observable.fromEvent(document, 'click');
- * const one$ = click$.mapTo(1);
- * const seed = 0;
- * const count$ = one$.mergeScan((acc, one) => Rx.Observable.of(acc + one), seed);
- * count$.subscribe(x => console.log(x));
- *
- * // Results:
- * 1
- * 2
- * 3
- * 4
- * // ...and so on for each click
- *
- * @param {function(acc: R, value: T): Observable<R>} accumulator
- * The accumulator function called on each source value.
- * @param seed The initial accumulation value.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of
- * input Observables being subscribed to concurrently.
- * @return {Observable<R>} An observable of the accumulated values.
- * @method mergeScan
- * @owner Observable
- */
- function mergeScan$1(accumulator, seed, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
- }
- var MergeScanOperator = (function () {
- function MergeScanOperator(accumulator, seed, concurrent) {
- this.accumulator = accumulator;
- this.seed = seed;
- this.concurrent = concurrent;
- }
- MergeScanOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
- };
- return MergeScanOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var MergeScanSubscriber = (function (_super) {
- __extends(MergeScanSubscriber, _super);
- function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
- _super.call(this, destination);
- this.accumulator = accumulator;
- this.acc = acc;
- this.concurrent = concurrent;
- this.hasValue = false;
- this.hasCompleted = false;
- this.buffer = [];
- this.active = 0;
- this.index = 0;
- }
- MergeScanSubscriber.prototype._next = function (value) {
- if (this.active < this.concurrent) {
- var index = this.index++;
- var ish = tryCatch(this.accumulator)(this.acc, value);
- var destination = this.destination;
- if (ish === errorObject) {
- destination.error(errorObject.e);
- }
- else {
- this.active++;
- this._innerSub(ish, value, index);
- }
- }
- else {
- this.buffer.push(value);
- }
- };
- MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
- this.add(subscribeToResult(this, ish, value, index));
- };
- MergeScanSubscriber.prototype._complete = function () {
- this.hasCompleted = true;
- if (this.active === 0 && this.buffer.length === 0) {
- if (this.hasValue === false) {
- this.destination.next(this.acc);
- }
- this.destination.complete();
- }
- };
- MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var destination = this.destination;
- this.acc = innerValue;
- this.hasValue = true;
- destination.next(innerValue);
- };
- MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
- var buffer = this.buffer;
- this.remove(innerSub);
- this.active--;
- if (buffer.length > 0) {
- this._next(buffer.shift());
- }
- else if (this.active === 0 && this.hasCompleted) {
- if (this.hasValue === false) {
- this.destination.next(this.acc);
- }
- this.destination.complete();
- }
- };
- return MergeScanSubscriber;
- }(OuterSubscriber));
-
- /**
- * Applies an accumulator function over the source Observable where the
- * accumulator function itself returns an Observable, then each intermediate
- * Observable returned is merged into the output Observable.
- *
- * <span class="informal">It's like {@link scan}, but the Observables returned
- * by the accumulator are merged into the outer Observable.</span>
- *
- * @example <caption>Count the number of click events</caption>
- * const click$ = Rx.Observable.fromEvent(document, 'click');
- * const one$ = click$.mapTo(1);
- * const seed = 0;
- * const count$ = one$.mergeScan((acc, one) => Rx.Observable.of(acc + one), seed);
- * count$.subscribe(x => console.log(x));
- *
- * // Results:
- * 1
- * 2
- * 3
- * 4
- * // ...and so on for each click
- *
- * @param {function(acc: R, value: T): Observable<R>} accumulator
- * The accumulator function called on each source value.
- * @param seed The initial accumulation value.
- * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of
- * input Observables being subscribed to concurrently.
- * @return {Observable<R>} An observable of the accumulated values.
- * @method mergeScan
- * @owner Observable
- */
- function mergeScan$$1(accumulator, seed, concurrent) {
- if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
- return mergeScan$1(accumulator, seed, concurrent)(this);
- }
-
- Observable.prototype.mergeScan = mergeScan$$1;
-
- /**
- * The Min operator operates on an Observable that emits numbers (or items that can be compared with a provided function),
- * and when source Observable completes it emits a single item: the item with the smallest value.
- *
- * <img src="./img/min.png" width="100%">
- *
- * @example <caption>Get the minimal value of a series of numbers</caption>
- * Rx.Observable.of(5, 4, 7, 2, 8)
- * .min()
- * .subscribe(x => console.log(x)); // -> 2
- *
- * @example <caption>Use a comparer function to get the minimal item</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- * Observable.of<Person>({age: 7, name: 'Foo'},
- * {age: 5, name: 'Bar'},
- * {age: 9, name: 'Beer'})
- * .min<Person>( (a: Person, b: Person) => a.age < b.age ? -1 : 1)
- * .subscribe((x: Person) => console.log(x.name)); // -> 'Bar'
- * }
- *
- * @see {@link max}
- *
- * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the
- * value of two items.
- * @return {Observable<R>} An Observable that emits item with the smallest value.
- * @method min
- * @owner Observable
- */
- function min$1(comparer) {
- var min = (typeof comparer === 'function')
- ? function (x, y) { return comparer(x, y) < 0 ? x : y; }
- : function (x, y) { return x < y ? x : y; };
- return reduce(min);
- }
-
- /**
- * The Min operator operates on an Observable that emits numbers (or items that can be compared with a provided function),
- * and when source Observable completes it emits a single item: the item with the smallest value.
- *
- * <img src="./img/min.png" width="100%">
- *
- * @example <caption>Get the minimal value of a series of numbers</caption>
- * Rx.Observable.of(5, 4, 7, 2, 8)
- * .min()
- * .subscribe(x => console.log(x)); // -> 2
- *
- * @example <caption>Use a comparer function to get the minimal item</caption>
- * interface Person {
- * age: number,
- * name: string
- * }
- * Observable.of<Person>({age: 7, name: 'Foo'},
- * {age: 5, name: 'Bar'},
- * {age: 9, name: 'Beer'})
- * .min<Person>( (a: Person, b: Person) => a.age < b.age ? -1 : 1)
- * .subscribe((x: Person) => console.log(x.name)); // -> 'Bar'
- * }
- *
- * @see {@link max}
- *
- * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the
- * value of two items.
- * @return {Observable<R>} An Observable that emits item with the smallest value.
- * @method min
- * @owner Observable
- */
- function min$$1(comparer) {
- return min$1(comparer)(this);
- }
-
- Observable.prototype.min = min$$1;
-
- function refCount() {
- return function refCountOperatorFunction(source) {
- return source.lift(new RefCountOperator$1(source));
- };
- }
- var RefCountOperator$1 = (function () {
- function RefCountOperator(connectable) {
- this.connectable = connectable;
- }
- RefCountOperator.prototype.call = function (subscriber, source) {
- var connectable = this.connectable;
- connectable._refCount++;
- var refCounter = new RefCountSubscriber$1(subscriber, connectable);
- var subscription = source.subscribe(refCounter);
- if (!refCounter.closed) {
- refCounter.connection = connectable.connect();
- }
- return subscription;
- };
- return RefCountOperator;
- }());
- var RefCountSubscriber$1 = (function (_super) {
- __extends(RefCountSubscriber, _super);
- function RefCountSubscriber(destination, connectable) {
- _super.call(this, destination);
- this.connectable = connectable;
- }
- /** @deprecated internal use only */ RefCountSubscriber.prototype._unsubscribe = function () {
- var connectable = this.connectable;
- if (!connectable) {
- this.connection = null;
- return;
- }
- this.connectable = null;
- var refCount = connectable._refCount;
- if (refCount <= 0) {
- this.connection = null;
- return;
- }
- connectable._refCount = refCount - 1;
- if (refCount > 1) {
- this.connection = null;
- return;
- }
- ///
- // Compare the local RefCountSubscriber's connection Subscription to the
- // connection Subscription on the shared ConnectableObservable. In cases
- // where the ConnectableObservable source synchronously emits values, and
- // the RefCountSubscriber's downstream Observers synchronously unsubscribe,
- // execution continues to here before the RefCountOperator has a chance to
- // supply the RefCountSubscriber with the shared connection Subscription.
- // For example:
- // ```
- // Observable.range(0, 10)
- // .publish()
- // .refCount()
- // .take(5)
- // .subscribe();
- // ```
- // In order to account for this case, RefCountSubscriber should only dispose
- // the ConnectableObservable's shared connection Subscription if the
- // connection Subscription exists, *and* either:
- // a. RefCountSubscriber doesn't have a reference to the shared connection
- // Subscription yet, or,
- // b. RefCountSubscriber's connection Subscription reference is identical
- // to the shared connection Subscription
- ///
- var connection = this.connection;
- var sharedConnection = connectable._connection;
- this.connection = null;
- if (sharedConnection && (!connection || sharedConnection === connection)) {
- sharedConnection.unsubscribe();
- }
- };
- return RefCountSubscriber;
- }(Subscriber));
-
- /**
- * @class ConnectableObservable<T>
- */
- var ConnectableObservable = (function (_super) {
- __extends(ConnectableObservable, _super);
- function ConnectableObservable(/** @deprecated internal use only */ source,
- /** @deprecated internal use only */ subjectFactory) {
- _super.call(this);
- this.source = source;
- this.subjectFactory = subjectFactory;
- /** @deprecated internal use only */ this._refCount = 0;
- this._isComplete = false;
- }
- /** @deprecated internal use only */ ConnectableObservable.prototype._subscribe = function (subscriber) {
- return this.getSubject().subscribe(subscriber);
- };
- /** @deprecated internal use only */ ConnectableObservable.prototype.getSubject = function () {
- var subject = this._subject;
- if (!subject || subject.isStopped) {
- this._subject = this.subjectFactory();
- }
- return this._subject;
- };
- ConnectableObservable.prototype.connect = function () {
- var connection = this._connection;
- if (!connection) {
- this._isComplete = false;
- connection = this._connection = new Subscription();
- connection.add(this.source
- .subscribe(new ConnectableSubscriber(this.getSubject(), this)));
- if (connection.closed) {
- this._connection = null;
- connection = Subscription.EMPTY;
- }
- else {
- this._connection = connection;
- }
- }
- return connection;
- };
- ConnectableObservable.prototype.refCount = function () {
- return refCount()(this);
- };
- return ConnectableObservable;
- }(Observable));
- var connectableProto = ConnectableObservable.prototype;
- var connectableObservableDescriptor = {
- operator: { value: null },
- _refCount: { value: 0, writable: true },
- _subject: { value: null, writable: true },
- _connection: { value: null, writable: true },
- _subscribe: { value: connectableProto._subscribe },
- _isComplete: { value: connectableProto._isComplete, writable: true },
- getSubject: { value: connectableProto.getSubject },
- connect: { value: connectableProto.connect },
- refCount: { value: connectableProto.refCount }
- };
- var ConnectableSubscriber = (function (_super) {
- __extends(ConnectableSubscriber, _super);
- function ConnectableSubscriber(destination, connectable) {
- _super.call(this, destination);
- this.connectable = connectable;
- }
- ConnectableSubscriber.prototype._error = function (err) {
- this._unsubscribe();
- _super.prototype._error.call(this, err);
- };
- ConnectableSubscriber.prototype._complete = function () {
- this.connectable._isComplete = true;
- this._unsubscribe();
- _super.prototype._complete.call(this);
- };
- /** @deprecated internal use only */ ConnectableSubscriber.prototype._unsubscribe = function () {
- var connectable = this.connectable;
- if (connectable) {
- this.connectable = null;
- var connection = connectable._connection;
- connectable._refCount = 0;
- connectable._subject = null;
- connectable._connection = null;
- if (connection) {
- connection.unsubscribe();
- }
- }
- };
- return ConnectableSubscriber;
- }(SubjectSubscriber));
- var RefCountSubscriber = (function (_super) {
- __extends(RefCountSubscriber, _super);
- function RefCountSubscriber(destination, connectable) {
- _super.call(this, destination);
- this.connectable = connectable;
- }
- /** @deprecated internal use only */ RefCountSubscriber.prototype._unsubscribe = function () {
- var connectable = this.connectable;
- if (!connectable) {
- this.connection = null;
- return;
- }
- this.connectable = null;
- var refCount$$1 = connectable._refCount;
- if (refCount$$1 <= 0) {
- this.connection = null;
- return;
- }
- connectable._refCount = refCount$$1 - 1;
- if (refCount$$1 > 1) {
- this.connection = null;
- return;
- }
- ///
- // Compare the local RefCountSubscriber's connection Subscription to the
- // connection Subscription on the shared ConnectableObservable. In cases
- // where the ConnectableObservable source synchronously emits values, and
- // the RefCountSubscriber's downstream Observers synchronously unsubscribe,
- // execution continues to here before the RefCountOperator has a chance to
- // supply the RefCountSubscriber with the shared connection Subscription.
- // For example:
- // ```
- // Observable.range(0, 10)
- // .publish()
- // .refCount()
- // .take(5)
- // .subscribe();
- // ```
- // In order to account for this case, RefCountSubscriber should only dispose
- // the ConnectableObservable's shared connection Subscription if the
- // connection Subscription exists, *and* either:
- // a. RefCountSubscriber doesn't have a reference to the shared connection
- // Subscription yet, or,
- // b. RefCountSubscriber's connection Subscription reference is identical
- // to the shared connection Subscription
- ///
- var connection = this.connection;
- var sharedConnection = connectable._connection;
- this.connection = null;
- if (sharedConnection && (!connection || sharedConnection === connection)) {
- sharedConnection.unsubscribe();
- }
- };
- return RefCountSubscriber;
- }(Subscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits the results of invoking a specified selector on items
- * emitted by a ConnectableObservable that shares a single subscription to the underlying stream.
- *
- * <img src="./img/multicast.png" width="100%">
- *
- * @param {Function|Subject} subjectOrSubjectFactory - Factory function to create an intermediate subject through
- * which the source sequence's elements will be multicast to the selector function
- * or Subject to push source elements into.
- * @param {Function} [selector] - Optional selector function that can use the multicasted source stream
- * as many times as needed, without causing multiple subscriptions to the source stream.
- * Subscribers to the given source will receive all notifications of the source from the
- * time of the subscription forward.
- * @return {Observable} An Observable that emits the results of invoking the selector
- * on the items emitted by a `ConnectableObservable` that shares a single subscription to
- * the underlying stream.
- * @method multicast
- * @owner Observable
- */
- function multicast$1(subjectOrSubjectFactory, selector) {
- return function multicastOperatorFunction(source) {
- var subjectFactory;
- if (typeof subjectOrSubjectFactory === 'function') {
- subjectFactory = subjectOrSubjectFactory;
- }
- else {
- subjectFactory = function subjectFactory() {
- return subjectOrSubjectFactory;
- };
- }
- if (typeof selector === 'function') {
- return source.lift(new MulticastOperator(subjectFactory, selector));
- }
- var connectable = Object.create(source, connectableObservableDescriptor);
- connectable.source = source;
- connectable.subjectFactory = subjectFactory;
- return connectable;
- };
- }
- var MulticastOperator = (function () {
- function MulticastOperator(subjectFactory, selector) {
- this.subjectFactory = subjectFactory;
- this.selector = selector;
- }
- MulticastOperator.prototype.call = function (subscriber, source) {
- var selector = this.selector;
- var subject = this.subjectFactory();
- var subscription = selector(subject).subscribe(subscriber);
- subscription.add(source.subscribe(subject));
- return subscription;
- };
- return MulticastOperator;
- }());
-
- /* tslint:enable:max-line-length */
- /**
- * Allows source Observable to be subscribed only once with a Subject of choice,
- * while still sharing its values between multiple subscribers.
- *
- * <span class="informal">Subscribe to Observable once, but send its values to multiple subscribers.</span>
- *
- * <img src="./img/multicast.png" width="100%">
- *
- * `multicast` is an operator that works in two modes.
- *
- * In the first mode you provide a single argument to it, which can be either an initialized Subject or a Subject
- * factory. As a result you will get a special kind of an Observable - a {@link ConnectableObservable}. It can be
- * subscribed multiple times, just as regular Observable, but it won't subscribe to the source Observable at that
- * moment. It will do it only if you call its `connect` method. This means you can essentially control by hand, when
- * source Observable will be actually subscribed. What is more, ConnectableObservable will share this one subscription
- * between all of its subscribers. This means that, for example, `ajax` Observable will only send a request once,
- * even though usually it would send a request per every subscriber. Since it sends a request at the moment of
- * subscription, here request would be sent when the `connect` method of a ConnectableObservable is called.
- *
- * The most common pattern of using ConnectableObservable is calling `connect` when the first consumer subscribes,
- * keeping the subscription alive while several consumers come and go and finally unsubscribing from the source
- * Observable, when the last consumer unsubscribes. To not implement that logic over and over again,
- * ConnectableObservable has a special operator, `refCount`. When called, it returns an Observable, which will count
- * the number of consumers subscribed to it and keep ConnectableObservable connected as long as there is at least
- * one consumer. So if you don't actually need to decide yourself when to connect and disconnect a
- * ConnectableObservable, use `refCount`.
- *
- * The second mode is invoked by calling `multicast` with an additional, second argument - selector function.
- * This function accepts an Observable - which basically mirrors the source Observable - and returns Observable
- * as well, which should be the input stream modified by any operators you want. Note that in this
- * mode you cannot provide initialized Subject as a first argument - it has to be a Subject factory. If
- * you provide selector function, `multicast` returns just a regular Observable, instead of ConnectableObservable.
- * Thus, as usual, each subscription to this stream triggers subscription to the source Observable. However,
- * if inside the selector function you subscribe to the input Observable multiple times, actual source stream
- * will be subscribed only once. So if you have a chain of operators that use some Observable many times,
- * but you want to subscribe to that Observable only once, this is the mode you would use.
- *
- * Subject provided as a first parameter of `multicast` is used as a proxy for the single subscription to the
- * source Observable. It means that all values from the source stream go through that Subject. Thus, if a Subject
- * has some special properties, Observable returned by `multicast` will have them as well. If you want to use
- * `multicast` with a Subject that is one of the ones included in RxJS by default - {@link Subject},
- * {@link AsyncSubject}, {@link BehaviorSubject}, or {@link ReplaySubject} - simply use {@link publish},
- * {@link publishLast}, {@link publishBehavior} or {@link publishReplay} respectively. These are actually
- * just wrappers around `multicast`, with a specific Subject hardcoded inside.
- *
- * Also, if you use {@link publish} or {@link publishReplay} with a ConnectableObservables `refCount` operator,
- * you can simply use {@link share} and {@link shareReplay} respectively, which chain these two.
- *
- * @example <caption>Use ConnectableObservable</caption>
- * const seconds = Rx.Observable.interval(1000);
- * const connectableSeconds = seconds.multicast(new Subject());
- *
- * connectableSeconds.subscribe(value => console.log('first: ' + value));
- * connectableSeconds.subscribe(value => console.log('second: ' + value));
- *
- * // At this point still nothing happens, even though we subscribed twice.
- *
- * connectableSeconds.connect();
- *
- * // From now on `seconds` are being logged to the console,
- * // twice per every second. `seconds` Observable was however only subscribed once,
- * // so under the hood Observable.interval had only one clock started.
- *
- * @example <caption>Use selector</caption>
- * const seconds = Rx.Observable.interval(1000);
- *
- * seconds
- * .multicast(
- * () => new Subject(),
- * seconds => seconds.zip(seconds) // Usually zip would subscribe to `seconds` twice.
- * // Because we are inside selector, `seconds` is subscribed once,
- * ) // thus starting only one clock used internally by Observable.interval.
- * .subscribe();
- *
- * @see {@link publish}
- * @see {@link publishLast}
- * @see {@link publishBehavior}
- * @see {@link publishReplay}
- * @see {@link share}
- * @see {@link shareReplay}
- *
- * @param {Function|Subject} subjectOrSubjectFactory - Factory function to create an intermediate Subject through
- * which the source sequence's elements will be multicast to the selector function input Observable or
- * ConnectableObservable returned by the operator.
- * @param {Function} [selector] - Optional selector function that can use the input stream
- * as many times as needed, without causing multiple subscriptions to the source stream.
- * Subscribers to the input source will receive all notifications of the source from the
- * time of the subscription forward.
- * @return {Observable<T>|ConnectableObservable<T>} An Observable that emits the results of invoking the selector
- * on the source stream or a special {@link ConnectableObservable}, if selector was not provided.
- *
- * @method multicast
- * @owner Observable
- */
- function multicast$$1(subjectOrSubjectFactory, selector) {
- return multicast$1(subjectOrSubjectFactory, selector)(this);
- }
-
- Observable.prototype.multicast = multicast$$1;
-
- /**
- *
- * Re-emits all notifications from source Observable with specified scheduler.
- *
- * <span class="informal">Ensure a specific scheduler is used, from outside of an Observable.</span>
- *
- * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule
- * notifications emitted by the source Observable. It might be useful, if you do not have control over
- * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.
- *
- * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,
- * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal
- * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits
- * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.
- * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split
- * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source
- * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a
- * little bit more, to ensure that they are emitted at expected moments.
- *
- * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications
- * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`
- * will delay all notifications - including error notifications - while `delay` will pass through error
- * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator
- * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used
- * for notification emissions in general.
- *
- * @example <caption>Ensure values in subscribe are called just before browser repaint.</caption>
- * const intervals = Rx.Observable.interval(10); // Intervals are scheduled
- * // with async scheduler by default...
- *
- * intervals
- * .observeOn(Rx.Scheduler.animationFrame) // ...but we will observe on animationFrame
- * .subscribe(val => { // scheduler to ensure smooth animation.
- * someDiv.style.height = val + 'px';
- * });
- *
- * @see {@link delay}
- *
- * @param {IScheduler} scheduler Scheduler that will be used to reschedule notifications from source Observable.
- * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.
- * @return {Observable<T>} Observable that emits the same notifications as the source Observable,
- * but with provided scheduler.
- *
- * @method observeOn
- * @owner Observable
- */
- function observeOn$1(scheduler, delay) {
- if (delay === void 0) { delay = 0; }
- return observeOn(scheduler, delay)(this);
- }
-
- Observable.prototype.observeOn = observeOn$1;
-
- /* tslint:enable:max-line-length */
- /**
- * When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one
- * that was passed.
- *
- * <span class="informal">Execute series of Observables no matter what, even if it means swallowing errors.</span>
- *
- * <img src="./img/onErrorResumeNext.png" width="100%">
- *
- * `onErrorResumeNext` is an operator that accepts a series of Observables, provided either directly as
- * arguments or as an array. If no single Observable is provided, returned Observable will simply behave the same
- * as the source.
- *
- * `onErrorResumeNext` returns an Observable that starts by subscribing and re-emitting values from the source Observable.
- * When its stream of values ends - no matter if Observable completed or emitted an error - `onErrorResumeNext`
- * will subscribe to the first Observable that was passed as an argument to the method. It will start re-emitting
- * its values as well and - again - when that stream ends, `onErrorResumeNext` will proceed to subscribing yet another
- * Observable in provided series, no matter if previous Observable completed or ended with an error. This will
- * be happening until there is no more Observables left in the series, at which point returned Observable will
- * complete - even if the last subscribed stream ended with an error.
- *
- * `onErrorResumeNext` can be therefore thought of as version of {@link concat} operator, which is more permissive
- * when it comes to the errors emitted by its input Observables. While `concat` subscribes to the next Observable
- * in series only if previous one successfully completed, `onErrorResumeNext` subscribes even if it ended with
- * an error.
- *
- * Note that you do not get any access to errors emitted by the Observables. In particular do not
- * expect these errors to appear in error callback passed to {@link subscribe}. If you want to take
- * specific actions based on what error was emitted by an Observable, you should try out {@link catch} instead.
- *
- *
- * @example <caption>Subscribe to the next Observable after map fails</caption>
- * Rx.Observable.of(1, 2, 3, 0)
- * .map(x => {
- * if (x === 0) { throw Error(); }
- return 10 / x;
- * })
- * .onErrorResumeNext(Rx.Observable.of(1, 2, 3))
- * .subscribe(
- * val => console.log(val),
- * err => console.log(err), // Will never be called.
- * () => console.log('that\'s it!')
- * );
- *
- * // Logs:
- * // 10
- * // 5
- * // 3.3333333333333335
- * // 1
- * // 2
- * // 3
- * // "that's it!"
- *
- * @see {@link concat}
- * @see {@link catch}
- *
- * @param {...ObservableInput} observables Observables passed either directly or as an array.
- * @return {Observable} An Observable that emits values from source Observable, but - if it errors - subscribes
- * to the next passed Observable and so on, until it completes or runs out of Observables.
- * @method onErrorResumeNext
- * @owner Observable
- */
- function onErrorResumeNext$2() {
- var nextSources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nextSources[_i - 0] = arguments[_i];
- }
- return onErrorResumeNext$1.apply(void 0, nextSources)(this);
- }
-
- Observable.prototype.onErrorResumeNext = onErrorResumeNext$2;
-
- /**
- * Groups pairs of consecutive emissions together and emits them as an array of
- * two values.
- *
- * <span class="informal">Puts the current value and previous value together as
- * an array, and emits that.</span>
- *
- * <img src="./img/pairwise.png" width="100%">
- *
- * The Nth emission from the source Observable will cause the output Observable
- * to emit an array [(N-1)th, Nth] of the previous and the current value, as a
- * pair. For this reason, `pairwise` emits on the second and subsequent
- * emissions from the source Observable, but not on the first emission, because
- * there is no previous value in that case.
- *
- * @example <caption>On every click (starting from the second), emit the relative distance to the previous click</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var pairs = clicks.pairwise();
- * var distance = pairs.map(pair => {
- * var x0 = pair[0].clientX;
- * var y0 = pair[0].clientY;
- * var x1 = pair[1].clientX;
- * var y1 = pair[1].clientY;
- * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
- * });
- * distance.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- *
- * @return {Observable<Array<T>>} An Observable of pairs (as arrays) of
- * consecutive values from the source Observable.
- * @method pairwise
- * @owner Observable
- */
- function pairwise$1() {
- return function (source) { return source.lift(new PairwiseOperator()); };
- }
- var PairwiseOperator = (function () {
- function PairwiseOperator() {
- }
- PairwiseOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new PairwiseSubscriber(subscriber));
- };
- return PairwiseOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var PairwiseSubscriber = (function (_super) {
- __extends(PairwiseSubscriber, _super);
- function PairwiseSubscriber(destination) {
- _super.call(this, destination);
- this.hasPrev = false;
- }
- PairwiseSubscriber.prototype._next = function (value) {
- if (this.hasPrev) {
- this.destination.next([this.prev, value]);
- }
- else {
- this.hasPrev = true;
- }
- this.prev = value;
- };
- return PairwiseSubscriber;
- }(Subscriber));
-
- /**
- * Groups pairs of consecutive emissions together and emits them as an array of
- * two values.
- *
- * <span class="informal">Puts the current value and previous value together as
- * an array, and emits that.</span>
- *
- * <img src="./img/pairwise.png" width="100%">
- *
- * The Nth emission from the source Observable will cause the output Observable
- * to emit an array [(N-1)th, Nth] of the previous and the current value, as a
- * pair. For this reason, `pairwise` emits on the second and subsequent
- * emissions from the source Observable, but not on the first emission, because
- * there is no previous value in that case.
- *
- * @example <caption>On every click (starting from the second), emit the relative distance to the previous click</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var pairs = clicks.pairwise();
- * var distance = pairs.map(pair => {
- * var x0 = pair[0].clientX;
- * var y0 = pair[0].clientY;
- * var x1 = pair[1].clientX;
- * var y1 = pair[1].clientY;
- * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
- * });
- * distance.subscribe(x => console.log(x));
- *
- * @see {@link buffer}
- * @see {@link bufferCount}
- *
- * @return {Observable<Array<T>>} An Observable of pairs (as arrays) of
- * consecutive values from the source Observable.
- * @method pairwise
- * @owner Observable
- */
- function pairwise$$1() {
- return pairwise$1()(this);
- }
-
- Observable.prototype.pairwise = pairwise$$1;
-
- function not(pred, thisArg) {
- function notPred() {
- return !(notPred.pred.apply(notPred.thisArg, arguments));
- }
- notPred.pred = pred;
- notPred.thisArg = thisArg;
- return notPred;
- }
-
- /**
- * Splits the source Observable into two, one with values that satisfy a
- * predicate, and another with values that don't satisfy the predicate.
- *
- * <span class="informal">It's like {@link filter}, but returns two Observables:
- * one like the output of {@link filter}, and the other with values that did not
- * pass the condition.</span>
- *
- * <img src="./img/partition.png" width="100%">
- *
- * `partition` outputs an array with two Observables that partition the values
- * from the source Observable through the given `predicate` function. The first
- * Observable in that array emits source values for which the predicate argument
- * returns true. The second Observable emits source values for which the
- * predicate returns false. The first behaves like {@link filter} and the second
- * behaves like {@link filter} with the predicate negated.
- *
- * @example <caption>Partition click events into those on DIV elements and those elsewhere</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var parts = clicks.partition(ev => ev.target.tagName === 'DIV');
- * var clicksOnDivs = parts[0];
- * var clicksElsewhere = parts[1];
- * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x));
- * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x));
- *
- * @see {@link filter}
- *
- * @param {function(value: T, index: number): boolean} predicate A function that
- * evaluates each value emitted by the source Observable. If it returns `true`,
- * the value is emitted on the first Observable in the returned array, if
- * `false` the value is emitted on the second Observable in the array. The
- * `index` parameter is the number `i` for the i-th source emission that has
- * happened since the subscription, starting from the number `0`.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {[Observable<T>, Observable<T>]} An array with two Observables: one
- * with values that passed the predicate, and another with values that did not
- * pass the predicate.
- * @method partition
- * @owner Observable
- */
- function partition$1(predicate, thisArg) {
- return function (source) { return [
- filter$1(predicate, thisArg)(source),
- filter$1(not(predicate, thisArg))(source)
- ]; };
- }
-
- /**
- * Splits the source Observable into two, one with values that satisfy a
- * predicate, and another with values that don't satisfy the predicate.
- *
- * <span class="informal">It's like {@link filter}, but returns two Observables:
- * one like the output of {@link filter}, and the other with values that did not
- * pass the condition.</span>
- *
- * <img src="./img/partition.png" width="100%">
- *
- * `partition` outputs an array with two Observables that partition the values
- * from the source Observable through the given `predicate` function. The first
- * Observable in that array emits source values for which the predicate argument
- * returns true. The second Observable emits source values for which the
- * predicate returns false. The first behaves like {@link filter} and the second
- * behaves like {@link filter} with the predicate negated.
- *
- * @example <caption>Partition click events into those on DIV elements and those elsewhere</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var parts = clicks.partition(ev => ev.target.tagName === 'DIV');
- * var clicksOnDivs = parts[0];
- * var clicksElsewhere = parts[1];
- * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x));
- * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x));
- *
- * @see {@link filter}
- *
- * @param {function(value: T, index: number): boolean} predicate A function that
- * evaluates each value emitted by the source Observable. If it returns `true`,
- * the value is emitted on the first Observable in the returned array, if
- * `false` the value is emitted on the second Observable in the array. The
- * `index` parameter is the number `i` for the i-th source emission that has
- * happened since the subscription, starting from the number `0`.
- * @param {any} [thisArg] An optional argument to determine the value of `this`
- * in the `predicate` function.
- * @return {[Observable<T>, Observable<T>]} An array with two Observables: one
- * with values that passed the predicate, and another with values that did not
- * pass the predicate.
- * @method partition
- * @owner Observable
- */
- function partition$$1(predicate, thisArg) {
- return partition$1(predicate, thisArg)(this);
- }
-
- Observable.prototype.partition = partition$$1;
-
- /**
- * Maps each source value (an object) to its specified nested property.
- *
- * <span class="informal">Like {@link map}, but meant only for picking one of
- * the nested properties of every emitted object.</span>
- *
- * <img src="./img/pluck.png" width="100%">
- *
- * Given a list of strings describing a path to an object property, retrieves
- * the value of a specified nested property from all values in the source
- * Observable. If a property can't be resolved, it will return `undefined` for
- * that value.
- *
- * @example <caption>Map every click to the tagName of the clicked target element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var tagNames = clicks.pluck('target', 'tagName');
- * tagNames.subscribe(x => console.log(x));
- *
- * @see {@link map}
- *
- * @param {...string} properties The nested properties to pluck from each source
- * value (an object).
- * @return {Observable} A new Observable of property values from the source values.
- * @method pluck
- * @owner Observable
- */
- function pluck$1() {
- var properties = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- properties[_i - 0] = arguments[_i];
- }
- var length = properties.length;
- if (length === 0) {
- throw new Error('list of properties cannot be empty.');
- }
- return function (source) { return map(plucker(properties, length))(source); };
- }
- function plucker(props, length) {
- var mapper = function (x) {
- var currentProp = x;
- for (var i = 0; i < length; i++) {
- var p = currentProp[props[i]];
- if (typeof p !== 'undefined') {
- currentProp = p;
- }
- else {
- return undefined;
- }
- }
- return currentProp;
- };
- return mapper;
- }
-
- /**
- * Maps each source value (an object) to its specified nested property.
- *
- * <span class="informal">Like {@link map}, but meant only for picking one of
- * the nested properties of every emitted object.</span>
- *
- * <img src="./img/pluck.png" width="100%">
- *
- * Given a list of strings describing a path to an object property, retrieves
- * the value of a specified nested property from all values in the source
- * Observable. If a property can't be resolved, it will return `undefined` for
- * that value.
- *
- * @example <caption>Map every click to the tagName of the clicked target element</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var tagNames = clicks.pluck('target', 'tagName');
- * tagNames.subscribe(x => console.log(x));
- *
- * @see {@link map}
- *
- * @param {...string} properties The nested properties to pluck from each source
- * value (an object).
- * @return {Observable} A new Observable of property values from the source values.
- * @method pluck
- * @owner Observable
- */
- function pluck$$1() {
- var properties = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- properties[_i - 0] = arguments[_i];
- }
- return pluck$1.apply(void 0, properties)(this);
- }
-
- Observable.prototype.pluck = pluck$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Returns a ConnectableObservable, which is a variety of Observable that waits until its connect method is called
- * before it begins emitting items to those Observers that have subscribed to it.
- *
- * <img src="./img/publish.png" width="100%">
- *
- * @param {Function} [selector] - Optional selector function which can use the multicasted source sequence as many times
- * as needed, without causing multiple subscriptions to the source sequence.
- * Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
- * @return A ConnectableObservable that upon connection causes the source Observable to emit items to its Observers.
- * @method publish
- * @owner Observable
- */
- function publish$1(selector) {
- return selector ?
- multicast$1(function () { return new Subject(); }, selector) :
- multicast$1(new Subject());
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Returns a ConnectableObservable, which is a variety of Observable that waits until its connect method is called
- * before it begins emitting items to those Observers that have subscribed to it.
- *
- * <img src="./img/publish.png" width="100%">
- *
- * @param {Function} [selector] - Optional selector function which can use the multicasted source sequence as many times
- * as needed, without causing multiple subscriptions to the source sequence.
- * Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
- * @return A ConnectableObservable that upon connection causes the source Observable to emit items to its Observers.
- * @method publish
- * @owner Observable
- */
- function publish$$1(selector) {
- return publish$1(selector)(this);
- }
-
- Observable.prototype.publish = publish$$1;
-
- /**
- * @class BehaviorSubject<T>
- */
- var BehaviorSubject = (function (_super) {
- __extends(BehaviorSubject, _super);
- function BehaviorSubject(_value) {
- _super.call(this);
- this._value = _value;
- }
- Object.defineProperty(BehaviorSubject.prototype, "value", {
- get: function () {
- return this.getValue();
- },
- enumerable: true,
- configurable: true
- });
- /** @deprecated internal use only */ BehaviorSubject.prototype._subscribe = function (subscriber) {
- var subscription = _super.prototype._subscribe.call(this, subscriber);
- if (subscription && !subscription.closed) {
- subscriber.next(this._value);
- }
- return subscription;
- };
- BehaviorSubject.prototype.getValue = function () {
- if (this.hasError) {
- throw this.thrownError;
- }
- else if (this.closed) {
- throw new ObjectUnsubscribedError();
- }
- else {
- return this._value;
- }
- };
- BehaviorSubject.prototype.next = function (value) {
- _super.prototype.next.call(this, this._value = value);
- };
- return BehaviorSubject;
- }(Subject));
-
- /**
- * @param value
- * @return {ConnectableObservable<T>}
- * @method publishBehavior
- * @owner Observable
- */
- function publishBehavior$1(value) {
- return function (source) { return multicast$1(new BehaviorSubject(value))(source); };
- }
-
- /**
- * @param value
- * @return {ConnectableObservable<T>}
- * @method publishBehavior
- * @owner Observable
- */
- function publishBehavior$$1(value) {
- return publishBehavior$1(value)(this);
- }
-
- Observable.prototype.publishBehavior = publishBehavior$$1;
-
- /* tslint:enable:max-line-length */
- function publishReplay$1(bufferSize, windowTime, selectorOrScheduler, scheduler) {
- if (selectorOrScheduler && typeof selectorOrScheduler !== 'function') {
- scheduler = selectorOrScheduler;
- }
- var selector = typeof selectorOrScheduler === 'function' ? selectorOrScheduler : undefined;
- var subject = new ReplaySubject(bufferSize, windowTime, scheduler);
- return function (source) { return multicast$1(function () { return subject; }, selector)(source); };
- }
-
- /* tslint:enable:max-line-length */
- /**
- * @param bufferSize
- * @param windowTime
- * @param selectorOrScheduler
- * @param scheduler
- * @return {Observable<T> | ConnectableObservable<T>}
- * @method publishReplay
- * @owner Observable
- */
- function publishReplay$$1(bufferSize, windowTime, selectorOrScheduler, scheduler) {
- return publishReplay$1(bufferSize, windowTime, selectorOrScheduler, scheduler)(this);
- }
-
- Observable.prototype.publishReplay = publishReplay$$1;
-
- function publishLast$1() {
- return function (source) { return multicast$1(new AsyncSubject())(source); };
- }
-
- /**
- * @return {ConnectableObservable<T>}
- * @method publishLast
- * @owner Observable
- */
- function publishLast$$1() {
- //TODO(benlesh): correct type-flow through here.
- return publishLast$1()(this);
- }
-
- Observable.prototype.publishLast = publishLast$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that mirrors the first source Observable to emit an item
- * from the combination of this Observable and supplied Observables.
- * @param {...Observables} ...observables Sources used to race for which Observable emits first.
- * @return {Observable} An Observable that mirrors the output of the first Observable to emit an item.
- * @method race
- * @owner Observable
- */
- function race$2() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return function raceOperatorFunction(source) {
- // if the only argument is an array, it was most likely called with
- // `pair([obs1, obs2, ...])`
- if (observables.length === 1 && isArray(observables[0])) {
- observables = observables[0];
- }
- return source.lift.call(race.apply(void 0, [source].concat(observables)));
- };
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that mirrors the first source Observable to emit an item
- * from the combination of this Observable and supplied Observables.
- * @param {...Observables} ...observables Sources used to race for which Observable emits first.
- * @return {Observable} An Observable that mirrors the output of the first Observable to emit an item.
- * @method race
- * @owner Observable
- */
- function race$1() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return race$2.apply(void 0, observables)(this);
- }
-
- Observable.prototype.race = race$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Applies an accumulator function over the source Observable, and returns the
- * accumulated result when the source completes, given an optional seed value.
- *
- * <span class="informal">Combines together all values emitted on the source,
- * using an accumulator function that knows how to join a new source value into
- * the accumulation from the past.</span>
- *
- * <img src="./img/reduce.png" width="100%">
- *
- * Like
- * [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce),
- * `reduce` applies an `accumulator` function against an accumulation and each
- * value of the source Observable (from the past) to reduce it to a single
- * value, emitted on the output Observable. Note that `reduce` will only emit
- * one value, only when the source Observable completes. It is equivalent to
- * applying operator {@link scan} followed by operator {@link last}.
- *
- * Returns an Observable that applies a specified `accumulator` function to each
- * item emitted by the source Observable. If a `seed` value is specified, then
- * that value will be used as the initial value for the accumulator. If no seed
- * value is specified, the first item of the source is used as the seed.
- *
- * @example <caption>Count the number of click events that happened in 5 seconds</caption>
- * var clicksInFiveSeconds = Rx.Observable.fromEvent(document, 'click')
- * .takeUntil(Rx.Observable.interval(5000));
- * var ones = clicksInFiveSeconds.mapTo(1);
- * var seed = 0;
- * var count = ones.reduce((acc, one) => acc + one, seed);
- * count.subscribe(x => console.log(x));
- *
- * @see {@link count}
- * @see {@link expand}
- * @see {@link mergeScan}
- * @see {@link scan}
- *
- * @param {function(acc: R, value: T, index: number): R} accumulator The accumulator function
- * called on each source value.
- * @param {R} [seed] The initial accumulation value.
- * @return {Observable<R>} An Observable that emits a single value that is the
- * result of accumulating the values emitted by the source Observable.
- * @method reduce
- * @owner Observable
- */
- function reduce$1(accumulator, seed) {
- // providing a seed of `undefined` *should* be valid and trigger
- // hasSeed! so don't use `seed !== undefined` checks!
- // For this reason, we have to check it here at the original call site
- // otherwise inside Operator/Subscriber we won't know if `undefined`
- // means they didn't provide anything or if they literally provided `undefined`
- if (arguments.length >= 2) {
- return reduce(accumulator, seed)(this);
- }
- return reduce(accumulator)(this);
- }
-
- Observable.prototype.reduce = reduce$1;
-
- /**
- * Returns an Observable that repeats the stream of items emitted by the source Observable at most count times.
- *
- * <img src="./img/repeat.png" width="100%">
- *
- * @param {number} [count] The number of times the source Observable items are repeated, a count of 0 will yield
- * an empty Observable.
- * @return {Observable} An Observable that repeats the stream of items emitted by the source Observable at most
- * count times.
- * @method repeat
- * @owner Observable
- */
- function repeat$1(count) {
- if (count === void 0) { count = -1; }
- return function (source) {
- if (count === 0) {
- return new EmptyObservable();
- }
- else if (count < 0) {
- return source.lift(new RepeatOperator(-1, source));
- }
- else {
- return source.lift(new RepeatOperator(count - 1, source));
- }
- };
- }
- var RepeatOperator = (function () {
- function RepeatOperator(count, source) {
- this.count = count;
- this.source = source;
- }
- RepeatOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
- };
- return RepeatOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var RepeatSubscriber = (function (_super) {
- __extends(RepeatSubscriber, _super);
- function RepeatSubscriber(destination, count, source) {
- _super.call(this, destination);
- this.count = count;
- this.source = source;
- }
- RepeatSubscriber.prototype.complete = function () {
- if (!this.isStopped) {
- var _a = this, source = _a.source, count = _a.count;
- if (count === 0) {
- return _super.prototype.complete.call(this);
- }
- else if (count > -1) {
- this.count = count - 1;
- }
- source.subscribe(this._unsubscribeAndRecycle());
- }
- };
- return RepeatSubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that repeats the stream of items emitted by the source Observable at most count times.
- *
- * <img src="./img/repeat.png" width="100%">
- *
- * @param {number} [count] The number of times the source Observable items are repeated, a count of 0 will yield
- * an empty Observable.
- * @return {Observable} An Observable that repeats the stream of items emitted by the source Observable at most
- * count times.
- * @method repeat
- * @owner Observable
- */
- function repeat$$1(count) {
- if (count === void 0) { count = -1; }
- return repeat$1(count)(this);
- }
-
- Observable.prototype.repeat = repeat$$1;
-
- /**
- * Returns an Observable that mirrors the source Observable with the exception of a `complete`. If the source
- * Observable calls `complete`, this method will emit to the Observable returned from `notifier`. If that Observable
- * calls `complete` or `error`, then this method will call `complete` or `error` on the child subscription. Otherwise
- * this method will resubscribe to the source Observable.
- *
- * <img src="./img/repeatWhen.png" width="100%">
- *
- * @param {function(notifications: Observable): Observable} notifier - Receives an Observable of notifications with
- * which a user can `complete` or `error`, aborting the repetition.
- * @return {Observable} The source Observable modified with repeat logic.
- * @method repeatWhen
- * @owner Observable
- */
- function repeatWhen$1(notifier) {
- return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
- }
- var RepeatWhenOperator = (function () {
- function RepeatWhenOperator(notifier) {
- this.notifier = notifier;
- }
- RepeatWhenOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
- };
- return RepeatWhenOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var RepeatWhenSubscriber = (function (_super) {
- __extends(RepeatWhenSubscriber, _super);
- function RepeatWhenSubscriber(destination, notifier, source) {
- _super.call(this, destination);
- this.notifier = notifier;
- this.source = source;
- this.sourceIsBeingSubscribedTo = true;
- }
- RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.sourceIsBeingSubscribedTo = true;
- this.source.subscribe(this);
- };
- RepeatWhenSubscriber.prototype.notifyComplete = function (innerSub) {
- if (this.sourceIsBeingSubscribedTo === false) {
- return _super.prototype.complete.call(this);
- }
- };
- RepeatWhenSubscriber.prototype.complete = function () {
- this.sourceIsBeingSubscribedTo = false;
- if (!this.isStopped) {
- if (!this.retries) {
- this.subscribeToRetries();
- }
- if (!this.retriesSubscription || this.retriesSubscription.closed) {
- return _super.prototype.complete.call(this);
- }
- this._unsubscribeAndRecycle();
- this.notifications.next();
- }
- };
- /** @deprecated internal use only */ RepeatWhenSubscriber.prototype._unsubscribe = function () {
- var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
- if (notifications) {
- notifications.unsubscribe();
- this.notifications = null;
- }
- if (retriesSubscription) {
- retriesSubscription.unsubscribe();
- this.retriesSubscription = null;
- }
- this.retries = null;
- };
- /** @deprecated internal use only */ RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
- var _a = this, notifications = _a.notifications, retries = _a.retries, retriesSubscription = _a.retriesSubscription;
- this.notifications = null;
- this.retries = null;
- this.retriesSubscription = null;
- _super.prototype._unsubscribeAndRecycle.call(this);
- this.notifications = notifications;
- this.retries = retries;
- this.retriesSubscription = retriesSubscription;
- return this;
- };
- RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
- this.notifications = new Subject();
- var retries = tryCatch(this.notifier)(this.notifications);
- if (retries === errorObject) {
- return _super.prototype.complete.call(this);
- }
- this.retries = retries;
- this.retriesSubscription = subscribeToResult(this, retries);
- };
- return RepeatWhenSubscriber;
- }(OuterSubscriber));
-
- /**
- * Returns an Observable that mirrors the source Observable with the exception of a `complete`. If the source
- * Observable calls `complete`, this method will emit to the Observable returned from `notifier`. If that Observable
- * calls `complete` or `error`, then this method will call `complete` or `error` on the child subscription. Otherwise
- * this method will resubscribe to the source Observable.
- *
- * <img src="./img/repeatWhen.png" width="100%">
- *
- * @param {function(notifications: Observable): Observable} notifier - Receives an Observable of notifications with
- * which a user can `complete` or `error`, aborting the repetition.
- * @return {Observable} The source Observable modified with repeat logic.
- * @method repeatWhen
- * @owner Observable
- */
- function repeatWhen$$1(notifier) {
- return repeatWhen$1(notifier)(this);
- }
-
- Observable.prototype.repeatWhen = repeatWhen$$1;
-
- /**
- * Returns an Observable that mirrors the source Observable with the exception of an `error`. If the source Observable
- * calls `error`, this method will resubscribe to the source Observable for a maximum of `count` resubscriptions (given
- * as a number parameter) rather than propagating the `error` call.
- *
- * <img src="./img/retry.png" width="100%">
- *
- * Any and all items emitted by the source Observable will be emitted by the resulting Observable, even those emitted
- * during failed subscriptions. For example, if an Observable fails at first but emits [1, 2] then succeeds the second
- * time and emits: [1, 2, 3, 4, 5] then the complete stream of emissions and notifications
- * would be: [1, 2, 1, 2, 3, 4, 5, `complete`].
- * @param {number} count - Number of retry attempts before failing.
- * @return {Observable} The source Observable modified with the retry logic.
- * @method retry
- * @owner Observable
- */
- function retry$1(count) {
- if (count === void 0) { count = -1; }
- return function (source) { return source.lift(new RetryOperator(count, source)); };
- }
- var RetryOperator = (function () {
- function RetryOperator(count, source) {
- this.count = count;
- this.source = source;
- }
- RetryOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
- };
- return RetryOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var RetrySubscriber = (function (_super) {
- __extends(RetrySubscriber, _super);
- function RetrySubscriber(destination, count, source) {
- _super.call(this, destination);
- this.count = count;
- this.source = source;
- }
- RetrySubscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- var _a = this, source = _a.source, count = _a.count;
- if (count === 0) {
- return _super.prototype.error.call(this, err);
- }
- else if (count > -1) {
- this.count = count - 1;
- }
- source.subscribe(this._unsubscribeAndRecycle());
- }
- };
- return RetrySubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that mirrors the source Observable with the exception of an `error`. If the source Observable
- * calls `error`, this method will resubscribe to the source Observable for a maximum of `count` resubscriptions (given
- * as a number parameter) rather than propagating the `error` call.
- *
- * <img src="./img/retry.png" width="100%">
- *
- * Any and all items emitted by the source Observable will be emitted by the resulting Observable, even those emitted
- * during failed subscriptions. For example, if an Observable fails at first but emits [1, 2] then succeeds the second
- * time and emits: [1, 2, 3, 4, 5] then the complete stream of emissions and notifications
- * would be: [1, 2, 1, 2, 3, 4, 5, `complete`].
- * @param {number} count - Number of retry attempts before failing.
- * @return {Observable} The source Observable modified with the retry logic.
- * @method retry
- * @owner Observable
- */
- function retry$$1(count) {
- if (count === void 0) { count = -1; }
- return retry$1(count)(this);
- }
-
- Observable.prototype.retry = retry$$1;
-
- /**
- * Returns an Observable that mirrors the source Observable with the exception of an `error`. If the source Observable
- * calls `error`, this method will emit the Throwable that caused the error to the Observable returned from `notifier`.
- * If that Observable calls `complete` or `error` then this method will call `complete` or `error` on the child
- * subscription. Otherwise this method will resubscribe to the source Observable.
- *
- * <img src="./img/retryWhen.png" width="100%">
- *
- * @param {function(errors: Observable): Observable} notifier - Receives an Observable of notifications with which a
- * user can `complete` or `error`, aborting the retry.
- * @return {Observable} The source Observable modified with retry logic.
- * @method retryWhen
- * @owner Observable
- */
- function retryWhen$1(notifier) {
- return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
- }
- var RetryWhenOperator = (function () {
- function RetryWhenOperator(notifier, source) {
- this.notifier = notifier;
- this.source = source;
- }
- RetryWhenOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
- };
- return RetryWhenOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var RetryWhenSubscriber = (function (_super) {
- __extends(RetryWhenSubscriber, _super);
- function RetryWhenSubscriber(destination, notifier, source) {
- _super.call(this, destination);
- this.notifier = notifier;
- this.source = source;
- }
- RetryWhenSubscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- var errors = this.errors;
- var retries = this.retries;
- var retriesSubscription = this.retriesSubscription;
- if (!retries) {
- errors = new Subject();
- retries = tryCatch(this.notifier)(errors);
- if (retries === errorObject) {
- return _super.prototype.error.call(this, errorObject.e);
- }
- retriesSubscription = subscribeToResult(this, retries);
- }
- else {
- this.errors = null;
- this.retriesSubscription = null;
- }
- this._unsubscribeAndRecycle();
- this.errors = errors;
- this.retries = retries;
- this.retriesSubscription = retriesSubscription;
- errors.next(err);
- }
- };
- /** @deprecated internal use only */ RetryWhenSubscriber.prototype._unsubscribe = function () {
- var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
- if (errors) {
- errors.unsubscribe();
- this.errors = null;
- }
- if (retriesSubscription) {
- retriesSubscription.unsubscribe();
- this.retriesSubscription = null;
- }
- this.retries = null;
- };
- RetryWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var _a = this, errors = _a.errors, retries = _a.retries, retriesSubscription = _a.retriesSubscription;
- this.errors = null;
- this.retries = null;
- this.retriesSubscription = null;
- this._unsubscribeAndRecycle();
- this.errors = errors;
- this.retries = retries;
- this.retriesSubscription = retriesSubscription;
- this.source.subscribe(this);
- };
- return RetryWhenSubscriber;
- }(OuterSubscriber));
-
- /**
- * Returns an Observable that mirrors the source Observable with the exception of an `error`. If the source Observable
- * calls `error`, this method will emit the Throwable that caused the error to the Observable returned from `notifier`.
- * If that Observable calls `complete` or `error` then this method will call `complete` or `error` on the child
- * subscription. Otherwise this method will resubscribe to the source Observable.
- *
- * <img src="./img/retryWhen.png" width="100%">
- *
- * @param {function(errors: Observable): Observable} notifier - Receives an Observable of notifications with which a
- * user can `complete` or `error`, aborting the retry.
- * @return {Observable} The source Observable modified with retry logic.
- * @method retryWhen
- * @owner Observable
- */
- function retryWhen$$1(notifier) {
- return retryWhen$1(notifier)(this);
- }
-
- Observable.prototype.retryWhen = retryWhen$$1;
-
- /**
- * Emits the most recently emitted value from the source Observable whenever
- * another Observable, the `notifier`, emits.
- *
- * <span class="informal">It's like {@link sampleTime}, but samples whenever
- * the `notifier` Observable emits something.</span>
- *
- * <img src="./img/sample.png" width="100%">
- *
- * Whenever the `notifier` Observable emits a value or completes, `sample`
- * looks at the source Observable and emits whichever value it has most recently
- * emitted since the previous sampling, unless the source has not emitted
- * anything since the previous sampling. The `notifier` is subscribed to as soon
- * as the output Observable is subscribed.
- *
- * @example <caption>On every click, sample the most recent "seconds" timer</caption>
- * var seconds = Rx.Observable.interval(1000);
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = seconds.sample(clicks);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounce}
- * @see {@link sampleTime}
- * @see {@link throttle}
- *
- * @param {Observable<any>} notifier The Observable to use for sampling the
- * source Observable.
- * @return {Observable<T>} An Observable that emits the results of sampling the
- * values emitted by the source Observable whenever the notifier Observable
- * emits value or completes.
- * @method sample
- * @owner Observable
- */
- function sample$1(notifier) {
- return function (source) { return source.lift(new SampleOperator(notifier)); };
- }
- var SampleOperator = (function () {
- function SampleOperator(notifier) {
- this.notifier = notifier;
- }
- SampleOperator.prototype.call = function (subscriber, source) {
- var sampleSubscriber = new SampleSubscriber(subscriber);
- var subscription = source.subscribe(sampleSubscriber);
- subscription.add(subscribeToResult(sampleSubscriber, this.notifier));
- return subscription;
- };
- return SampleOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SampleSubscriber = (function (_super) {
- __extends(SampleSubscriber, _super);
- function SampleSubscriber() {
- _super.apply(this, arguments);
- this.hasValue = false;
- }
- SampleSubscriber.prototype._next = function (value) {
- this.value = value;
- this.hasValue = true;
- };
- SampleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.emitValue();
- };
- SampleSubscriber.prototype.notifyComplete = function () {
- this.emitValue();
- };
- SampleSubscriber.prototype.emitValue = function () {
- if (this.hasValue) {
- this.hasValue = false;
- this.destination.next(this.value);
- }
- };
- return SampleSubscriber;
- }(OuterSubscriber));
-
- /**
- * Emits the most recently emitted value from the source Observable whenever
- * another Observable, the `notifier`, emits.
- *
- * <span class="informal">It's like {@link sampleTime}, but samples whenever
- * the `notifier` Observable emits something.</span>
- *
- * <img src="./img/sample.png" width="100%">
- *
- * Whenever the `notifier` Observable emits a value or completes, `sample`
- * looks at the source Observable and emits whichever value it has most recently
- * emitted since the previous sampling, unless the source has not emitted
- * anything since the previous sampling. The `notifier` is subscribed to as soon
- * as the output Observable is subscribed.
- *
- * @example <caption>On every click, sample the most recent "seconds" timer</caption>
- * var seconds = Rx.Observable.interval(1000);
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = seconds.sample(clicks);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounce}
- * @see {@link sampleTime}
- * @see {@link throttle}
- *
- * @param {Observable<any>} notifier The Observable to use for sampling the
- * source Observable.
- * @return {Observable<T>} An Observable that emits the results of sampling the
- * values emitted by the source Observable whenever the notifier Observable
- * emits value or completes.
- * @method sample
- * @owner Observable
- */
- function sample$$1(notifier) {
- return sample$1(notifier)(this);
- }
-
- Observable.prototype.sample = sample$$1;
-
- /**
- * Emits the most recently emitted value from the source Observable within
- * periodic time intervals.
- *
- * <span class="informal">Samples the source Observable at periodic time
- * intervals, emitting what it samples.</span>
- *
- * <img src="./img/sampleTime.png" width="100%">
- *
- * `sampleTime` periodically looks at the source Observable and emits whichever
- * value it has most recently emitted since the previous sampling, unless the
- * source has not emitted anything since the previous sampling. The sampling
- * happens periodically in time every `period` milliseconds (or the time unit
- * defined by the optional `scheduler` argument). The sampling starts as soon as
- * the output Observable is subscribed.
- *
- * @example <caption>Every second, emit the most recent click at most once</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.sampleTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounceTime}
- * @see {@link delay}
- * @see {@link sample}
- * @see {@link throttleTime}
- *
- * @param {number} period The sampling period expressed in milliseconds or the
- * time unit determined internally by the optional `scheduler`.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the sampling.
- * @return {Observable<T>} An Observable that emits the results of sampling the
- * values emitted by the source Observable at the specified time interval.
- * @method sampleTime
- * @owner Observable
- */
- function sampleTime$1(period, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return function (source) { return source.lift(new SampleTimeOperator(period, scheduler)); };
- }
- var SampleTimeOperator = (function () {
- function SampleTimeOperator(period, scheduler) {
- this.period = period;
- this.scheduler = scheduler;
- }
- SampleTimeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
- };
- return SampleTimeOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SampleTimeSubscriber = (function (_super) {
- __extends(SampleTimeSubscriber, _super);
- function SampleTimeSubscriber(destination, period, scheduler) {
- _super.call(this, destination);
- this.period = period;
- this.scheduler = scheduler;
- this.hasValue = false;
- this.add(scheduler.schedule(dispatchNotification, period, { subscriber: this, period: period }));
- }
- SampleTimeSubscriber.prototype._next = function (value) {
- this.lastValue = value;
- this.hasValue = true;
- };
- SampleTimeSubscriber.prototype.notifyNext = function () {
- if (this.hasValue) {
- this.hasValue = false;
- this.destination.next(this.lastValue);
- }
- };
- return SampleTimeSubscriber;
- }(Subscriber));
- function dispatchNotification(state) {
- var subscriber = state.subscriber, period = state.period;
- subscriber.notifyNext();
- this.schedule(state, period);
- }
-
- /**
- * Emits the most recently emitted value from the source Observable within
- * periodic time intervals.
- *
- * <span class="informal">Samples the source Observable at periodic time
- * intervals, emitting what it samples.</span>
- *
- * <img src="./img/sampleTime.png" width="100%">
- *
- * `sampleTime` periodically looks at the source Observable and emits whichever
- * value it has most recently emitted since the previous sampling, unless the
- * source has not emitted anything since the previous sampling. The sampling
- * happens periodically in time every `period` milliseconds (or the time unit
- * defined by the optional `scheduler` argument). The sampling starts as soon as
- * the output Observable is subscribed.
- *
- * @example <caption>Every second, emit the most recent click at most once</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.sampleTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounceTime}
- * @see {@link delay}
- * @see {@link sample}
- * @see {@link throttleTime}
- *
- * @param {number} period The sampling period expressed in milliseconds or the
- * time unit determined internally by the optional `scheduler`.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the sampling.
- * @return {Observable<T>} An Observable that emits the results of sampling the
- * values emitted by the source Observable at the specified time interval.
- * @method sampleTime
- * @owner Observable
- */
- function sampleTime$$1(period, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return sampleTime$1(period, scheduler)(this);
- }
-
- Observable.prototype.sampleTime = sampleTime$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Applies an accumulator function over the source Observable, and returns each
- * intermediate result, with an optional seed value.
- *
- * <span class="informal">It's like {@link reduce}, but emits the current
- * accumulation whenever the source emits a value.</span>
- *
- * <img src="./img/scan.png" width="100%">
- *
- * Combines together all values emitted on the source, using an accumulator
- * function that knows how to join a new source value into the accumulation from
- * the past. Is similar to {@link reduce}, but emits the intermediate
- * accumulations.
- *
- * Returns an Observable that applies a specified `accumulator` function to each
- * item emitted by the source Observable. If a `seed` value is specified, then
- * that value will be used as the initial value for the accumulator. If no seed
- * value is specified, the first item of the source is used as the seed.
- *
- * @example <caption>Count the number of click events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var ones = clicks.mapTo(1);
- * var seed = 0;
- * var count = ones.scan((acc, one) => acc + one, seed);
- * count.subscribe(x => console.log(x));
- *
- * @see {@link expand}
- * @see {@link mergeScan}
- * @see {@link reduce}
- *
- * @param {function(acc: R, value: T, index: number): R} accumulator
- * The accumulator function called on each source value.
- * @param {T|R} [seed] The initial accumulation value.
- * @return {Observable<R>} An observable of the accumulated values.
- * @method scan
- * @owner Observable
- */
- function scan$1(accumulator, seed) {
- if (arguments.length >= 2) {
- return scan(accumulator, seed)(this);
- }
- return scan(accumulator)(this);
- }
-
- Observable.prototype.scan = scan$1;
-
- /**
- * Compares all values of two observables in sequence using an optional comparor function
- * and returns an observable of a single boolean value representing whether or not the two sequences
- * are equal.
- *
- * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
- *
- * <img src="./img/sequenceEqual.png" width="100%">
- *
- * `sequenceEqual` subscribes to two observables and buffers incoming values from each observable. Whenever either
- * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom
- * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the
- * observables completes, the operator will wait for the other observable to complete; If the other
- * observable emits before completing, the returned observable will emit `false` and complete. If one observable never
- * completes or emits after the other complets, the returned observable will never complete.
- *
- * @example <caption>figure out if the Konami code matches</caption>
- * var code = Rx.Observable.from([
- * "ArrowUp",
- * "ArrowUp",
- * "ArrowDown",
- * "ArrowDown",
- * "ArrowLeft",
- * "ArrowRight",
- * "ArrowLeft",
- * "ArrowRight",
- * "KeyB",
- * "KeyA",
- * "Enter" // no start key, clearly.
- * ]);
- *
- * var keys = Rx.Observable.fromEvent(document, 'keyup')
- * .map(e => e.code);
- * var matches = keys.bufferCount(11, 1)
- * .mergeMap(
- * last11 =>
- * Rx.Observable.from(last11)
- * .sequenceEqual(code)
- * );
- * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
- *
- * @see {@link combineLatest}
- * @see {@link zip}
- * @see {@link withLatestFrom}
- *
- * @param {Observable} compareTo The observable sequence to compare the source sequence to.
- * @param {function} [comparor] An optional function to compare each value pair
- * @return {Observable} An Observable of a single boolean value representing whether or not
- * the values emitted by both observables were equal in sequence.
- * @method sequenceEqual
- * @owner Observable
- */
- function sequenceEqual$1(compareTo, comparor) {
- return function (source) { return source.lift(new SequenceEqualOperator(compareTo, comparor)); };
- }
- var SequenceEqualOperator = (function () {
- function SequenceEqualOperator(compareTo, comparor) {
- this.compareTo = compareTo;
- this.comparor = comparor;
- }
- SequenceEqualOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparor));
- };
- return SequenceEqualOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SequenceEqualSubscriber = (function (_super) {
- __extends(SequenceEqualSubscriber, _super);
- function SequenceEqualSubscriber(destination, compareTo, comparor) {
- _super.call(this, destination);
- this.compareTo = compareTo;
- this.comparor = comparor;
- this._a = [];
- this._b = [];
- this._oneComplete = false;
- this.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, this)));
- }
- SequenceEqualSubscriber.prototype._next = function (value) {
- if (this._oneComplete && this._b.length === 0) {
- this.emit(false);
- }
- else {
- this._a.push(value);
- this.checkValues();
- }
- };
- SequenceEqualSubscriber.prototype._complete = function () {
- if (this._oneComplete) {
- this.emit(this._a.length === 0 && this._b.length === 0);
- }
- else {
- this._oneComplete = true;
- }
- };
- SequenceEqualSubscriber.prototype.checkValues = function () {
- var _c = this, _a = _c._a, _b = _c._b, comparor = _c.comparor;
- while (_a.length > 0 && _b.length > 0) {
- var a = _a.shift();
- var b = _b.shift();
- var areEqual = false;
- if (comparor) {
- areEqual = tryCatch(comparor)(a, b);
- if (areEqual === errorObject) {
- this.destination.error(errorObject.e);
- }
- }
- else {
- areEqual = a === b;
- }
- if (!areEqual) {
- this.emit(false);
- }
- }
- };
- SequenceEqualSubscriber.prototype.emit = function (value) {
- var destination = this.destination;
- destination.next(value);
- destination.complete();
- };
- SequenceEqualSubscriber.prototype.nextB = function (value) {
- if (this._oneComplete && this._a.length === 0) {
- this.emit(false);
- }
- else {
- this._b.push(value);
- this.checkValues();
- }
- };
- return SequenceEqualSubscriber;
- }(Subscriber));
- var SequenceEqualCompareToSubscriber = (function (_super) {
- __extends(SequenceEqualCompareToSubscriber, _super);
- function SequenceEqualCompareToSubscriber(destination, parent) {
- _super.call(this, destination);
- this.parent = parent;
- }
- SequenceEqualCompareToSubscriber.prototype._next = function (value) {
- this.parent.nextB(value);
- };
- SequenceEqualCompareToSubscriber.prototype._error = function (err) {
- this.parent.error(err);
- };
- SequenceEqualCompareToSubscriber.prototype._complete = function () {
- this.parent._complete();
- };
- return SequenceEqualCompareToSubscriber;
- }(Subscriber));
-
- /**
- * Compares all values of two observables in sequence using an optional comparor function
- * and returns an observable of a single boolean value representing whether or not the two sequences
- * are equal.
- *
- * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
- *
- * <img src="./img/sequenceEqual.png" width="100%">
- *
- * `sequenceEqual` subscribes to two observables and buffers incoming values from each observable. Whenever either
- * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom
- * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the
- * observables completes, the operator will wait for the other observable to complete; If the other
- * observable emits before completing, the returned observable will emit `false` and complete. If one observable never
- * completes or emits after the other complets, the returned observable will never complete.
- *
- * @example <caption>figure out if the Konami code matches</caption>
- * var code = Rx.Observable.from([
- * "ArrowUp",
- * "ArrowUp",
- * "ArrowDown",
- * "ArrowDown",
- * "ArrowLeft",
- * "ArrowRight",
- * "ArrowLeft",
- * "ArrowRight",
- * "KeyB",
- * "KeyA",
- * "Enter" // no start key, clearly.
- * ]);
- *
- * var keys = Rx.Observable.fromEvent(document, 'keyup')
- * .map(e => e.code);
- * var matches = keys.bufferCount(11, 1)
- * .mergeMap(
- * last11 =>
- * Rx.Observable.from(last11)
- * .sequenceEqual(code)
- * );
- * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
- *
- * @see {@link combineLatest}
- * @see {@link zip}
- * @see {@link withLatestFrom}
- *
- * @param {Observable} compareTo The observable sequence to compare the source sequence to.
- * @param {function} [comparor] An optional function to compare each value pair
- * @return {Observable} An Observable of a single boolean value representing whether or not
- * the values emitted by both observables were equal in sequence.
- * @method sequenceEqual
- * @owner Observable
- */
- function sequenceEqual$$1(compareTo, comparor) {
- return sequenceEqual$1(compareTo, comparor)(this);
- }
-
- Observable.prototype.sequenceEqual = sequenceEqual$$1;
-
- function shareSubjectFactory() {
- return new Subject();
- }
- /**
- * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one
- * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will
- * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`.
- * This is an alias for .multicast(() => new Subject()).refCount().
- *
- * <img src="./img/share.png" width="100%">
- *
- * @return {Observable<T>} An Observable that upon connection causes the source Observable to emit items to its Observers.
- * @method share
- * @owner Observable
- */
- function share$1() {
- return function (source) { return refCount()(multicast$1(shareSubjectFactory)(source)); };
- }
-
- /**
- * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one
- * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will
- * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`.
- *
- * This behaves similarly to .publish().refCount(), with a behavior difference when the source observable emits complete.
- * .publish().refCount() will not resubscribe to the original source, however .share() will resubscribe to the original source.
- * Observable.of("test").publish().refCount() will not re-emit "test" on new subscriptions, Observable.of("test").share() will
- * re-emit "test" to new subscriptions.
- *
- * <img src="./img/share.png" width="100%">
- *
- * @return {Observable<T>} An Observable that upon connection causes the source Observable to emit items to its Observers.
- * @method share
- * @owner Observable
- */
- function share$$1() {
- return share$1()(this);
- }
-
- Observable.prototype.share = share$$1;
-
- /**
- * @method shareReplay
- * @owner Observable
- */
- function shareReplay$1(bufferSize, windowTime, scheduler) {
- return function (source) { return source.lift(shareReplayOperator(bufferSize, windowTime, scheduler)); };
- }
- function shareReplayOperator(bufferSize, windowTime, scheduler) {
- var subject;
- var refCount = 0;
- var subscription;
- var hasError = false;
- var isComplete = false;
- return function shareReplayOperation(source) {
- refCount++;
- if (!subject || hasError) {
- hasError = false;
- subject = new ReplaySubject(bufferSize, windowTime, scheduler);
- subscription = source.subscribe({
- next: function (value) { subject.next(value); },
- error: function (err) {
- hasError = true;
- subject.error(err);
- },
- complete: function () {
- isComplete = true;
- subject.complete();
- },
- });
- }
- var innerSub = subject.subscribe(this);
- return function () {
- refCount--;
- innerSub.unsubscribe();
- if (subscription && refCount === 0 && isComplete) {
- subscription.unsubscribe();
- }
- };
- };
- }
-
- /**
- * @method shareReplay
- * @owner Observable
- */
- function shareReplay$$1(bufferSize, windowTime, scheduler) {
- return shareReplay$1(bufferSize, windowTime, scheduler)(this);
- }
-
- Observable.prototype.shareReplay = shareReplay$$1;
-
- /**
- * Returns an Observable that emits the single item emitted by the source Observable that matches a specified
- * predicate, if that Observable emits one such item. If the source Observable emits more than one such item or no
- * such items, notify of an IllegalArgumentException or NoSuchElementException respectively.
- *
- * <img src="./img/single.png" width="100%">
- *
- * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
- * callback if the Observable completes before any `next` notification was sent.
- * @param {Function} predicate - A predicate function to evaluate items emitted by the source Observable.
- * @return {Observable<T>} An Observable that emits the single item emitted by the source Observable that matches
- * the predicate.
- .
- * @method single
- * @owner Observable
- */
- function single$1(predicate) {
- return function (source) { return source.lift(new SingleOperator(predicate, source)); };
- }
- var SingleOperator = (function () {
- function SingleOperator(predicate, source) {
- this.predicate = predicate;
- this.source = source;
- }
- SingleOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SingleSubscriber(subscriber, this.predicate, this.source));
- };
- return SingleOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SingleSubscriber = (function (_super) {
- __extends(SingleSubscriber, _super);
- function SingleSubscriber(destination, predicate, source) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.source = source;
- this.seenValue = false;
- this.index = 0;
- }
- SingleSubscriber.prototype.applySingleValue = function (value) {
- if (this.seenValue) {
- this.destination.error('Sequence contains more than one element');
- }
- else {
- this.seenValue = true;
- this.singleValue = value;
- }
- };
- SingleSubscriber.prototype._next = function (value) {
- var index = this.index++;
- if (this.predicate) {
- this.tryNext(value, index);
- }
- else {
- this.applySingleValue(value);
- }
- };
- SingleSubscriber.prototype.tryNext = function (value, index) {
- try {
- if (this.predicate(value, index, this.source)) {
- this.applySingleValue(value);
- }
- }
- catch (err) {
- this.destination.error(err);
- }
- };
- SingleSubscriber.prototype._complete = function () {
- var destination = this.destination;
- if (this.index > 0) {
- destination.next(this.seenValue ? this.singleValue : undefined);
- destination.complete();
- }
- else {
- destination.error(new EmptyError);
- }
- };
- return SingleSubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that emits the single item emitted by the source Observable that matches a specified
- * predicate, if that Observable emits one such item. If the source Observable emits more than one such item or no
- * such items, notify of an IllegalArgumentException or NoSuchElementException respectively.
- *
- * <img src="./img/single.png" width="100%">
- *
- * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
- * callback if the Observable completes before any `next` notification was sent.
- * @param {Function} predicate - A predicate function to evaluate items emitted by the source Observable.
- * @return {Observable<T>} An Observable that emits the single item emitted by the source Observable that matches
- * the predicate.
- .
- * @method single
- * @owner Observable
- */
- function single$$1(predicate) {
- return single$1(predicate)(this);
- }
-
- Observable.prototype.single = single$$1;
-
- /**
- * Returns an Observable that skips the first `count` items emitted by the source Observable.
- *
- * <img src="./img/skip.png" width="100%">
- *
- * @param {Number} count - The number of times, items emitted by source Observable should be skipped.
- * @return {Observable} An Observable that skips values emitted by the source Observable.
- *
- * @method skip
- * @owner Observable
- */
- function skip$1(count) {
- return function (source) { return source.lift(new SkipOperator(count)); };
- }
- var SkipOperator = (function () {
- function SkipOperator(total) {
- this.total = total;
- }
- SkipOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SkipSubscriber(subscriber, this.total));
- };
- return SkipOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SkipSubscriber = (function (_super) {
- __extends(SkipSubscriber, _super);
- function SkipSubscriber(destination, total) {
- _super.call(this, destination);
- this.total = total;
- this.count = 0;
- }
- SkipSubscriber.prototype._next = function (x) {
- if (++this.count > this.total) {
- this.destination.next(x);
- }
- };
- return SkipSubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that skips the first `count` items emitted by the source Observable.
- *
- * <img src="./img/skip.png" width="100%">
- *
- * @param {Number} count - The number of times, items emitted by source Observable should be skipped.
- * @return {Observable} An Observable that skips values emitted by the source Observable.
- *
- * @method skip
- * @owner Observable
- */
- function skip$$1(count) {
- return skip$1(count)(this);
- }
-
- Observable.prototype.skip = skip$$1;
-
- /**
- * Skip the last `count` values emitted by the source Observable.
- *
- * <img src="./img/skipLast.png" width="100%">
- *
- * `skipLast` returns an Observable that accumulates a queue with a length
- * enough to store the first `count` values. As more values are received,
- * values are taken from the front of the queue and produced on the result
- * sequence. This causes values to be delayed.
- *
- * @example <caption>Skip the last 2 values of an Observable with many values</caption>
- * var many = Rx.Observable.range(1, 5);
- * var skipLastTwo = many.skipLast(2);
- * skipLastTwo.subscribe(x => console.log(x));
- *
- * // Results in:
- * // 1 2 3
- *
- * @see {@link skip}
- * @see {@link skipUntil}
- * @see {@link skipWhile}
- * @see {@link take}
- *
- * @throws {ArgumentOutOfRangeError} When using `skipLast(i)`, it throws
- * ArgumentOutOrRangeError if `i < 0`.
- *
- * @param {number} count Number of elements to skip from the end of the source Observable.
- * @returns {Observable<T>} An Observable that skips the last count values
- * emitted by the source Observable.
- * @method skipLast
- * @owner Observable
- */
- function skipLast$1(count) {
- return function (source) { return source.lift(new SkipLastOperator(count)); };
- }
- var SkipLastOperator = (function () {
- function SkipLastOperator(_skipCount) {
- this._skipCount = _skipCount;
- if (this._skipCount < 0) {
- throw new ArgumentOutOfRangeError;
- }
- }
- SkipLastOperator.prototype.call = function (subscriber, source) {
- if (this._skipCount === 0) {
- // If we don't want to skip any values then just subscribe
- // to Subscriber without any further logic.
- return source.subscribe(new Subscriber(subscriber));
- }
- else {
- return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
- }
- };
- return SkipLastOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SkipLastSubscriber = (function (_super) {
- __extends(SkipLastSubscriber, _super);
- function SkipLastSubscriber(destination, _skipCount) {
- _super.call(this, destination);
- this._skipCount = _skipCount;
- this._count = 0;
- this._ring = new Array(_skipCount);
- }
- SkipLastSubscriber.prototype._next = function (value) {
- var skipCount = this._skipCount;
- var count = this._count++;
- if (count < skipCount) {
- this._ring[count] = value;
- }
- else {
- var currentIndex = count % skipCount;
- var ring = this._ring;
- var oldValue = ring[currentIndex];
- ring[currentIndex] = value;
- this.destination.next(oldValue);
- }
- };
- return SkipLastSubscriber;
- }(Subscriber));
-
- /**
- * Skip the last `count` values emitted by the source Observable.
- *
- * <img src="./img/skipLast.png" width="100%">
- *
- * `skipLast` returns an Observable that accumulates a queue with a length
- * enough to store the first `count` values. As more values are received,
- * values are taken from the front of the queue and produced on the result
- * sequence. This causes values to be delayed.
- *
- * @example <caption>Skip the last 2 values of an Observable with many values</caption>
- * var many = Rx.Observable.range(1, 5);
- * var skipLastTwo = many.skipLast(2);
- * skipLastTwo.subscribe(x => console.log(x));
- *
- * // Results in:
- * // 1 2 3
- *
- * @see {@link skip}
- * @see {@link skipUntil}
- * @see {@link skipWhile}
- * @see {@link take}
- *
- * @throws {ArgumentOutOfRangeError} When using `skipLast(i)`, it throws
- * ArgumentOutOrRangeError if `i < 0`.
- *
- * @param {number} count Number of elements to skip from the end of the source Observable.
- * @returns {Observable<T>} An Observable that skips the last count values
- * emitted by the source Observable.
- * @method skipLast
- * @owner Observable
- */
- function skipLast$$1(count) {
- return skipLast$1(count)(this);
- }
-
- Observable.prototype.skipLast = skipLast$$1;
-
- /**
- * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item.
- *
- * <img src="./img/skipUntil.png" width="100%">
- *
- * @param {Observable} notifier - The second Observable that has to emit an item before the source Observable's elements begin to
- * be mirrored by the resulting Observable.
- * @return {Observable<T>} An Observable that skips items from the source Observable until the second Observable emits
- * an item, then emits the remaining items.
- * @method skipUntil
- * @owner Observable
- */
- function skipUntil$1(notifier) {
- return function (source) { return source.lift(new SkipUntilOperator(notifier)); };
- }
- var SkipUntilOperator = (function () {
- function SkipUntilOperator(notifier) {
- this.notifier = notifier;
- }
- SkipUntilOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SkipUntilSubscriber(subscriber, this.notifier));
- };
- return SkipUntilOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SkipUntilSubscriber = (function (_super) {
- __extends(SkipUntilSubscriber, _super);
- function SkipUntilSubscriber(destination, notifier) {
- _super.call(this, destination);
- this.hasValue = false;
- this.isInnerStopped = false;
- this.add(subscribeToResult(this, notifier));
- }
- SkipUntilSubscriber.prototype._next = function (value) {
- if (this.hasValue) {
- _super.prototype._next.call(this, value);
- }
- };
- SkipUntilSubscriber.prototype._complete = function () {
- if (this.isInnerStopped) {
- _super.prototype._complete.call(this);
- }
- else {
- this.unsubscribe();
- }
- };
- SkipUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.hasValue = true;
- };
- SkipUntilSubscriber.prototype.notifyComplete = function () {
- this.isInnerStopped = true;
- if (this.isStopped) {
- _super.prototype._complete.call(this);
- }
- };
- return SkipUntilSubscriber;
- }(OuterSubscriber));
-
- /**
- * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item.
- *
- * <img src="./img/skipUntil.png" width="100%">
- *
- * @param {Observable} notifier - The second Observable that has to emit an item before the source Observable's elements begin to
- * be mirrored by the resulting Observable.
- * @return {Observable<T>} An Observable that skips items from the source Observable until the second Observable emits
- * an item, then emits the remaining items.
- * @method skipUntil
- * @owner Observable
- */
- function skipUntil$$1(notifier) {
- return skipUntil$1(notifier)(this);
- }
-
- Observable.prototype.skipUntil = skipUntil$$1;
-
- /**
- * Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds
- * true, but emits all further source items as soon as the condition becomes false.
- *
- * <img src="./img/skipWhile.png" width="100%">
- *
- * @param {Function} predicate - A function to test each item emitted from the source Observable.
- * @return {Observable<T>} An Observable that begins emitting items emitted by the source Observable when the
- * specified predicate becomes false.
- * @method skipWhile
- * @owner Observable
- */
- function skipWhile$1(predicate) {
- return function (source) { return source.lift(new SkipWhileOperator(predicate)); };
- }
- var SkipWhileOperator = (function () {
- function SkipWhileOperator(predicate) {
- this.predicate = predicate;
- }
- SkipWhileOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
- };
- return SkipWhileOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SkipWhileSubscriber = (function (_super) {
- __extends(SkipWhileSubscriber, _super);
- function SkipWhileSubscriber(destination, predicate) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.skipping = true;
- this.index = 0;
- }
- SkipWhileSubscriber.prototype._next = function (value) {
- var destination = this.destination;
- if (this.skipping) {
- this.tryCallPredicate(value);
- }
- if (!this.skipping) {
- destination.next(value);
- }
- };
- SkipWhileSubscriber.prototype.tryCallPredicate = function (value) {
- try {
- var result = this.predicate(value, this.index++);
- this.skipping = Boolean(result);
- }
- catch (err) {
- this.destination.error(err);
- }
- };
- return SkipWhileSubscriber;
- }(Subscriber));
-
- /**
- * Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds
- * true, but emits all further source items as soon as the condition becomes false.
- *
- * <img src="./img/skipWhile.png" width="100%">
- *
- * @param {Function} predicate - A function to test each item emitted from the source Observable.
- * @return {Observable<T>} An Observable that begins emitting items emitted by the source Observable when the
- * specified predicate becomes false.
- * @method skipWhile
- * @owner Observable
- */
- function skipWhile$$1(predicate) {
- return skipWhile$1(predicate)(this);
- }
-
- Observable.prototype.skipWhile = skipWhile$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits the items you specify as arguments before it begins to emit
- * items emitted by the source Observable.
- *
- * <img src="./img/startWith.png" width="100%">
- *
- * @param {...T} values - Items you want the modified Observable to emit first.
- * @param {Scheduler} [scheduler] - A {@link IScheduler} to use for scheduling
- * the emissions of the `next` notifications.
- * @return {Observable} An Observable that emits the items in the specified Iterable and then emits the items
- * emitted by the source Observable.
- * @method startWith
- * @owner Observable
- */
- function startWith$1() {
- var array = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- array[_i - 0] = arguments[_i];
- }
- return function (source) {
- var scheduler = array[array.length - 1];
- if (isScheduler(scheduler)) {
- array.pop();
- }
- else {
- scheduler = null;
- }
- var len = array.length;
- if (len === 1) {
- return concat(new ScalarObservable(array[0], scheduler), source);
- }
- else if (len > 1) {
- return concat(new ArrayObservable(array, scheduler), source);
- }
- else {
- return concat(new EmptyObservable(scheduler), source);
- }
- };
- }
-
- /* tslint:enable:max-line-length */
- /**
- * Returns an Observable that emits the items you specify as arguments before it begins to emit
- * items emitted by the source Observable.
- *
- * <img src="./img/startWith.png" width="100%">
- *
- * @param {...T} values - Items you want the modified Observable to emit first.
- * @param {Scheduler} [scheduler] - A {@link IScheduler} to use for scheduling
- * the emissions of the `next` notifications.
- * @return {Observable} An Observable that emits the items in the specified Iterable and then emits the items
- * emitted by the source Observable.
- * @method startWith
- * @owner Observable
- */
- function startWith$$1() {
- var array = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- array[_i - 0] = arguments[_i];
- }
- return startWith$1.apply(void 0, array)(this);
- }
-
- Observable.prototype.startWith = startWith$$1;
-
- /**
- Some credit for this helper goes to http://github.com/YuzuJS/setImmediate
- */
- var ImmediateDefinition = (function () {
- function ImmediateDefinition(root$$1) {
- this.root = root$$1;
- if (root$$1.setImmediate && typeof root$$1.setImmediate === 'function') {
- this.setImmediate = root$$1.setImmediate.bind(root$$1);
- this.clearImmediate = root$$1.clearImmediate.bind(root$$1);
- }
- else {
- this.nextHandle = 1;
- this.tasksByHandle = {};
- this.currentlyRunningATask = false;
- // Don't get fooled by e.g. browserify environments.
- if (this.canUseProcessNextTick()) {
- // For Node.js before 0.9
- this.setImmediate = this.createProcessNextTickSetImmediate();
- }
- else if (this.canUsePostMessage()) {
- // For non-IE10 modern browsers
- this.setImmediate = this.createPostMessageSetImmediate();
- }
- else if (this.canUseMessageChannel()) {
- // For web workers, where supported
- this.setImmediate = this.createMessageChannelSetImmediate();
- }
- else if (this.canUseReadyStateChange()) {
- // For IE 6–8
- this.setImmediate = this.createReadyStateChangeSetImmediate();
- }
- else {
- // For older browsers
- this.setImmediate = this.createSetTimeoutSetImmediate();
- }
- var ci = function clearImmediate(handle) {
- delete clearImmediate.instance.tasksByHandle[handle];
- };
- ci.instance = this;
- this.clearImmediate = ci;
- }
- }
- ImmediateDefinition.prototype.identify = function (o) {
- return this.root.Object.prototype.toString.call(o);
- };
- ImmediateDefinition.prototype.canUseProcessNextTick = function () {
- return this.identify(this.root.process) === '[object process]';
- };
- ImmediateDefinition.prototype.canUseMessageChannel = function () {
- return Boolean(this.root.MessageChannel);
- };
- ImmediateDefinition.prototype.canUseReadyStateChange = function () {
- var document = this.root.document;
- return Boolean(document && 'onreadystatechange' in document.createElement('script'));
- };
- ImmediateDefinition.prototype.canUsePostMessage = function () {
- var root$$1 = this.root;
- // The test against `importScripts` prevents this implementation from being installed inside a web worker,
- // where `root.postMessage` means something completely different and can't be used for this purpose.
- if (root$$1.postMessage && !root$$1.importScripts) {
- var postMessageIsAsynchronous_1 = true;
- var oldOnMessage = root$$1.onmessage;
- root$$1.onmessage = function () {
- postMessageIsAsynchronous_1 = false;
- };
- root$$1.postMessage('', '*');
- root$$1.onmessage = oldOnMessage;
- return postMessageIsAsynchronous_1;
- }
- return false;
- };
- // This function accepts the same arguments as setImmediate, but
- // returns a function that requires no arguments.
- ImmediateDefinition.prototype.partiallyApplied = function (handler) {
- var args = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- args[_i - 1] = arguments[_i];
- }
- var fn = function result() {
- var _a = result, handler = _a.handler, args = _a.args;
- if (typeof handler === 'function') {
- handler.apply(undefined, args);
- }
- else {
- (new Function('' + handler))();
- }
- };
- fn.handler = handler;
- fn.args = args;
- return fn;
- };
- ImmediateDefinition.prototype.addFromSetImmediateArguments = function (args) {
- this.tasksByHandle[this.nextHandle] = this.partiallyApplied.apply(undefined, args);
- return this.nextHandle++;
- };
- ImmediateDefinition.prototype.createProcessNextTickSetImmediate = function () {
- var fn = function setImmediate() {
- var instance = setImmediate.instance;
- var handle = instance.addFromSetImmediateArguments(arguments);
- instance.root.process.nextTick(instance.partiallyApplied(instance.runIfPresent, handle));
- return handle;
- };
- fn.instance = this;
- return fn;
- };
- ImmediateDefinition.prototype.createPostMessageSetImmediate = function () {
- // Installs an event handler on `global` for the `message` event: see
- // * https://developer.mozilla.org/en/DOM/window.postMessage
- // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
- var root$$1 = this.root;
- var messagePrefix = 'setImmediate$' + root$$1.Math.random() + '$';
- var onGlobalMessage = function globalMessageHandler(event) {
- var instance = globalMessageHandler.instance;
- if (event.source === root$$1 &&
- typeof event.data === 'string' &&
- event.data.indexOf(messagePrefix) === 0) {
- instance.runIfPresent(+event.data.slice(messagePrefix.length));
- }
- };
- onGlobalMessage.instance = this;
- root$$1.addEventListener('message', onGlobalMessage, false);
- var fn = function setImmediate() {
- var _a = setImmediate, messagePrefix = _a.messagePrefix, instance = _a.instance;
- var handle = instance.addFromSetImmediateArguments(arguments);
- instance.root.postMessage(messagePrefix + handle, '*');
- return handle;
- };
- fn.instance = this;
- fn.messagePrefix = messagePrefix;
- return fn;
- };
- ImmediateDefinition.prototype.runIfPresent = function (handle) {
- // From the spec: 'Wait until any invocations of this algorithm started before this one have completed.'
- // So if we're currently running a task, we'll need to delay this invocation.
- if (this.currentlyRunningATask) {
- // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
- // 'too much recursion' error.
- this.root.setTimeout(this.partiallyApplied(this.runIfPresent, handle), 0);
- }
- else {
- var task = this.tasksByHandle[handle];
- if (task) {
- this.currentlyRunningATask = true;
- try {
- task();
- }
- finally {
- this.clearImmediate(handle);
- this.currentlyRunningATask = false;
- }
- }
- }
- };
- ImmediateDefinition.prototype.createMessageChannelSetImmediate = function () {
- var _this = this;
- var channel = new this.root.MessageChannel();
- channel.port1.onmessage = function (event) {
- var handle = event.data;
- _this.runIfPresent(handle);
- };
- var fn = function setImmediate() {
- var _a = setImmediate, channel = _a.channel, instance = _a.instance;
- var handle = instance.addFromSetImmediateArguments(arguments);
- channel.port2.postMessage(handle);
- return handle;
- };
- fn.channel = channel;
- fn.instance = this;
- return fn;
- };
- ImmediateDefinition.prototype.createReadyStateChangeSetImmediate = function () {
- var fn = function setImmediate() {
- var instance = setImmediate.instance;
- var root$$1 = instance.root;
- var doc = root$$1.document;
- var html = doc.documentElement;
- var handle = instance.addFromSetImmediateArguments(arguments);
- // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
- // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
- var script = doc.createElement('script');
- script.onreadystatechange = function () {
- instance.runIfPresent(handle);
- script.onreadystatechange = null;
- html.removeChild(script);
- script = null;
- };
- html.appendChild(script);
- return handle;
- };
- fn.instance = this;
- return fn;
- };
- ImmediateDefinition.prototype.createSetTimeoutSetImmediate = function () {
- var fn = function setImmediate() {
- var instance = setImmediate.instance;
- var handle = instance.addFromSetImmediateArguments(arguments);
- instance.root.setTimeout(instance.partiallyApplied(instance.runIfPresent, handle), 0);
- return handle;
- };
- fn.instance = this;
- return fn;
- };
- return ImmediateDefinition;
- }());
- var Immediate = new ImmediateDefinition(_root);
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var AsapAction = (function (_super) {
- __extends(AsapAction, _super);
- function AsapAction(scheduler, work) {
- _super.call(this, scheduler, work);
- this.scheduler = scheduler;
- this.work = work;
- }
- AsapAction.prototype.requestAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- // If delay is greater than 0, request as an async action.
- if (delay !== null && delay > 0) {
- return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
- }
- // Push the action to the end of the scheduler queue.
- scheduler.actions.push(this);
- // If a microtask has already been scheduled, don't schedule another
- // one. If a microtask hasn't been scheduled yet, schedule one now. Return
- // the current scheduled microtask id.
- return scheduler.scheduled || (scheduler.scheduled = Immediate.setImmediate(scheduler.flush.bind(scheduler, null)));
- };
- AsapAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- // If delay exists and is greater than 0, or if the delay is null (the
- // action wasn't rescheduled) but was originally scheduled as an async
- // action, then recycle as an async action.
- if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
- return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
- }
- // If the scheduler queue is empty, cancel the requested microtask and
- // set the scheduled flag to undefined so the next AsapAction will schedule
- // its own.
- if (scheduler.actions.length === 0) {
- Immediate.clearImmediate(id);
- scheduler.scheduled = undefined;
- }
- // Return undefined so the action knows to request a new async id if it's rescheduled.
- return undefined;
- };
- return AsapAction;
- }(AsyncAction));
-
- var AsapScheduler = (function (_super) {
- __extends(AsapScheduler, _super);
- function AsapScheduler() {
- _super.apply(this, arguments);
- }
- AsapScheduler.prototype.flush = function (action) {
- this.active = true;
- this.scheduled = undefined;
- var actions = this.actions;
- var error;
- var index = -1;
- var count = actions.length;
- action = action || actions.shift();
- do {
- if (error = action.execute(action.state, action.delay)) {
- break;
- }
- } while (++index < count && (action = actions.shift()));
- this.active = false;
- if (error) {
- while (++index < count && (action = actions.shift())) {
- action.unsubscribe();
- }
- throw error;
- }
- };
- return AsapScheduler;
- }(AsyncScheduler));
-
- /**
- *
- * Asap Scheduler
- *
- * <span class="informal">Perform task as fast as it can be performed asynchronously</span>
- *
- * `asap` scheduler behaves the same as {@link async} scheduler when you use it to delay task
- * in time. If however you set delay to `0`, `asap` will wait for current synchronously executing
- * code to end and then it will try to execute given task as fast as possible.
- *
- * `asap` scheduler will do its best to minimize time between end of currently executing code
- * and start of scheduled task. This makes it best candidate for performing so called "deferring".
- * Traditionally this was achieved by calling `setTimeout(deferredTask, 0)`, but that technique involves
- * some (although minimal) unwanted delay.
- *
- * Note that using `asap` scheduler does not necessarily mean that your task will be first to process
- * after currently executing code. In particular, if some task was also scheduled with `asap` before,
- * that task will execute first. That being said, if you need to schedule task asynchronously, but
- * as soon as possible, `asap` scheduler is your best bet.
- *
- * @example <caption>Compare async and asap scheduler</caption>
- *
- * Rx.Scheduler.async.schedule(() => console.log('async')); // scheduling 'async' first...
- * Rx.Scheduler.asap.schedule(() => console.log('asap'));
- *
- * // Logs:
- * // "asap"
- * // "async"
- * // ... but 'asap' goes first!
- *
- * @static true
- * @name asap
- * @owner Scheduler
- */
- var asap = new AsapScheduler(AsapAction);
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var SubscribeOnObservable = (function (_super) {
- __extends(SubscribeOnObservable, _super);
- function SubscribeOnObservable(source, delayTime, scheduler) {
- if (delayTime === void 0) { delayTime = 0; }
- if (scheduler === void 0) { scheduler = asap; }
- _super.call(this);
- this.source = source;
- this.delayTime = delayTime;
- this.scheduler = scheduler;
- if (!isNumeric(delayTime) || delayTime < 0) {
- this.delayTime = 0;
- }
- if (!scheduler || typeof scheduler.schedule !== 'function') {
- this.scheduler = asap;
- }
- }
- SubscribeOnObservable.create = function (source, delay, scheduler) {
- if (delay === void 0) { delay = 0; }
- if (scheduler === void 0) { scheduler = asap; }
- return new SubscribeOnObservable(source, delay, scheduler);
- };
- SubscribeOnObservable.dispatch = function (arg) {
- var source = arg.source, subscriber = arg.subscriber;
- return this.add(source.subscribe(subscriber));
- };
- /** @deprecated internal use only */ SubscribeOnObservable.prototype._subscribe = function (subscriber) {
- var delay = this.delayTime;
- var source = this.source;
- var scheduler = this.scheduler;
- return scheduler.schedule(SubscribeOnObservable.dispatch, delay, {
- source: source, subscriber: subscriber
- });
- };
- return SubscribeOnObservable;
- }(Observable));
-
- /**
- * Asynchronously subscribes Observers to this Observable on the specified IScheduler.
- *
- * <img src="./img/subscribeOn.png" width="100%">
- *
- * @param {Scheduler} scheduler - The IScheduler to perform subscription actions on.
- * @return {Observable<T>} The source Observable modified so that its subscriptions happen on the specified IScheduler.
- .
- * @method subscribeOn
- * @owner Observable
- */
- function subscribeOn$1(scheduler, delay) {
- if (delay === void 0) { delay = 0; }
- return function subscribeOnOperatorFunction(source) {
- return source.lift(new SubscribeOnOperator(scheduler, delay));
- };
- }
- var SubscribeOnOperator = (function () {
- function SubscribeOnOperator(scheduler, delay) {
- this.scheduler = scheduler;
- this.delay = delay;
- }
- SubscribeOnOperator.prototype.call = function (subscriber, source) {
- return new SubscribeOnObservable(source, this.delay, this.scheduler).subscribe(subscriber);
- };
- return SubscribeOnOperator;
- }());
-
- /**
- * Asynchronously subscribes Observers to this Observable on the specified IScheduler.
- *
- * <img src="./img/subscribeOn.png" width="100%">
- *
- * @param {Scheduler} scheduler - The IScheduler to perform subscription actions on.
- * @return {Observable<T>} The source Observable modified so that its subscriptions happen on the specified IScheduler.
- .
- * @method subscribeOn
- * @owner Observable
- */
- function subscribeOn$$1(scheduler, delay) {
- if (delay === void 0) { delay = 0; }
- return subscribeOn$1(scheduler, delay)(this);
- }
-
- Observable.prototype.subscribeOn = subscribeOn$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable, emitting values only from the most recently projected Observable.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link switch}.</span>
- *
- * <img src="./img/switchMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an (so-called "inner") Observable. Each time it observes one of these
- * inner Observables, the output Observable begins emitting the items emitted by
- * that inner Observable. When a new inner Observable is emitted, `switchMap`
- * stops emitting items from the earlier-emitted inner Observable and begins
- * emitting items from the new one. It continues to behave like this for
- * subsequent inner Observables.
- *
- * @example <caption>Rerun an interval Observable on every click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.switchMap((ev) => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMap}
- * @see {@link exhaustMap}
- * @see {@link mergeMap}
- * @see {@link switch}
- * @see {@link switchMapTo}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable that emits the result of applying the
- * projection function (and the optional `resultSelector`) to each item emitted
- * by the source Observable and taking only the values from the most recently
- * projected inner Observable.
- * @method switchMap
- * @owner Observable
- */
- function switchMap(project, resultSelector) {
- return function switchMapOperatorFunction(source) {
- return source.lift(new SwitchMapOperator(project, resultSelector));
- };
- }
- var SwitchMapOperator = (function () {
- function SwitchMapOperator(project, resultSelector) {
- this.project = project;
- this.resultSelector = resultSelector;
- }
- SwitchMapOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SwitchMapSubscriber(subscriber, this.project, this.resultSelector));
- };
- return SwitchMapOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SwitchMapSubscriber = (function (_super) {
- __extends(SwitchMapSubscriber, _super);
- function SwitchMapSubscriber(destination, project, resultSelector) {
- _super.call(this, destination);
- this.project = project;
- this.resultSelector = resultSelector;
- this.index = 0;
- }
- SwitchMapSubscriber.prototype._next = function (value) {
- var result;
- var index = this.index++;
- try {
- result = this.project(value, index);
- }
- catch (error) {
- this.destination.error(error);
- return;
- }
- this._innerSub(result, value, index);
- };
- SwitchMapSubscriber.prototype._innerSub = function (result, value, index) {
- var innerSubscription = this.innerSubscription;
- if (innerSubscription) {
- innerSubscription.unsubscribe();
- }
- this.add(this.innerSubscription = subscribeToResult(this, result, value, index));
- };
- SwitchMapSubscriber.prototype._complete = function () {
- var innerSubscription = this.innerSubscription;
- if (!innerSubscription || innerSubscription.closed) {
- _super.prototype._complete.call(this);
- }
- };
- /** @deprecated internal use only */ SwitchMapSubscriber.prototype._unsubscribe = function () {
- this.innerSubscription = null;
- };
- SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) {
- this.remove(innerSub);
- this.innerSubscription = null;
- if (this.isStopped) {
- _super.prototype._complete.call(this);
- }
- };
- SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- if (this.resultSelector) {
- this._tryNotifyNext(outerValue, innerValue, outerIndex, innerIndex);
- }
- else {
- this.destination.next(innerValue);
- }
- };
- SwitchMapSubscriber.prototype._tryNotifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
- var result;
- try {
- result = this.resultSelector(outerValue, innerValue, outerIndex, innerIndex);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.destination.next(result);
- };
- return SwitchMapSubscriber;
- }(OuterSubscriber));
-
- function switchAll() {
- return switchMap(identity);
- }
-
- /**
- * Converts a higher-order Observable into a first-order Observable by
- * subscribing to only the most recently emitted of those inner Observables.
- *
- * <span class="informal">Flattens an Observable-of-Observables by dropping the
- * previous inner Observable once a new one appears.</span>
- *
- * <img src="./img/switch.png" width="100%">
- *
- * `switch` subscribes to an Observable that emits Observables, also known as a
- * higher-order Observable. Each time it observes one of these emitted inner
- * Observables, the output Observable subscribes to the inner Observable and
- * begins emitting the items emitted by that. So far, it behaves
- * like {@link mergeAll}. However, when a new inner Observable is emitted,
- * `switch` unsubscribes from the earlier-emitted inner Observable and
- * subscribes to the new inner Observable and begins emitting items from it. It
- * continues to behave like this for subsequent inner Observables.
- *
- * @example <caption>Rerun an interval Observable on every click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * // Each click event is mapped to an Observable that ticks every second
- * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000));
- * var switched = higherOrder.switch();
- * // The outcome is that `switched` is essentially a timer that restarts
- * // on every click. The interval Observables from older clicks do not merge
- * // with the current interval Observable.
- * switched.subscribe(x => console.log(x));
- *
- * @see {@link combineAll}
- * @see {@link concatAll}
- * @see {@link exhaust}
- * @see {@link mergeAll}
- * @see {@link switchMap}
- * @see {@link switchMapTo}
- * @see {@link zipAll}
- *
- * @return {Observable<T>} An Observable that emits the items emitted by the
- * Observable most recently emitted by the source Observable.
- * @method switch
- * @name switch
- * @owner Observable
- */
- function _switch() {
- return switchAll()(this);
- }
-
- Observable.prototype.switch = _switch;
- Observable.prototype._switch = _switch;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to an Observable which is merged in the output
- * Observable, emitting values only from the most recently projected Observable.
- *
- * <span class="informal">Maps each value to an Observable, then flattens all of
- * these inner Observables using {@link switch}.</span>
- *
- * <img src="./img/switchMap.png" width="100%">
- *
- * Returns an Observable that emits items based on applying a function that you
- * supply to each item emitted by the source Observable, where that function
- * returns an (so-called "inner") Observable. Each time it observes one of these
- * inner Observables, the output Observable begins emitting the items emitted by
- * that inner Observable. When a new inner Observable is emitted, `switchMap`
- * stops emitting items from the earlier-emitted inner Observable and begins
- * emitting items from the new one. It continues to behave like this for
- * subsequent inner Observables.
- *
- * @example <caption>Rerun an interval Observable on every click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.switchMap((ev) => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMap}
- * @see {@link exhaustMap}
- * @see {@link mergeMap}
- * @see {@link switch}
- * @see {@link switchMapTo}
- *
- * @param {function(value: T, ?index: number): ObservableInput} project A function
- * that, when applied to an item emitted by the source Observable, returns an
- * Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable that emits the result of applying the
- * projection function (and the optional `resultSelector`) to each item emitted
- * by the source Observable and taking only the values from the most recently
- * projected inner Observable.
- * @method switchMap
- * @owner Observable
- */
- function switchMap$1(project, resultSelector) {
- return switchMap(project, resultSelector)(this);
- }
-
- Observable.prototype.switchMap = switchMap$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to the same Observable which is flattened multiple
- * times with {@link switch} in the output Observable.
- *
- * <span class="informal">It's like {@link switchMap}, but maps each value
- * always to the same inner Observable.</span>
- *
- * <img src="./img/switchMapTo.png" width="100%">
- *
- * Maps each source value to the given Observable `innerObservable` regardless
- * of the source value, and then flattens those resulting Observables into one
- * single Observable, which is the output Observable. The output Observables
- * emits values only from the most recently emitted instance of
- * `innerObservable`.
- *
- * @example <caption>Rerun an interval Observable on every click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.switchMapTo(Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMapTo}
- * @see {@link switch}
- * @see {@link switchMap}
- * @see {@link mergeMapTo}
- *
- * @param {ObservableInput} innerObservable An Observable to replace each value from
- * the source Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable that emits items from the given
- * `innerObservable` (and optionally transformed through `resultSelector`) every
- * time a value is emitted on the source Observable, and taking only the values
- * from the most recently projected inner Observable.
- * @method switchMapTo
- * @owner Observable
- */
- function switchMapTo$1(innerObservable, resultSelector) {
- return function (source) { return source.lift(new SwitchMapToOperator(innerObservable, resultSelector)); };
- }
- var SwitchMapToOperator = (function () {
- function SwitchMapToOperator(observable, resultSelector) {
- this.observable = observable;
- this.resultSelector = resultSelector;
- }
- SwitchMapToOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new SwitchMapToSubscriber(subscriber, this.observable, this.resultSelector));
- };
- return SwitchMapToOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var SwitchMapToSubscriber = (function (_super) {
- __extends(SwitchMapToSubscriber, _super);
- function SwitchMapToSubscriber(destination, inner, resultSelector) {
- _super.call(this, destination);
- this.inner = inner;
- this.resultSelector = resultSelector;
- this.index = 0;
- }
- SwitchMapToSubscriber.prototype._next = function (value) {
- var innerSubscription = this.innerSubscription;
- if (innerSubscription) {
- innerSubscription.unsubscribe();
- }
- this.add(this.innerSubscription = subscribeToResult(this, this.inner, value, this.index++));
- };
- SwitchMapToSubscriber.prototype._complete = function () {
- var innerSubscription = this.innerSubscription;
- if (!innerSubscription || innerSubscription.closed) {
- _super.prototype._complete.call(this);
- }
- };
- /** @deprecated internal use only */ SwitchMapToSubscriber.prototype._unsubscribe = function () {
- this.innerSubscription = null;
- };
- SwitchMapToSubscriber.prototype.notifyComplete = function (innerSub) {
- this.remove(innerSub);
- this.innerSubscription = null;
- if (this.isStopped) {
- _super.prototype._complete.call(this);
- }
- };
- SwitchMapToSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
- if (resultSelector) {
- this.tryResultSelector(outerValue, innerValue, outerIndex, innerIndex);
- }
- else {
- destination.next(innerValue);
- }
- };
- SwitchMapToSubscriber.prototype.tryResultSelector = function (outerValue, innerValue, outerIndex, innerIndex) {
- var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
- var result;
- try {
- result = resultSelector(outerValue, innerValue, outerIndex, innerIndex);
- }
- catch (err) {
- destination.error(err);
- return;
- }
- destination.next(result);
- };
- return SwitchMapToSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Projects each source value to the same Observable which is flattened multiple
- * times with {@link switch} in the output Observable.
- *
- * <span class="informal">It's like {@link switchMap}, but maps each value
- * always to the same inner Observable.</span>
- *
- * <img src="./img/switchMapTo.png" width="100%">
- *
- * Maps each source value to the given Observable `innerObservable` regardless
- * of the source value, and then flattens those resulting Observables into one
- * single Observable, which is the output Observable. The output Observables
- * emits values only from the most recently emitted instance of
- * `innerObservable`.
- *
- * @example <caption>Rerun an interval Observable on every click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.switchMapTo(Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link concatMapTo}
- * @see {@link switch}
- * @see {@link switchMap}
- * @see {@link mergeMapTo}
- *
- * @param {ObservableInput} innerObservable An Observable to replace each value from
- * the source Observable.
- * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
- * A function to produce the value on the output Observable based on the values
- * and the indices of the source (outer) emission and the inner Observable
- * emission. The arguments passed to this function are:
- * - `outerValue`: the value that came from the source
- * - `innerValue`: the value that came from the projected Observable
- * - `outerIndex`: the "index" of the value that came from the source
- * - `innerIndex`: the "index" of the value from the projected Observable
- * @return {Observable} An Observable that emits items from the given
- * `innerObservable` (and optionally transformed through `resultSelector`) every
- * time a value is emitted on the source Observable, and taking only the values
- * from the most recently projected inner Observable.
- * @method switchMapTo
- * @owner Observable
- */
- function switchMapTo$$1(innerObservable, resultSelector) {
- return switchMapTo$1(innerObservable, resultSelector)(this);
- }
-
- Observable.prototype.switchMapTo = switchMapTo$$1;
-
- /**
- * Emits only the first `count` values emitted by the source Observable.
- *
- * <span class="informal">Takes the first `count` values from the source, then
- * completes.</span>
- *
- * <img src="./img/take.png" width="100%">
- *
- * `take` returns an Observable that emits only the first `count` values emitted
- * by the source Observable. If the source emits fewer than `count` values then
- * all of its values are emitted. After that, it completes, regardless if the
- * source completes.
- *
- * @example <caption>Take the first 5 seconds of an infinite 1-second interval Observable</caption>
- * var interval = Rx.Observable.interval(1000);
- * var five = interval.take(5);
- * five.subscribe(x => console.log(x));
- *
- * @see {@link takeLast}
- * @see {@link takeUntil}
- * @see {@link takeWhile}
- * @see {@link skip}
- *
- * @throws {ArgumentOutOfRangeError} When using `take(i)`, it delivers an
- * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
- *
- * @param {number} count The maximum number of `next` values to emit.
- * @return {Observable<T>} An Observable that emits only the first `count`
- * values emitted by the source Observable, or all of the values from the source
- * if the source emits fewer than `count` values.
- * @method take
- * @owner Observable
- */
- function take$1(count) {
- return function (source) {
- if (count === 0) {
- return new EmptyObservable();
- }
- else {
- return source.lift(new TakeOperator(count));
- }
- };
- }
- var TakeOperator = (function () {
- function TakeOperator(total) {
- this.total = total;
- if (this.total < 0) {
- throw new ArgumentOutOfRangeError;
- }
- }
- TakeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new TakeSubscriber(subscriber, this.total));
- };
- return TakeOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TakeSubscriber = (function (_super) {
- __extends(TakeSubscriber, _super);
- function TakeSubscriber(destination, total) {
- _super.call(this, destination);
- this.total = total;
- this.count = 0;
- }
- TakeSubscriber.prototype._next = function (value) {
- var total = this.total;
- var count = ++this.count;
- if (count <= total) {
- this.destination.next(value);
- if (count === total) {
- this.destination.complete();
- this.unsubscribe();
- }
- }
- };
- return TakeSubscriber;
- }(Subscriber));
-
- /**
- * Emits only the first `count` values emitted by the source Observable.
- *
- * <span class="informal">Takes the first `count` values from the source, then
- * completes.</span>
- *
- * <img src="./img/take.png" width="100%">
- *
- * `take` returns an Observable that emits only the first `count` values emitted
- * by the source Observable. If the source emits fewer than `count` values then
- * all of its values are emitted. After that, it completes, regardless if the
- * source completes.
- *
- * @example <caption>Take the first 5 seconds of an infinite 1-second interval Observable</caption>
- * var interval = Rx.Observable.interval(1000);
- * var five = interval.take(5);
- * five.subscribe(x => console.log(x));
- *
- * @see {@link takeLast}
- * @see {@link takeUntil}
- * @see {@link takeWhile}
- * @see {@link skip}
- *
- * @throws {ArgumentOutOfRangeError} When using `take(i)`, it delivers an
- * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
- *
- * @param {number} count The maximum number of `next` values to emit.
- * @return {Observable<T>} An Observable that emits only the first `count`
- * values emitted by the source Observable, or all of the values from the source
- * if the source emits fewer than `count` values.
- * @method take
- * @owner Observable
- */
- function take$$1(count) {
- return take$1(count)(this);
- }
-
- Observable.prototype.take = take$$1;
-
- /**
- * Emits only the last `count` values emitted by the source Observable.
- *
- * <span class="informal">Remembers the latest `count` values, then emits those
- * only when the source completes.</span>
- *
- * <img src="./img/takeLast.png" width="100%">
- *
- * `takeLast` returns an Observable that emits at most the last `count` values
- * emitted by the source Observable. If the source emits fewer than `count`
- * values then all of its values are emitted. This operator must wait until the
- * `complete` notification emission from the source in order to emit the `next`
- * values on the output Observable, because otherwise it is impossible to know
- * whether or not more values will be emitted on the source. For this reason,
- * all values are emitted synchronously, followed by the complete notification.
- *
- * @example <caption>Take the last 3 values of an Observable with many values</caption>
- * var many = Rx.Observable.range(1, 100);
- * var lastThree = many.takeLast(3);
- * lastThree.subscribe(x => console.log(x));
- *
- * @see {@link take}
- * @see {@link takeUntil}
- * @see {@link takeWhile}
- * @see {@link skip}
- *
- * @throws {ArgumentOutOfRangeError} When using `takeLast(i)`, it delivers an
- * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
- *
- * @param {number} count The maximum number of values to emit from the end of
- * the sequence of values emitted by the source Observable.
- * @return {Observable<T>} An Observable that emits at most the last count
- * values emitted by the source Observable.
- * @method takeLast
- * @owner Observable
- */
- function takeLast$1(count) {
- return takeLast(count)(this);
- }
-
- Observable.prototype.takeLast = takeLast$1;
-
- /**
- * Emits the values emitted by the source Observable until a `notifier`
- * Observable emits a value.
- *
- * <span class="informal">Lets values pass until a second Observable,
- * `notifier`, emits something. Then, it completes.</span>
- *
- * <img src="./img/takeUntil.png" width="100%">
- *
- * `takeUntil` subscribes and begins mirroring the source Observable. It also
- * monitors a second Observable, `notifier` that you provide. If the `notifier`
- * emits a value or a complete notification, the output Observable stops
- * mirroring the source Observable and completes.
- *
- * @example <caption>Tick every second until the first click happens</caption>
- * var interval = Rx.Observable.interval(1000);
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = interval.takeUntil(clicks);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link take}
- * @see {@link takeLast}
- * @see {@link takeWhile}
- * @see {@link skip}
- *
- * @param {Observable} notifier The Observable whose first emitted value will
- * cause the output Observable of `takeUntil` to stop emitting values from the
- * source Observable.
- * @return {Observable<T>} An Observable that emits the values from the source
- * Observable until such time as `notifier` emits its first value.
- * @method takeUntil
- * @owner Observable
- */
- function takeUntil$1(notifier) {
- return function (source) { return source.lift(new TakeUntilOperator(notifier)); };
- }
- var TakeUntilOperator = (function () {
- function TakeUntilOperator(notifier) {
- this.notifier = notifier;
- }
- TakeUntilOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new TakeUntilSubscriber(subscriber, this.notifier));
- };
- return TakeUntilOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TakeUntilSubscriber = (function (_super) {
- __extends(TakeUntilSubscriber, _super);
- function TakeUntilSubscriber(destination, notifier) {
- _super.call(this, destination);
- this.notifier = notifier;
- this.add(subscribeToResult(this, notifier));
- }
- TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.complete();
- };
- TakeUntilSubscriber.prototype.notifyComplete = function () {
- // noop
- };
- return TakeUntilSubscriber;
- }(OuterSubscriber));
-
- /**
- * Emits the values emitted by the source Observable until a `notifier`
- * Observable emits a value.
- *
- * <span class="informal">Lets values pass until a second Observable,
- * `notifier`, emits something. Then, it completes.</span>
- *
- * <img src="./img/takeUntil.png" width="100%">
- *
- * `takeUntil` subscribes and begins mirroring the source Observable. It also
- * monitors a second Observable, `notifier` that you provide. If the `notifier`
- * emits a value, the output Observable stops mirroring the source Observable
- * and completes.
- *
- * @example <caption>Tick every second until the first click happens</caption>
- * var interval = Rx.Observable.interval(1000);
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = interval.takeUntil(clicks);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link take}
- * @see {@link takeLast}
- * @see {@link takeWhile}
- * @see {@link skip}
- *
- * @param {Observable} notifier The Observable whose first emitted value will
- * cause the output Observable of `takeUntil` to stop emitting values from the
- * source Observable.
- * @return {Observable<T>} An Observable that emits the values from the source
- * Observable until such time as `notifier` emits its first value.
- * @method takeUntil
- * @owner Observable
- */
- function takeUntil$$1(notifier) {
- return takeUntil$1(notifier)(this);
- }
-
- Observable.prototype.takeUntil = takeUntil$$1;
-
- /**
- * Emits values emitted by the source Observable so long as each value satisfies
- * the given `predicate`, and then completes as soon as this `predicate` is not
- * satisfied.
- *
- * <span class="informal">Takes values from the source only while they pass the
- * condition given. When the first value does not satisfy, it completes.</span>
- *
- * <img src="./img/takeWhile.png" width="100%">
- *
- * `takeWhile` subscribes and begins mirroring the source Observable. Each value
- * emitted on the source is given to the `predicate` function which returns a
- * boolean, representing a condition to be satisfied by the source values. The
- * output Observable emits the source values until such time as the `predicate`
- * returns false, at which point `takeWhile` stops mirroring the source
- * Observable and completes the output Observable.
- *
- * @example <caption>Emit click events only while the clientX property is greater than 200</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.takeWhile(ev => ev.clientX > 200);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link take}
- * @see {@link takeLast}
- * @see {@link takeUntil}
- * @see {@link skip}
- *
- * @param {function(value: T, index: number): boolean} predicate A function that
- * evaluates a value emitted by the source Observable and returns a boolean.
- * Also takes the (zero-based) index as the second argument.
- * @return {Observable<T>} An Observable that emits the values from the source
- * Observable so long as each value satisfies the condition defined by the
- * `predicate`, then completes.
- * @method takeWhile
- * @owner Observable
- */
- function takeWhile$1(predicate) {
- return function (source) { return source.lift(new TakeWhileOperator(predicate)); };
- }
- var TakeWhileOperator = (function () {
- function TakeWhileOperator(predicate) {
- this.predicate = predicate;
- }
- TakeWhileOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate));
- };
- return TakeWhileOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TakeWhileSubscriber = (function (_super) {
- __extends(TakeWhileSubscriber, _super);
- function TakeWhileSubscriber(destination, predicate) {
- _super.call(this, destination);
- this.predicate = predicate;
- this.index = 0;
- }
- TakeWhileSubscriber.prototype._next = function (value) {
- var destination = this.destination;
- var result;
- try {
- result = this.predicate(value, this.index++);
- }
- catch (err) {
- destination.error(err);
- return;
- }
- this.nextOrComplete(value, result);
- };
- TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {
- var destination = this.destination;
- if (Boolean(predicateResult)) {
- destination.next(value);
- }
- else {
- destination.complete();
- }
- };
- return TakeWhileSubscriber;
- }(Subscriber));
-
- /**
- * Emits values emitted by the source Observable so long as each value satisfies
- * the given `predicate`, and then completes as soon as this `predicate` is not
- * satisfied.
- *
- * <span class="informal">Takes values from the source only while they pass the
- * condition given. When the first value does not satisfy, it completes.</span>
- *
- * <img src="./img/takeWhile.png" width="100%">
- *
- * `takeWhile` subscribes and begins mirroring the source Observable. Each value
- * emitted on the source is given to the `predicate` function which returns a
- * boolean, representing a condition to be satisfied by the source values. The
- * output Observable emits the source values until such time as the `predicate`
- * returns false, at which point `takeWhile` stops mirroring the source
- * Observable and completes the output Observable.
- *
- * @example <caption>Emit click events only while the clientX property is greater than 200</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.takeWhile(ev => ev.clientX > 200);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link take}
- * @see {@link takeLast}
- * @see {@link takeUntil}
- * @see {@link skip}
- *
- * @param {function(value: T, index: number): boolean} predicate A function that
- * evaluates a value emitted by the source Observable and returns a boolean.
- * Also takes the (zero-based) index as the second argument.
- * @return {Observable<T>} An Observable that emits the values from the source
- * Observable so long as each value satisfies the condition defined by the
- * `predicate`, then completes.
- * @method takeWhile
- * @owner Observable
- */
- function takeWhile$$1(predicate) {
- return takeWhile$1(predicate)(this);
- }
-
- Observable.prototype.takeWhile = takeWhile$$1;
-
- var defaultThrottleConfig = {
- leading: true,
- trailing: false
- };
- /**
- * Emits a value from the source Observable, then ignores subsequent source
- * values for a duration determined by another Observable, then repeats this
- * process.
- *
- * <span class="informal">It's like {@link throttleTime}, but the silencing
- * duration is determined by a second Observable.</span>
- *
- * <img src="./img/throttle.png" width="100%">
- *
- * `throttle` emits the source Observable values on the output Observable
- * when its internal timer is disabled, and ignores source values when the timer
- * is enabled. Initially, the timer is disabled. As soon as the first source
- * value arrives, it is forwarded to the output Observable, and then the timer
- * is enabled by calling the `durationSelector` function with the source value,
- * which returns the "duration" Observable. When the duration Observable emits a
- * value or completes, the timer is disabled, and this process repeats for the
- * next source value.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.throttle(ev => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounce}
- * @see {@link delayWhen}
- * @see {@link sample}
- * @see {@link throttleTime}
- *
- * @param {function(value: T): SubscribableOrPromise} durationSelector A function
- * that receives a value from the source Observable, for computing the silencing
- * duration for each source value, returned as an Observable or a Promise.
- * @param {Object} config a configuration object to define `leading` and `trailing` behavior. Defaults
- * to `{ leading: true, trailing: false }`.
- * @return {Observable<T>} An Observable that performs the throttle operation to
- * limit the rate of emissions from the source.
- * @method throttle
- * @owner Observable
- */
- function throttle$1(durationSelector, config) {
- if (config === void 0) { config = defaultThrottleConfig; }
- return function (source) { return source.lift(new ThrottleOperator(durationSelector, config.leading, config.trailing)); };
- }
- var ThrottleOperator = (function () {
- function ThrottleOperator(durationSelector, leading, trailing) {
- this.durationSelector = durationSelector;
- this.leading = leading;
- this.trailing = trailing;
- }
- ThrottleOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
- };
- return ThrottleOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc
- * @ignore
- * @extends {Ignored}
- */
- var ThrottleSubscriber = (function (_super) {
- __extends(ThrottleSubscriber, _super);
- function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
- _super.call(this, destination);
- this.destination = destination;
- this.durationSelector = durationSelector;
- this._leading = _leading;
- this._trailing = _trailing;
- this._hasTrailingValue = false;
- }
- ThrottleSubscriber.prototype._next = function (value) {
- if (this.throttled) {
- if (this._trailing) {
- this._hasTrailingValue = true;
- this._trailingValue = value;
- }
- }
- else {
- var duration = this.tryDurationSelector(value);
- if (duration) {
- this.add(this.throttled = subscribeToResult(this, duration));
- }
- if (this._leading) {
- this.destination.next(value);
- if (this._trailing) {
- this._hasTrailingValue = true;
- this._trailingValue = value;
- }
- }
- }
- };
- ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
- try {
- return this.durationSelector(value);
- }
- catch (err) {
- this.destination.error(err);
- return null;
- }
- };
- /** @deprecated internal use only */ ThrottleSubscriber.prototype._unsubscribe = function () {
- var _a = this, throttled = _a.throttled, _trailingValue = _a._trailingValue, _hasTrailingValue = _a._hasTrailingValue, _trailing = _a._trailing;
- this._trailingValue = null;
- this._hasTrailingValue = false;
- if (throttled) {
- this.remove(throttled);
- this.throttled = null;
- throttled.unsubscribe();
- }
- };
- ThrottleSubscriber.prototype._sendTrailing = function () {
- var _a = this, destination = _a.destination, throttled = _a.throttled, _trailing = _a._trailing, _trailingValue = _a._trailingValue, _hasTrailingValue = _a._hasTrailingValue;
- if (throttled && _trailing && _hasTrailingValue) {
- destination.next(_trailingValue);
- this._trailingValue = null;
- this._hasTrailingValue = false;
- }
- };
- ThrottleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this._sendTrailing();
- this._unsubscribe();
- };
- ThrottleSubscriber.prototype.notifyComplete = function () {
- this._sendTrailing();
- this._unsubscribe();
- };
- return ThrottleSubscriber;
- }(OuterSubscriber));
-
- /**
- * Emits a value from the source Observable, then ignores subsequent source
- * values for a duration determined by another Observable, then repeats this
- * process.
- *
- * <span class="informal">It's like {@link throttleTime}, but the silencing
- * duration is determined by a second Observable.</span>
- *
- * <img src="./img/throttle.png" width="100%">
- *
- * `throttle` emits the source Observable values on the output Observable
- * when its internal timer is disabled, and ignores source values when the timer
- * is enabled. Initially, the timer is disabled. As soon as the first source
- * value arrives, it is forwarded to the output Observable, and then the timer
- * is enabled by calling the `durationSelector` function with the source value,
- * which returns the "duration" Observable. When the duration Observable emits a
- * value or completes, the timer is disabled, and this process repeats for the
- * next source value.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.throttle(ev => Rx.Observable.interval(1000));
- * result.subscribe(x => console.log(x));
- *
- * @see {@link audit}
- * @see {@link debounce}
- * @see {@link delayWhen}
- * @see {@link sample}
- * @see {@link throttleTime}
- *
- * @param {function(value: T): SubscribableOrPromise} durationSelector A function
- * that receives a value from the source Observable, for computing the silencing
- * duration for each source value, returned as an Observable or a Promise.
- * @param {Object} config a configuration object to define `leading` and `trailing` behavior. Defaults
- * to `{ leading: true, trailing: false }`.
- * @return {Observable<T>} An Observable that performs the throttle operation to
- * limit the rate of emissions from the source.
- * @method throttle
- * @owner Observable
- */
- function throttle$$1(durationSelector, config) {
- if (config === void 0) { config = defaultThrottleConfig; }
- return throttle$1(durationSelector, config)(this);
- }
-
- Observable.prototype.throttle = throttle$$1;
-
- /**
- * Emits a value from the source Observable, then ignores subsequent source
- * values for `duration` milliseconds, then repeats this process.
- *
- * <span class="informal">Lets a value pass, then ignores source values for the
- * next `duration` milliseconds.</span>
- *
- * <img src="./img/throttleTime.png" width="100%">
- *
- * `throttleTime` emits the source Observable values on the output Observable
- * when its internal timer is disabled, and ignores source values when the timer
- * is enabled. Initially, the timer is disabled. As soon as the first source
- * value arrives, it is forwarded to the output Observable, and then the timer
- * is enabled. After `duration` milliseconds (or the time unit determined
- * internally by the optional `scheduler`) has passed, the timer is disabled,
- * and this process repeats for the next source value. Optionally takes a
- * {@link IScheduler} for managing timers.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.throttleTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounceTime}
- * @see {@link delay}
- * @see {@link sampleTime}
- * @see {@link throttle}
- *
- * @param {number} duration Time to wait before emitting another value after
- * emitting the last value, measured in milliseconds or the time unit determined
- * internally by the optional `scheduler`.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the throttling.
- * @return {Observable<T>} An Observable that performs the throttle operation to
- * limit the rate of emissions from the source.
- * @method throttleTime
- * @owner Observable
- */
- function throttleTime$1(duration, scheduler, config) {
- if (scheduler === void 0) { scheduler = async; }
- if (config === void 0) { config = defaultThrottleConfig; }
- return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
- }
- var ThrottleTimeOperator = (function () {
- function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
- this.duration = duration;
- this.scheduler = scheduler;
- this.leading = leading;
- this.trailing = trailing;
- }
- ThrottleTimeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
- };
- return ThrottleTimeOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ThrottleTimeSubscriber = (function (_super) {
- __extends(ThrottleTimeSubscriber, _super);
- function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
- _super.call(this, destination);
- this.duration = duration;
- this.scheduler = scheduler;
- this.leading = leading;
- this.trailing = trailing;
- this._hasTrailingValue = false;
- this._trailingValue = null;
- }
- ThrottleTimeSubscriber.prototype._next = function (value) {
- if (this.throttled) {
- if (this.trailing) {
- this._trailingValue = value;
- this._hasTrailingValue = true;
- }
- }
- else {
- this.add(this.throttled = this.scheduler.schedule(dispatchNext$4, this.duration, { subscriber: this }));
- if (this.leading) {
- this.destination.next(value);
- }
- }
- };
- ThrottleTimeSubscriber.prototype.clearThrottle = function () {
- var throttled = this.throttled;
- if (throttled) {
- if (this.trailing && this._hasTrailingValue) {
- this.destination.next(this._trailingValue);
- this._trailingValue = null;
- this._hasTrailingValue = false;
- }
- throttled.unsubscribe();
- this.remove(throttled);
- this.throttled = null;
- }
- };
- return ThrottleTimeSubscriber;
- }(Subscriber));
- function dispatchNext$4(arg) {
- var subscriber = arg.subscriber;
- subscriber.clearThrottle();
- }
-
- /**
- * Emits a value from the source Observable, then ignores subsequent source
- * values for `duration` milliseconds, then repeats this process.
- *
- * <span class="informal">Lets a value pass, then ignores source values for the
- * next `duration` milliseconds.</span>
- *
- * <img src="./img/throttleTime.png" width="100%">
- *
- * `throttleTime` emits the source Observable values on the output Observable
- * when its internal timer is disabled, and ignores source values when the timer
- * is enabled. Initially, the timer is disabled. As soon as the first source
- * value arrives, it is forwarded to the output Observable, and then the timer
- * is enabled. After `duration` milliseconds (or the time unit determined
- * internally by the optional `scheduler`) has passed, the timer is disabled,
- * and this process repeats for the next source value. Optionally takes a
- * {@link IScheduler} for managing timers.
- *
- * @example <caption>Emit clicks at a rate of at most one click per second</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.throttleTime(1000);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link auditTime}
- * @see {@link debounceTime}
- * @see {@link delay}
- * @see {@link sampleTime}
- * @see {@link throttle}
- *
- * @param {number} duration Time to wait before emitting another value after
- * emitting the last value, measured in milliseconds or the time unit determined
- * internally by the optional `scheduler`.
- * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
- * managing the timers that handle the throttling.
- * @return {Observable<T>} An Observable that performs the throttle operation to
- * limit the rate of emissions from the source.
- * @method throttleTime
- * @owner Observable
- */
- function throttleTime$$1(duration, scheduler, config) {
- if (scheduler === void 0) { scheduler = async; }
- if (config === void 0) { config = defaultThrottleConfig; }
- return throttleTime$1(duration, scheduler, config)(this);
- }
-
- Observable.prototype.throttleTime = throttleTime$$1;
-
- function timeInterval$1(scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return function (source) { return source.lift(new TimeIntervalOperator(scheduler)); };
- }
- var TimeInterval = (function () {
- function TimeInterval(value, interval) {
- this.value = value;
- this.interval = interval;
- }
- return TimeInterval;
- }());
-
- var TimeIntervalOperator = (function () {
- function TimeIntervalOperator(scheduler) {
- this.scheduler = scheduler;
- }
- TimeIntervalOperator.prototype.call = function (observer, source) {
- return source.subscribe(new TimeIntervalSubscriber(observer, this.scheduler));
- };
- return TimeIntervalOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TimeIntervalSubscriber = (function (_super) {
- __extends(TimeIntervalSubscriber, _super);
- function TimeIntervalSubscriber(destination, scheduler) {
- _super.call(this, destination);
- this.scheduler = scheduler;
- this.lastTime = 0;
- this.lastTime = scheduler.now();
- }
- TimeIntervalSubscriber.prototype._next = function (value) {
- var now = this.scheduler.now();
- var span = now - this.lastTime;
- this.lastTime = now;
- this.destination.next(new TimeInterval(value, span));
- };
- return TimeIntervalSubscriber;
- }(Subscriber));
-
- /**
- * @param scheduler
- * @return {Observable<TimeInterval<any>>|WebSocketSubject<T>|Observable<T>}
- * @method timeInterval
- * @owner Observable
- */
- function timeInterval$$1(scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return timeInterval$1(scheduler)(this);
- }
-
- Observable.prototype.timeInterval = timeInterval$$1;
-
- /**
- * An error thrown when duetime elapses.
- *
- * @see {@link timeout}
- *
- * @class TimeoutError
- */
- var TimeoutError = (function (_super) {
- __extends(TimeoutError, _super);
- function TimeoutError() {
- var err = _super.call(this, 'Timeout has occurred');
- this.name = err.name = 'TimeoutError';
- this.stack = err.stack;
- this.message = err.message;
- }
- return TimeoutError;
- }(Error));
-
- /**
- *
- * Errors if Observable does not emit a value in given time span.
- *
- * <span class="informal">Timeouts on Observable that doesn't emit values fast enough.</span>
- *
- * <img src="./img/timeout.png" width="100%">
- *
- * `timeout` operator accepts as an argument either a number or a Date.
- *
- * If number was provided, it returns an Observable that behaves like a source
- * Observable, unless there is a period of time where there is no value emitted.
- * So if you provide `100` as argument and first value comes after 50ms from
- * the moment of subscription, this value will be simply re-emitted by the resulting
- * Observable. If however after that 100ms passes without a second value being emitted,
- * stream will end with an error and source Observable will be unsubscribed.
- * These checks are performed throughout whole lifecycle of Observable - from the moment
- * it was subscribed to, until it completes or errors itself. Thus every value must be
- * emitted within specified period since previous value.
- *
- * If provided argument was Date, returned Observable behaves differently. It throws
- * if Observable did not complete before provided Date. This means that periods between
- * emission of particular values do not matter in this case. If Observable did not complete
- * before provided Date, source Observable will be unsubscribed. Other than that, resulting
- * stream behaves just as source Observable.
- *
- * `timeout` accepts also a Scheduler as a second parameter. It is used to schedule moment (or moments)
- * when returned Observable will check if source stream emitted value or completed.
- *
- * @example <caption>Check if ticks are emitted within certain timespan</caption>
- * const seconds = Rx.Observable.interval(1000);
- *
- * seconds.timeout(1100) // Let's use bigger timespan to be safe,
- * // since `interval` might fire a bit later then scheduled.
- * .subscribe(
- * value => console.log(value), // Will emit numbers just as regular `interval` would.
- * err => console.log(err) // Will never be called.
- * );
- *
- * seconds.timeout(900).subscribe(
- * value => console.log(value), // Will never be called.
- * err => console.log(err) // Will emit error before even first value is emitted,
- * // since it did not arrive within 900ms period.
- * );
- *
- * @example <caption>Use Date to check if Observable completed</caption>
- * const seconds = Rx.Observable.interval(1000);
- *
- * seconds.timeout(new Date("December 17, 2020 03:24:00"))
- * .subscribe(
- * value => console.log(value), // Will emit values as regular `interval` would
- * // until December 17, 2020 at 03:24:00.
- * err => console.log(err) // On December 17, 2020 at 03:24:00 it will emit an error,
- * // since Observable did not complete by then.
- * );
- *
- * @see {@link timeoutWith}
- *
- * @param {number|Date} due Number specifying period within which Observable must emit values
- * or Date specifying before when Observable should complete
- * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
- * @return {Observable<T>} Observable that mirrors behaviour of source, unless timeout checks fail.
- * @method timeout
- * @owner Observable
- */
- function timeout$1(due, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- var absoluteTimeout = isDate(due);
- var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
- return function (source) { return source.lift(new TimeoutOperator(waitFor, absoluteTimeout, scheduler, new TimeoutError())); };
- }
- var TimeoutOperator = (function () {
- function TimeoutOperator(waitFor, absoluteTimeout, scheduler, errorInstance) {
- this.waitFor = waitFor;
- this.absoluteTimeout = absoluteTimeout;
- this.scheduler = scheduler;
- this.errorInstance = errorInstance;
- }
- TimeoutOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new TimeoutSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.scheduler, this.errorInstance));
- };
- return TimeoutOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TimeoutSubscriber = (function (_super) {
- __extends(TimeoutSubscriber, _super);
- function TimeoutSubscriber(destination, absoluteTimeout, waitFor, scheduler, errorInstance) {
- _super.call(this, destination);
- this.absoluteTimeout = absoluteTimeout;
- this.waitFor = waitFor;
- this.scheduler = scheduler;
- this.errorInstance = errorInstance;
- this.action = null;
- this.scheduleTimeout();
- }
- TimeoutSubscriber.dispatchTimeout = function (subscriber) {
- subscriber.error(subscriber.errorInstance);
- };
- TimeoutSubscriber.prototype.scheduleTimeout = function () {
- var action = this.action;
- if (action) {
- // Recycle the action if we've already scheduled one. All the production
- // Scheduler Actions mutate their state/delay time and return themeselves.
- // VirtualActions are immutable, so they create and return a clone. In this
- // case, we need to set the action reference to the most recent VirtualAction,
- // to ensure that's the one we clone from next time.
- this.action = action.schedule(this, this.waitFor);
- }
- else {
- this.add(this.action = this.scheduler.schedule(TimeoutSubscriber.dispatchTimeout, this.waitFor, this));
- }
- };
- TimeoutSubscriber.prototype._next = function (value) {
- if (!this.absoluteTimeout) {
- this.scheduleTimeout();
- }
- _super.prototype._next.call(this, value);
- };
- /** @deprecated internal use only */ TimeoutSubscriber.prototype._unsubscribe = function () {
- this.action = null;
- this.scheduler = null;
- this.errorInstance = null;
- };
- return TimeoutSubscriber;
- }(Subscriber));
-
- /**
- *
- * Errors if Observable does not emit a value in given time span.
- *
- * <span class="informal">Timeouts on Observable that doesn't emit values fast enough.</span>
- *
- * <img src="./img/timeout.png" width="100%">
- *
- * `timeout` operator accepts as an argument either a number or a Date.
- *
- * If number was provided, it returns an Observable that behaves like a source
- * Observable, unless there is a period of time where there is no value emitted.
- * So if you provide `100` as argument and first value comes after 50ms from
- * the moment of subscription, this value will be simply re-emitted by the resulting
- * Observable. If however after that 100ms passes without a second value being emitted,
- * stream will end with an error and source Observable will be unsubscribed.
- * These checks are performed throughout whole lifecycle of Observable - from the moment
- * it was subscribed to, until it completes or errors itself. Thus every value must be
- * emitted within specified period since previous value.
- *
- * If provided argument was Date, returned Observable behaves differently. It throws
- * if Observable did not complete before provided Date. This means that periods between
- * emission of particular values do not matter in this case. If Observable did not complete
- * before provided Date, source Observable will be unsubscribed. Other than that, resulting
- * stream behaves just as source Observable.
- *
- * `timeout` accepts also a Scheduler as a second parameter. It is used to schedule moment (or moments)
- * when returned Observable will check if source stream emitted value or completed.
- *
- * @example <caption>Check if ticks are emitted within certain timespan</caption>
- * const seconds = Rx.Observable.interval(1000);
- *
- * seconds.timeout(1100) // Let's use bigger timespan to be safe,
- * // since `interval` might fire a bit later then scheduled.
- * .subscribe(
- * value => console.log(value), // Will emit numbers just as regular `interval` would.
- * err => console.log(err) // Will never be called.
- * );
- *
- * seconds.timeout(900).subscribe(
- * value => console.log(value), // Will never be called.
- * err => console.log(err) // Will emit error before even first value is emitted,
- * // since it did not arrive within 900ms period.
- * );
- *
- * @example <caption>Use Date to check if Observable completed</caption>
- * const seconds = Rx.Observable.interval(1000);
- *
- * seconds.timeout(new Date("December 17, 2020 03:24:00"))
- * .subscribe(
- * value => console.log(value), // Will emit values as regular `interval` would
- * // until December 17, 2020 at 03:24:00.
- * err => console.log(err) // On December 17, 2020 at 03:24:00 it will emit an error,
- * // since Observable did not complete by then.
- * );
- *
- * @see {@link timeoutWith}
- *
- * @param {number|Date} due Number specifying period within which Observable must emit values
- * or Date specifying before when Observable should complete
- * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
- * @return {Observable<T>} Observable that mirrors behaviour of source, unless timeout checks fail.
- * @method timeout
- * @owner Observable
- */
- function timeout$$1(due, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return timeout$1(due, scheduler)(this);
- }
-
- Observable.prototype.timeout = timeout$$1;
-
- /* tslint:enable:max-line-length */
- /**
- *
- * Errors if Observable does not emit a value in given time span, in case of which
- * subscribes to the second Observable.
- *
- * <span class="informal">It's a version of `timeout` operator that let's you specify fallback Observable.</span>
- *
- * <img src="./img/timeoutWith.png" width="100%">
- *
- * `timeoutWith` is a variation of `timeout` operator. It behaves exactly the same,
- * still accepting as a first argument either a number or a Date, which control - respectively -
- * when values of source Observable should be emitted or when it should complete.
- *
- * The only difference is that it accepts a second, required parameter. This parameter
- * should be an Observable which will be subscribed when source Observable fails any timeout check.
- * So whenever regular `timeout` would emit an error, `timeoutWith` will instead start re-emitting
- * values from second Observable. Note that this fallback Observable is not checked for timeouts
- * itself, so it can emit values and complete at arbitrary points in time. From the moment of a second
- * subscription, Observable returned from `timeoutWith` simply mirrors fallback stream. When that
- * stream completes, it completes as well.
- *
- * Scheduler, which in case of `timeout` is provided as as second argument, can be still provided
- * here - as a third, optional parameter. It still is used to schedule timeout checks and -
- * as a consequence - when second Observable will be subscribed, since subscription happens
- * immediately after failing check.
- *
- * @example <caption>Add fallback observable</caption>
- * const seconds = Rx.Observable.interval(1000);
- * const minutes = Rx.Observable.interval(60 * 1000);
- *
- * seconds.timeoutWith(900, minutes)
- * .subscribe(
- * value => console.log(value), // After 900ms, will start emitting `minutes`,
- * // since first value of `seconds` will not arrive fast enough.
- * err => console.log(err) // Would be called after 900ms in case of `timeout`,
- * // but here will never be called.
- * );
- *
- * @param {number|Date} due Number specifying period within which Observable must emit values
- * or Date specifying before when Observable should complete
- * @param {Observable<T>} withObservable Observable which will be subscribed if source fails timeout check.
- * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
- * @return {Observable<T>} Observable that mirrors behaviour of source or, when timeout check fails, of an Observable
- * passed as a second parameter.
- * @method timeoutWith
- * @owner Observable
- */
- function timeoutWith$1(due, withObservable, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return function (source) {
- var absoluteTimeout = isDate(due);
- var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
- return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
- };
- }
- var TimeoutWithOperator = (function () {
- function TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler) {
- this.waitFor = waitFor;
- this.absoluteTimeout = absoluteTimeout;
- this.withObservable = withObservable;
- this.scheduler = scheduler;
- }
- TimeoutWithOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
- };
- return TimeoutWithOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var TimeoutWithSubscriber = (function (_super) {
- __extends(TimeoutWithSubscriber, _super);
- function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
- _super.call(this, destination);
- this.absoluteTimeout = absoluteTimeout;
- this.waitFor = waitFor;
- this.withObservable = withObservable;
- this.scheduler = scheduler;
- this.action = null;
- this.scheduleTimeout();
- }
- TimeoutWithSubscriber.dispatchTimeout = function (subscriber) {
- var withObservable = subscriber.withObservable;
- subscriber._unsubscribeAndRecycle();
- subscriber.add(subscribeToResult(subscriber, withObservable));
- };
- TimeoutWithSubscriber.prototype.scheduleTimeout = function () {
- var action = this.action;
- if (action) {
- // Recycle the action if we've already scheduled one. All the production
- // Scheduler Actions mutate their state/delay time and return themeselves.
- // VirtualActions are immutable, so they create and return a clone. In this
- // case, we need to set the action reference to the most recent VirtualAction,
- // to ensure that's the one we clone from next time.
- this.action = action.schedule(this, this.waitFor);
- }
- else {
- this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
- }
- };
- TimeoutWithSubscriber.prototype._next = function (value) {
- if (!this.absoluteTimeout) {
- this.scheduleTimeout();
- }
- _super.prototype._next.call(this, value);
- };
- /** @deprecated internal use only */ TimeoutWithSubscriber.prototype._unsubscribe = function () {
- this.action = null;
- this.scheduler = null;
- this.withObservable = null;
- };
- return TimeoutWithSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- *
- * Errors if Observable does not emit a value in given time span, in case of which
- * subscribes to the second Observable.
- *
- * <span class="informal">It's a version of `timeout` operator that let's you specify fallback Observable.</span>
- *
- * <img src="./img/timeoutWith.png" width="100%">
- *
- * `timeoutWith` is a variation of `timeout` operator. It behaves exactly the same,
- * still accepting as a first argument either a number or a Date, which control - respectively -
- * when values of source Observable should be emitted or when it should complete.
- *
- * The only difference is that it accepts a second, required parameter. This parameter
- * should be an Observable which will be subscribed when source Observable fails any timeout check.
- * So whenever regular `timeout` would emit an error, `timeoutWith` will instead start re-emitting
- * values from second Observable. Note that this fallback Observable is not checked for timeouts
- * itself, so it can emit values and complete at arbitrary points in time. From the moment of a second
- * subscription, Observable returned from `timeoutWith` simply mirrors fallback stream. When that
- * stream completes, it completes as well.
- *
- * Scheduler, which in case of `timeout` is provided as as second argument, can be still provided
- * here - as a third, optional parameter. It still is used to schedule timeout checks and -
- * as a consequence - when second Observable will be subscribed, since subscription happens
- * immediately after failing check.
- *
- * @example <caption>Add fallback observable</caption>
- * const seconds = Rx.Observable.interval(1000);
- * const minutes = Rx.Observable.interval(60 * 1000);
- *
- * seconds.timeoutWith(900, minutes)
- * .subscribe(
- * value => console.log(value), // After 900ms, will start emitting `minutes`,
- * // since first value of `seconds` will not arrive fast enough.
- * err => console.log(err) // Would be called after 900ms in case of `timeout`,
- * // but here will never be called.
- * );
- *
- * @param {number|Date} due Number specifying period within which Observable must emit values
- * or Date specifying before when Observable should complete
- * @param {Observable<T>} withObservable Observable which will be subscribed if source fails timeout check.
- * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
- * @return {Observable<T>} Observable that mirrors behaviour of source or, when timeout check fails, of an Observable
- * passed as a second parameter.
- * @method timeoutWith
- * @owner Observable
- */
- function timeoutWith$$1(due, withObservable, scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return timeoutWith$1(due, withObservable, scheduler)(this);
- }
-
- Observable.prototype.timeoutWith = timeoutWith$$1;
-
- /**
- * @param scheduler
- * @return {Observable<Timestamp<any>>|WebSocketSubject<T>|Observable<T>}
- * @method timestamp
- * @owner Observable
- */
- function timestamp$1(scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return map(function (value) { return new Timestamp(value, scheduler.now()); });
- // return (source: Observable<T>) => source.lift(new TimestampOperator(scheduler));
- }
- var Timestamp = (function () {
- function Timestamp(value, timestamp) {
- this.value = value;
- this.timestamp = timestamp;
- }
- return Timestamp;
- }());
-
- /**
- * @param scheduler
- * @return {Observable<Timestamp<any>>|WebSocketSubject<T>|Observable<T>}
- * @method timestamp
- * @owner Observable
- */
- function timestamp$$1(scheduler) {
- if (scheduler === void 0) { scheduler = async; }
- return timestamp$1(scheduler)(this);
- }
-
- Observable.prototype.timestamp = timestamp$$1;
-
- function toArrayReducer(arr, item, index) {
- if (index === 0) {
- return [item];
- }
- arr.push(item);
- return arr;
- }
- function toArray$1() {
- return reduce(toArrayReducer, []);
- }
-
- /**
- * Collects all source emissions and emits them as an array when the source completes.
- *
- * <span class="informal">Get all values inside an array when the source completes</span>
- *
- * <img src="./img/toArray.png" width="100%">
- *
- * `toArray` will wait until the source Observable completes
- * before emitting the array containing all emissions.
- * When the source Observable errors no array will be emitted.
- *
- * @example <caption>Create array from input</caption>
- * const input = Rx.Observable.interval(100).take(4);
- *
- * input.toArray()
- * .subscribe(arr => console.log(arr)); // [0,1,2,3]
- *
- * @see {@link buffer}
- *
- * @return {Observable<any[]>|WebSocketSubject<T>|Observable<T>}
- * @method toArray
- * @owner Observable
- */
- function toArray$$1() {
- return toArray$1()(this);
- }
-
- Observable.prototype.toArray = toArray$$1;
-
- // HACK: does nothing, because `toPromise` now lives on the `Observable` itself.
- // leaving this module here to prevent breakage.
-
- /**
- * Branch out the source Observable values as a nested Observable whenever
- * `windowBoundaries` emits.
- *
- * <span class="informal">It's like {@link buffer}, but emits a nested Observable
- * instead of an array.</span>
- *
- * <img src="./img/window.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits connected, non-overlapping
- * windows. It emits the current window and opens a new one whenever the
- * Observable `windowBoundaries` emits an item. Because each window is an
- * Observable, the output is a higher-order Observable.
- *
- * @example <caption>In every window of 1 second each, emit at most 2 click events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var interval = Rx.Observable.interval(1000);
- * var result = clicks.window(interval)
- * .map(win => win.take(2)) // each window has at most 2 emissions
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @see {@link windowCount}
- * @see {@link windowTime}
- * @see {@link windowToggle}
- * @see {@link windowWhen}
- * @see {@link buffer}
- *
- * @param {Observable<any>} windowBoundaries An Observable that completes the
- * previous window and starts a new window.
- * @return {Observable<Observable<T>>} An Observable of windows, which are
- * Observables emitting values of the source Observable.
- * @method window
- * @owner Observable
- */
- function window$2(windowBoundaries) {
- return function windowOperatorFunction(source) {
- return source.lift(new WindowOperator(windowBoundaries));
- };
- }
- var WindowOperator = (function () {
- function WindowOperator(windowBoundaries) {
- this.windowBoundaries = windowBoundaries;
- }
- WindowOperator.prototype.call = function (subscriber, source) {
- var windowSubscriber = new WindowSubscriber(subscriber);
- var sourceSubscription = source.subscribe(windowSubscriber);
- if (!sourceSubscription.closed) {
- windowSubscriber.add(subscribeToResult(windowSubscriber, this.windowBoundaries));
- }
- return sourceSubscription;
- };
- return WindowOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var WindowSubscriber = (function (_super) {
- __extends(WindowSubscriber, _super);
- function WindowSubscriber(destination) {
- _super.call(this, destination);
- this.window = new Subject();
- destination.next(this.window);
- }
- WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.openWindow();
- };
- WindowSubscriber.prototype.notifyError = function (error, innerSub) {
- this._error(error);
- };
- WindowSubscriber.prototype.notifyComplete = function (innerSub) {
- this._complete();
- };
- WindowSubscriber.prototype._next = function (value) {
- this.window.next(value);
- };
- WindowSubscriber.prototype._error = function (err) {
- this.window.error(err);
- this.destination.error(err);
- };
- WindowSubscriber.prototype._complete = function () {
- this.window.complete();
- this.destination.complete();
- };
- /** @deprecated internal use only */ WindowSubscriber.prototype._unsubscribe = function () {
- this.window = null;
- };
- WindowSubscriber.prototype.openWindow = function () {
- var prevWindow = this.window;
- if (prevWindow) {
- prevWindow.complete();
- }
- var destination = this.destination;
- var newWindow = this.window = new Subject();
- destination.next(newWindow);
- };
- return WindowSubscriber;
- }(OuterSubscriber));
-
- /**
- * Branch out the source Observable values as a nested Observable whenever
- * `windowBoundaries` emits.
- *
- * <span class="informal">It's like {@link buffer}, but emits a nested Observable
- * instead of an array.</span>
- *
- * <img src="./img/window.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits connected, non-overlapping
- * windows. It emits the current window and opens a new one whenever the
- * Observable `windowBoundaries` emits an item. Because each window is an
- * Observable, the output is a higher-order Observable.
- *
- * @example <caption>In every window of 1 second each, emit at most 2 click events</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var interval = Rx.Observable.interval(1000);
- * var result = clicks.window(interval)
- * .map(win => win.take(2)) // each window has at most 2 emissions
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @see {@link windowCount}
- * @see {@link windowTime}
- * @see {@link windowToggle}
- * @see {@link windowWhen}
- * @see {@link buffer}
- *
- * @param {Observable<any>} windowBoundaries An Observable that completes the
- * previous window and starts a new window.
- * @return {Observable<Observable<T>>} An Observable of windows, which are
- * Observables emitting values of the source Observable.
- * @method window
- * @owner Observable
- */
- function window$1(windowBoundaries) {
- return window$2(windowBoundaries)(this);
- }
-
- Observable.prototype.window = window$1;
-
- /**
- * Branch out the source Observable values as a nested Observable with each
- * nested Observable emitting at most `windowSize` values.
- *
- * <span class="informal">It's like {@link bufferCount}, but emits a nested
- * Observable instead of an array.</span>
- *
- * <img src="./img/windowCount.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits windows every `startWindowEvery`
- * items, each containing no more than `windowSize` items. When the source
- * Observable completes or encounters an error, the output Observable emits
- * the current window and propagates the notification from the source
- * Observable. If `startWindowEvery` is not provided, then new windows are
- * started immediately at the start of the source and when each window completes
- * with size `windowSize`.
- *
- * @example <caption>Ignore every 3rd click event, starting from the first one</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.windowCount(3)
- * .map(win => win.skip(1)) // skip first of every 3 clicks
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Ignore every 3rd click event, starting from the third one</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.windowCount(2, 3)
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @see {@link window}
- * @see {@link windowTime}
- * @see {@link windowToggle}
- * @see {@link windowWhen}
- * @see {@link bufferCount}
- *
- * @param {number} windowSize The maximum number of values emitted by each
- * window.
- * @param {number} [startWindowEvery] Interval at which to start a new window.
- * For example if `startWindowEvery` is `2`, then a new window will be started
- * on every other value from the source. A new window is started at the
- * beginning of the source by default.
- * @return {Observable<Observable<T>>} An Observable of windows, which in turn
- * are Observable of values.
- * @method windowCount
- * @owner Observable
- */
- function windowCount$1(windowSize, startWindowEvery) {
- if (startWindowEvery === void 0) { startWindowEvery = 0; }
- return function windowCountOperatorFunction(source) {
- return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
- };
- }
- var WindowCountOperator = (function () {
- function WindowCountOperator(windowSize, startWindowEvery) {
- this.windowSize = windowSize;
- this.startWindowEvery = startWindowEvery;
- }
- WindowCountOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
- };
- return WindowCountOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var WindowCountSubscriber = (function (_super) {
- __extends(WindowCountSubscriber, _super);
- function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
- _super.call(this, destination);
- this.destination = destination;
- this.windowSize = windowSize;
- this.startWindowEvery = startWindowEvery;
- this.windows = [new Subject()];
- this.count = 0;
- destination.next(this.windows[0]);
- }
- WindowCountSubscriber.prototype._next = function (value) {
- var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
- var destination = this.destination;
- var windowSize = this.windowSize;
- var windows = this.windows;
- var len = windows.length;
- for (var i = 0; i < len && !this.closed; i++) {
- windows[i].next(value);
- }
- var c = this.count - windowSize + 1;
- if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
- windows.shift().complete();
- }
- if (++this.count % startWindowEvery === 0 && !this.closed) {
- var window_1 = new Subject();
- windows.push(window_1);
- destination.next(window_1);
- }
- };
- WindowCountSubscriber.prototype._error = function (err) {
- var windows = this.windows;
- if (windows) {
- while (windows.length > 0 && !this.closed) {
- windows.shift().error(err);
- }
- }
- this.destination.error(err);
- };
- WindowCountSubscriber.prototype._complete = function () {
- var windows = this.windows;
- if (windows) {
- while (windows.length > 0 && !this.closed) {
- windows.shift().complete();
- }
- }
- this.destination.complete();
- };
- /** @deprecated internal use only */ WindowCountSubscriber.prototype._unsubscribe = function () {
- this.count = 0;
- this.windows = null;
- };
- return WindowCountSubscriber;
- }(Subscriber));
-
- /**
- * Branch out the source Observable values as a nested Observable with each
- * nested Observable emitting at most `windowSize` values.
- *
- * <span class="informal">It's like {@link bufferCount}, but emits a nested
- * Observable instead of an array.</span>
- *
- * <img src="./img/windowCount.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits windows every `startWindowEvery`
- * items, each containing no more than `windowSize` items. When the source
- * Observable completes or encounters an error, the output Observable emits
- * the current window and propagates the notification from the source
- * Observable. If `startWindowEvery` is not provided, then new windows are
- * started immediately at the start of the source and when each window completes
- * with size `windowSize`.
- *
- * @example <caption>Ignore every 3rd click event, starting from the first one</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.windowCount(3)
- * .map(win => win.skip(1)) // skip first of every 3 clicks
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @example <caption>Ignore every 3rd click event, starting from the third one</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks.windowCount(2, 3)
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @see {@link window}
- * @see {@link windowTime}
- * @see {@link windowToggle}
- * @see {@link windowWhen}
- * @see {@link bufferCount}
- *
- * @param {number} windowSize The maximum number of values emitted by each
- * window.
- * @param {number} [startWindowEvery] Interval at which to start a new window.
- * For example if `startWindowEvery` is `2`, then a new window will be started
- * on every other value from the source. A new window is started at the
- * beginning of the source by default.
- * @return {Observable<Observable<T>>} An Observable of windows, which in turn
- * are Observable of values.
- * @method windowCount
- * @owner Observable
- */
- function windowCount$$1(windowSize, startWindowEvery) {
- if (startWindowEvery === void 0) { startWindowEvery = 0; }
- return windowCount$1(windowSize, startWindowEvery)(this);
- }
-
- Observable.prototype.windowCount = windowCount$$1;
-
- function windowTime$1(windowTimeSpan) {
- var scheduler = async;
- var windowCreationInterval = null;
- var maxWindowSize = Number.POSITIVE_INFINITY;
- if (isScheduler(arguments[3])) {
- scheduler = arguments[3];
- }
- if (isScheduler(arguments[2])) {
- scheduler = arguments[2];
- }
- else if (isNumeric(arguments[2])) {
- maxWindowSize = arguments[2];
- }
- if (isScheduler(arguments[1])) {
- scheduler = arguments[1];
- }
- else if (isNumeric(arguments[1])) {
- windowCreationInterval = arguments[1];
- }
- return function windowTimeOperatorFunction(source) {
- return source.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler));
- };
- }
- var WindowTimeOperator = (function () {
- function WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
- this.windowTimeSpan = windowTimeSpan;
- this.windowCreationInterval = windowCreationInterval;
- this.maxWindowSize = maxWindowSize;
- this.scheduler = scheduler;
- }
- WindowTimeOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new WindowTimeSubscriber(subscriber, this.windowTimeSpan, this.windowCreationInterval, this.maxWindowSize, this.scheduler));
- };
- return WindowTimeOperator;
- }());
- var CountedSubject = (function (_super) {
- __extends(CountedSubject, _super);
- function CountedSubject() {
- _super.apply(this, arguments);
- this._numberOfNextedValues = 0;
- }
- CountedSubject.prototype.next = function (value) {
- this._numberOfNextedValues++;
- _super.prototype.next.call(this, value);
- };
- Object.defineProperty(CountedSubject.prototype, "numberOfNextedValues", {
- get: function () {
- return this._numberOfNextedValues;
- },
- enumerable: true,
- configurable: true
- });
- return CountedSubject;
- }(Subject));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var WindowTimeSubscriber = (function (_super) {
- __extends(WindowTimeSubscriber, _super);
- function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
- _super.call(this, destination);
- this.destination = destination;
- this.windowTimeSpan = windowTimeSpan;
- this.windowCreationInterval = windowCreationInterval;
- this.maxWindowSize = maxWindowSize;
- this.scheduler = scheduler;
- this.windows = [];
- var window = this.openWindow();
- if (windowCreationInterval !== null && windowCreationInterval >= 0) {
- var closeState = { subscriber: this, window: window, context: null };
- var creationState = { windowTimeSpan: windowTimeSpan, windowCreationInterval: windowCreationInterval, subscriber: this, scheduler: scheduler };
- this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState));
- this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState));
- }
- else {
- var timeSpanOnlyState = { subscriber: this, window: window, windowTimeSpan: windowTimeSpan };
- this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState));
- }
- }
- WindowTimeSubscriber.prototype._next = function (value) {
- var windows = this.windows;
- var len = windows.length;
- for (var i = 0; i < len; i++) {
- var window_1 = windows[i];
- if (!window_1.closed) {
- window_1.next(value);
- if (window_1.numberOfNextedValues >= this.maxWindowSize) {
- this.closeWindow(window_1);
- }
- }
- }
- };
- WindowTimeSubscriber.prototype._error = function (err) {
- var windows = this.windows;
- while (windows.length > 0) {
- windows.shift().error(err);
- }
- this.destination.error(err);
- };
- WindowTimeSubscriber.prototype._complete = function () {
- var windows = this.windows;
- while (windows.length > 0) {
- var window_2 = windows.shift();
- if (!window_2.closed) {
- window_2.complete();
- }
- }
- this.destination.complete();
- };
- WindowTimeSubscriber.prototype.openWindow = function () {
- var window = new CountedSubject();
- this.windows.push(window);
- var destination = this.destination;
- destination.next(window);
- return window;
- };
- WindowTimeSubscriber.prototype.closeWindow = function (window) {
- window.complete();
- var windows = this.windows;
- windows.splice(windows.indexOf(window), 1);
- };
- return WindowTimeSubscriber;
- }(Subscriber));
- function dispatchWindowTimeSpanOnly(state) {
- var subscriber = state.subscriber, windowTimeSpan = state.windowTimeSpan, window = state.window;
- if (window) {
- subscriber.closeWindow(window);
- }
- state.window = subscriber.openWindow();
- this.schedule(state, windowTimeSpan);
- }
- function dispatchWindowCreation(state) {
- var windowTimeSpan = state.windowTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler, windowCreationInterval = state.windowCreationInterval;
- var window = subscriber.openWindow();
- var action = this;
- var context = { action: action, subscription: null };
- var timeSpanState = { subscriber: subscriber, window: window, context: context };
- context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState);
- action.add(context.subscription);
- action.schedule(state, windowCreationInterval);
- }
- function dispatchWindowClose(state) {
- var subscriber = state.subscriber, window = state.window, context = state.context;
- if (context && context.action && context.subscription) {
- context.action.remove(context.subscription);
- }
- subscriber.closeWindow(window);
- }
-
- function windowTime$$1(windowTimeSpan) {
- var scheduler = async;
- var windowCreationInterval = null;
- var maxWindowSize = Number.POSITIVE_INFINITY;
- if (isScheduler(arguments[3])) {
- scheduler = arguments[3];
- }
- if (isScheduler(arguments[2])) {
- scheduler = arguments[2];
- }
- else if (isNumeric(arguments[2])) {
- maxWindowSize = arguments[2];
- }
- if (isScheduler(arguments[1])) {
- scheduler = arguments[1];
- }
- else if (isNumeric(arguments[1])) {
- windowCreationInterval = arguments[1];
- }
- return windowTime$1(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler)(this);
- }
-
- Observable.prototype.windowTime = windowTime$$1;
-
- /**
- * Branch out the source Observable values as a nested Observable starting from
- * an emission from `openings` and ending when the output of `closingSelector`
- * emits.
- *
- * <span class="informal">It's like {@link bufferToggle}, but emits a nested
- * Observable instead of an array.</span>
- *
- * <img src="./img/windowToggle.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits windows that contain those items
- * emitted by the source Observable between the time when the `openings`
- * Observable emits an item and when the Observable returned by
- * `closingSelector` emits an item.
- *
- * @example <caption>Every other second, emit the click events from the next 500ms</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var openings = Rx.Observable.interval(1000);
- * var result = clicks.windowToggle(openings, i =>
- * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
- * ).mergeAll();
- * result.subscribe(x => console.log(x));
- *
- * @see {@link window}
- * @see {@link windowCount}
- * @see {@link windowTime}
- * @see {@link windowWhen}
- * @see {@link bufferToggle}
- *
- * @param {Observable<O>} openings An observable of notifications to start new
- * windows.
- * @param {function(value: O): Observable} closingSelector A function that takes
- * the value emitted by the `openings` observable and returns an Observable,
- * which, when it emits (either `next` or `complete`), signals that the
- * associated window should complete.
- * @return {Observable<Observable<T>>} An observable of windows, which in turn
- * are Observables.
- * @method windowToggle
- * @owner Observable
- */
- function windowToggle$1(openings, closingSelector) {
- return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
- }
- var WindowToggleOperator = (function () {
- function WindowToggleOperator(openings, closingSelector) {
- this.openings = openings;
- this.closingSelector = closingSelector;
- }
- WindowToggleOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
- };
- return WindowToggleOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var WindowToggleSubscriber = (function (_super) {
- __extends(WindowToggleSubscriber, _super);
- function WindowToggleSubscriber(destination, openings, closingSelector) {
- _super.call(this, destination);
- this.openings = openings;
- this.closingSelector = closingSelector;
- this.contexts = [];
- this.add(this.openSubscription = subscribeToResult(this, openings, openings));
- }
- WindowToggleSubscriber.prototype._next = function (value) {
- var contexts = this.contexts;
- if (contexts) {
- var len = contexts.length;
- for (var i = 0; i < len; i++) {
- contexts[i].window.next(value);
- }
- }
- };
- WindowToggleSubscriber.prototype._error = function (err) {
- var contexts = this.contexts;
- this.contexts = null;
- if (contexts) {
- var len = contexts.length;
- var index = -1;
- while (++index < len) {
- var context = contexts[index];
- context.window.error(err);
- context.subscription.unsubscribe();
- }
- }
- _super.prototype._error.call(this, err);
- };
- WindowToggleSubscriber.prototype._complete = function () {
- var contexts = this.contexts;
- this.contexts = null;
- if (contexts) {
- var len = contexts.length;
- var index = -1;
- while (++index < len) {
- var context = contexts[index];
- context.window.complete();
- context.subscription.unsubscribe();
- }
- }
- _super.prototype._complete.call(this);
- };
- /** @deprecated internal use only */ WindowToggleSubscriber.prototype._unsubscribe = function () {
- var contexts = this.contexts;
- this.contexts = null;
- if (contexts) {
- var len = contexts.length;
- var index = -1;
- while (++index < len) {
- var context = contexts[index];
- context.window.unsubscribe();
- context.subscription.unsubscribe();
- }
- }
- };
- WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- if (outerValue === this.openings) {
- var closingSelector = this.closingSelector;
- var closingNotifier = tryCatch(closingSelector)(innerValue);
- if (closingNotifier === errorObject) {
- return this.error(errorObject.e);
- }
- else {
- var window_1 = new Subject();
- var subscription = new Subscription();
- var context = { window: window_1, subscription: subscription };
- this.contexts.push(context);
- var innerSubscription = subscribeToResult(this, closingNotifier, context);
- if (innerSubscription.closed) {
- this.closeWindow(this.contexts.length - 1);
- }
- else {
- innerSubscription.context = context;
- subscription.add(innerSubscription);
- }
- this.destination.next(window_1);
- }
- }
- else {
- this.closeWindow(this.contexts.indexOf(outerValue));
- }
- };
- WindowToggleSubscriber.prototype.notifyError = function (err) {
- this.error(err);
- };
- WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
- if (inner !== this.openSubscription) {
- this.closeWindow(this.contexts.indexOf(inner.context));
- }
- };
- WindowToggleSubscriber.prototype.closeWindow = function (index) {
- if (index === -1) {
- return;
- }
- var contexts = this.contexts;
- var context = contexts[index];
- var window = context.window, subscription = context.subscription;
- contexts.splice(index, 1);
- window.complete();
- subscription.unsubscribe();
- };
- return WindowToggleSubscriber;
- }(OuterSubscriber));
-
- /**
- * Branch out the source Observable values as a nested Observable starting from
- * an emission from `openings` and ending when the output of `closingSelector`
- * emits.
- *
- * <span class="informal">It's like {@link bufferToggle}, but emits a nested
- * Observable instead of an array.</span>
- *
- * <img src="./img/windowToggle.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits windows that contain those items
- * emitted by the source Observable between the time when the `openings`
- * Observable emits an item and when the Observable returned by
- * `closingSelector` emits an item.
- *
- * @example <caption>Every other second, emit the click events from the next 500ms</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var openings = Rx.Observable.interval(1000);
- * var result = clicks.windowToggle(openings, i =>
- * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
- * ).mergeAll();
- * result.subscribe(x => console.log(x));
- *
- * @see {@link window}
- * @see {@link windowCount}
- * @see {@link windowTime}
- * @see {@link windowWhen}
- * @see {@link bufferToggle}
- *
- * @param {Observable<O>} openings An observable of notifications to start new
- * windows.
- * @param {function(value: O): Observable} closingSelector A function that takes
- * the value emitted by the `openings` observable and returns an Observable,
- * which, when it emits (either `next` or `complete`), signals that the
- * associated window should complete.
- * @return {Observable<Observable<T>>} An observable of windows, which in turn
- * are Observables.
- * @method windowToggle
- * @owner Observable
- */
- function windowToggle$$1(openings, closingSelector) {
- return windowToggle$1(openings, closingSelector)(this);
- }
-
- Observable.prototype.windowToggle = windowToggle$$1;
-
- /**
- * Branch out the source Observable values as a nested Observable using a
- * factory function of closing Observables to determine when to start a new
- * window.
- *
- * <span class="informal">It's like {@link bufferWhen}, but emits a nested
- * Observable instead of an array.</span>
- *
- * <img src="./img/windowWhen.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits connected, non-overlapping windows.
- * It emits the current window and opens a new one whenever the Observable
- * produced by the specified `closingSelector` function emits an item. The first
- * window is opened immediately when subscribing to the output Observable.
- *
- * @example <caption>Emit only the first two clicks events in every window of [1-5] random seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks
- * .windowWhen(() => Rx.Observable.interval(1000 + Math.random() * 4000))
- * .map(win => win.take(2)) // each window has at most 2 emissions
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @see {@link window}
- * @see {@link windowCount}
- * @see {@link windowTime}
- * @see {@link windowToggle}
- * @see {@link bufferWhen}
- *
- * @param {function(): Observable} closingSelector A function that takes no
- * arguments and returns an Observable that signals (on either `next` or
- * `complete`) when to close the previous window and start a new one.
- * @return {Observable<Observable<T>>} An observable of windows, which in turn
- * are Observables.
- * @method windowWhen
- * @owner Observable
- */
- function windowWhen$1(closingSelector) {
- return function windowWhenOperatorFunction(source) {
- return source.lift(new WindowOperator$1(closingSelector));
- };
- }
- var WindowOperator$1 = (function () {
- function WindowOperator(closingSelector) {
- this.closingSelector = closingSelector;
- }
- WindowOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new WindowSubscriber$1(subscriber, this.closingSelector));
- };
- return WindowOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var WindowSubscriber$1 = (function (_super) {
- __extends(WindowSubscriber, _super);
- function WindowSubscriber(destination, closingSelector) {
- _super.call(this, destination);
- this.destination = destination;
- this.closingSelector = closingSelector;
- this.openWindow();
- }
- WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.openWindow(innerSub);
- };
- WindowSubscriber.prototype.notifyError = function (error, innerSub) {
- this._error(error);
- };
- WindowSubscriber.prototype.notifyComplete = function (innerSub) {
- this.openWindow(innerSub);
- };
- WindowSubscriber.prototype._next = function (value) {
- this.window.next(value);
- };
- WindowSubscriber.prototype._error = function (err) {
- this.window.error(err);
- this.destination.error(err);
- this.unsubscribeClosingNotification();
- };
- WindowSubscriber.prototype._complete = function () {
- this.window.complete();
- this.destination.complete();
- this.unsubscribeClosingNotification();
- };
- WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
- if (this.closingNotification) {
- this.closingNotification.unsubscribe();
- }
- };
- WindowSubscriber.prototype.openWindow = function (innerSub) {
- if (innerSub === void 0) { innerSub = null; }
- if (innerSub) {
- this.remove(innerSub);
- innerSub.unsubscribe();
- }
- var prevWindow = this.window;
- if (prevWindow) {
- prevWindow.complete();
- }
- var window = this.window = new Subject();
- this.destination.next(window);
- var closingNotifier = tryCatch(this.closingSelector)();
- if (closingNotifier === errorObject) {
- var err = errorObject.e;
- this.destination.error(err);
- this.window.error(err);
- }
- else {
- this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
- }
- };
- return WindowSubscriber;
- }(OuterSubscriber));
-
- /**
- * Branch out the source Observable values as a nested Observable using a
- * factory function of closing Observables to determine when to start a new
- * window.
- *
- * <span class="informal">It's like {@link bufferWhen}, but emits a nested
- * Observable instead of an array.</span>
- *
- * <img src="./img/windowWhen.png" width="100%">
- *
- * Returns an Observable that emits windows of items it collects from the source
- * Observable. The output Observable emits connected, non-overlapping windows.
- * It emits the current window and opens a new one whenever the Observable
- * produced by the specified `closingSelector` function emits an item. The first
- * window is opened immediately when subscribing to the output Observable.
- *
- * @example <caption>Emit only the first two clicks events in every window of [1-5] random seconds</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var result = clicks
- * .windowWhen(() => Rx.Observable.interval(1000 + Math.random() * 4000))
- * .map(win => win.take(2)) // each window has at most 2 emissions
- * .mergeAll(); // flatten the Observable-of-Observables
- * result.subscribe(x => console.log(x));
- *
- * @see {@link window}
- * @see {@link windowCount}
- * @see {@link windowTime}
- * @see {@link windowToggle}
- * @see {@link bufferWhen}
- *
- * @param {function(): Observable} closingSelector A function that takes no
- * arguments and returns an Observable that signals (on either `next` or
- * `complete`) when to close the previous window and start a new one.
- * @return {Observable<Observable<T>>} An observable of windows, which in turn
- * are Observables.
- * @method windowWhen
- * @owner Observable
- */
- function windowWhen$$1(closingSelector) {
- return windowWhen$1(closingSelector)(this);
- }
-
- Observable.prototype.windowWhen = windowWhen$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * Combines the source Observable with other Observables to create an Observable
- * whose values are calculated from the latest values of each, only when the
- * source emits.
- *
- * <span class="informal">Whenever the source Observable emits a value, it
- * computes a formula using that value plus the latest values from other input
- * Observables, then emits the output of that formula.</span>
- *
- * <img src="./img/withLatestFrom.png" width="100%">
- *
- * `withLatestFrom` combines each value from the source Observable (the
- * instance) with the latest values from the other input Observables only when
- * the source emits a value, optionally using a `project` function to determine
- * the value to be emitted on the output Observable. All input Observables must
- * emit at least one value before the output Observable will emit a value.
- *
- * @example <caption>On every click event, emit an array with the latest timer event plus the click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var timer = Rx.Observable.interval(1000);
- * var result = clicks.withLatestFrom(timer);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link combineLatest}
- *
- * @param {ObservableInput} other An input Observable to combine with the source
- * Observable. More than one input Observables may be given as argument.
- * @param {Function} [project] Projection function for combining values
- * together. Receives all values in order of the Observables passed, where the
- * first parameter is a value from the source Observable. (e.g.
- * `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not
- * passed, arrays will be emitted on the output Observable.
- * @return {Observable} An Observable of projected values from the most recent
- * values from each input Observable, or an array of the most recent values from
- * each input Observable.
- * @method withLatestFrom
- * @owner Observable
- */
- function withLatestFrom$1() {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i - 0] = arguments[_i];
- }
- return function (source) {
- var project;
- if (typeof args[args.length - 1] === 'function') {
- project = args.pop();
- }
- var observables = args;
- return source.lift(new WithLatestFromOperator(observables, project));
- };
- }
- var WithLatestFromOperator = (function () {
- function WithLatestFromOperator(observables, project) {
- this.observables = observables;
- this.project = project;
- }
- WithLatestFromOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
- };
- return WithLatestFromOperator;
- }());
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var WithLatestFromSubscriber = (function (_super) {
- __extends(WithLatestFromSubscriber, _super);
- function WithLatestFromSubscriber(destination, observables, project) {
- _super.call(this, destination);
- this.observables = observables;
- this.project = project;
- this.toRespond = [];
- var len = observables.length;
- this.values = new Array(len);
- for (var i = 0; i < len; i++) {
- this.toRespond.push(i);
- }
- for (var i = 0; i < len; i++) {
- var observable = observables[i];
- this.add(subscribeToResult(this, observable, observable, i));
- }
- }
- WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- this.values[outerIndex] = innerValue;
- var toRespond = this.toRespond;
- if (toRespond.length > 0) {
- var found = toRespond.indexOf(outerIndex);
- if (found !== -1) {
- toRespond.splice(found, 1);
- }
- }
- };
- WithLatestFromSubscriber.prototype.notifyComplete = function () {
- // noop
- };
- WithLatestFromSubscriber.prototype._next = function (value) {
- if (this.toRespond.length === 0) {
- var args = [value].concat(this.values);
- if (this.project) {
- this._tryProject(args);
- }
- else {
- this.destination.next(args);
- }
- }
- };
- WithLatestFromSubscriber.prototype._tryProject = function (args) {
- var result;
- try {
- result = this.project.apply(this, args);
- }
- catch (err) {
- this.destination.error(err);
- return;
- }
- this.destination.next(result);
- };
- return WithLatestFromSubscriber;
- }(OuterSubscriber));
-
- /* tslint:enable:max-line-length */
- /**
- * Combines the source Observable with other Observables to create an Observable
- * whose values are calculated from the latest values of each, only when the
- * source emits.
- *
- * <span class="informal">Whenever the source Observable emits a value, it
- * computes a formula using that value plus the latest values from other input
- * Observables, then emits the output of that formula.</span>
- *
- * <img src="./img/withLatestFrom.png" width="100%">
- *
- * `withLatestFrom` combines each value from the source Observable (the
- * instance) with the latest values from the other input Observables only when
- * the source emits a value, optionally using a `project` function to determine
- * the value to be emitted on the output Observable. All input Observables must
- * emit at least one value before the output Observable will emit a value.
- *
- * @example <caption>On every click event, emit an array with the latest timer event plus the click event</caption>
- * var clicks = Rx.Observable.fromEvent(document, 'click');
- * var timer = Rx.Observable.interval(1000);
- * var result = clicks.withLatestFrom(timer);
- * result.subscribe(x => console.log(x));
- *
- * @see {@link combineLatest}
- *
- * @param {ObservableInput} other An input Observable to combine with the source
- * Observable. More than one input Observables may be given as argument.
- * @param {Function} [project] Projection function for combining values
- * together. Receives all values in order of the Observables passed, where the
- * first parameter is a value from the source Observable. (e.g.
- * `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not
- * passed, arrays will be emitted on the output Observable.
- * @return {Observable} An Observable of projected values from the most recent
- * values from each input Observable, or an array of the most recent values from
- * each input Observable.
- * @method withLatestFrom
- * @owner Observable
- */
- function withLatestFrom$$1() {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i - 0] = arguments[_i];
- }
- return withLatestFrom$1.apply(void 0, args)(this);
- }
-
- Observable.prototype.withLatestFrom = withLatestFrom$$1;
-
- /* tslint:enable:max-line-length */
- /**
- * @param observables
- * @return {Observable<R>}
- * @method zip
- * @owner Observable
- */
- function zipProto() {
- var observables = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- observables[_i - 0] = arguments[_i];
- }
- return zip$1.apply(void 0, observables)(this);
- }
-
- Observable.prototype.zip = zipProto;
-
- function zipAll$1(project) {
- return function (source) { return source.lift(new ZipOperator(project)); };
- }
-
- /**
- * @param project
- * @return {Observable<R>|WebSocketSubject<T>|Observable<T>}
- * @method zipAll
- * @owner Observable
- */
- function zipAll$$1(project) {
- return zipAll$1(project)(this);
- }
-
- Observable.prototype.zipAll = zipAll$$1;
-
- var SubscriptionLog = (function () {
- function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
- if (unsubscribedFrame === void 0) { unsubscribedFrame = Number.POSITIVE_INFINITY; }
- this.subscribedFrame = subscribedFrame;
- this.unsubscribedFrame = unsubscribedFrame;
- }
- return SubscriptionLog;
- }());
-
- var SubscriptionLoggable = (function () {
- function SubscriptionLoggable() {
- this.subscriptions = [];
- }
- SubscriptionLoggable.prototype.logSubscribedFrame = function () {
- this.subscriptions.push(new SubscriptionLog(this.scheduler.now()));
- return this.subscriptions.length - 1;
- };
- SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) {
- var subscriptionLogs = this.subscriptions;
- var oldSubscriptionLog = subscriptionLogs[index];
- subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now());
- };
- return SubscriptionLoggable;
- }());
-
- function applyMixins(derivedCtor, baseCtors) {
- for (var i = 0, len = baseCtors.length; i < len; i++) {
- var baseCtor = baseCtors[i];
- var propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
- for (var j = 0, len2 = propertyKeys.length; j < len2; j++) {
- var name_1 = propertyKeys[j];
- derivedCtor.prototype[name_1] = baseCtor.prototype[name_1];
- }
- }
- }
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var ColdObservable = (function (_super) {
- __extends(ColdObservable, _super);
- function ColdObservable(messages, scheduler) {
- _super.call(this, function (subscriber) {
- var observable = this;
- var index = observable.logSubscribedFrame();
- subscriber.add(new Subscription(function () {
- observable.logUnsubscribedFrame(index);
- }));
- observable.scheduleMessages(subscriber);
- return subscriber;
- });
- this.messages = messages;
- this.subscriptions = [];
- this.scheduler = scheduler;
- }
- ColdObservable.prototype.scheduleMessages = function (subscriber) {
- var messagesLength = this.messages.length;
- for (var i = 0; i < messagesLength; i++) {
- var message = this.messages[i];
- subscriber.add(this.scheduler.schedule(function (_a) {
- var message = _a.message, subscriber = _a.subscriber;
- message.notification.observe(subscriber);
- }, message.frame, { message: message, subscriber: subscriber }));
- }
- };
- return ColdObservable;
- }(Observable));
- applyMixins(ColdObservable, [SubscriptionLoggable]);
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var HotObservable = (function (_super) {
- __extends(HotObservable, _super);
- function HotObservable(messages, scheduler) {
- _super.call(this);
- this.messages = messages;
- this.subscriptions = [];
- this.scheduler = scheduler;
- }
- /** @deprecated internal use only */ HotObservable.prototype._subscribe = function (subscriber) {
- var subject = this;
- var index = subject.logSubscribedFrame();
- subscriber.add(new Subscription(function () {
- subject.logUnsubscribedFrame(index);
- }));
- return _super.prototype._subscribe.call(this, subscriber);
- };
- HotObservable.prototype.setup = function () {
- var subject = this;
- var messagesLength = subject.messages.length;
- /* tslint:disable:no-var-keyword */
- for (var i = 0; i < messagesLength; i++) {
- (function () {
- var message = subject.messages[i];
- /* tslint:enable */
- subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame);
- })();
- }
- };
- return HotObservable;
- }(Subject));
- applyMixins(HotObservable, [SubscriptionLoggable]);
-
- var VirtualTimeScheduler = (function (_super) {
- __extends(VirtualTimeScheduler, _super);
- function VirtualTimeScheduler(SchedulerAction, maxFrames) {
- var _this = this;
- if (SchedulerAction === void 0) { SchedulerAction = VirtualAction; }
- if (maxFrames === void 0) { maxFrames = Number.POSITIVE_INFINITY; }
- _super.call(this, SchedulerAction, function () { return _this.frame; });
- this.maxFrames = maxFrames;
- this.frame = 0;
- this.index = -1;
- }
- /**
- * Prompt the Scheduler to execute all of its queued actions, therefore
- * clearing its queue.
- * @return {void}
- */
- VirtualTimeScheduler.prototype.flush = function () {
- var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
- var error, action;
- while ((action = actions.shift()) && (this.frame = action.delay) <= maxFrames) {
- if (error = action.execute(action.state, action.delay)) {
- break;
- }
- }
- if (error) {
- while (action = actions.shift()) {
- action.unsubscribe();
- }
- throw error;
- }
- };
- VirtualTimeScheduler.frameTimeFactor = 10;
- return VirtualTimeScheduler;
- }(AsyncScheduler));
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var VirtualAction = (function (_super) {
- __extends(VirtualAction, _super);
- function VirtualAction(scheduler, work, index) {
- if (index === void 0) { index = scheduler.index += 1; }
- _super.call(this, scheduler, work);
- this.scheduler = scheduler;
- this.work = work;
- this.index = index;
- this.active = true;
- this.index = scheduler.index = index;
- }
- VirtualAction.prototype.schedule = function (state, delay) {
- if (delay === void 0) { delay = 0; }
- if (!this.id) {
- return _super.prototype.schedule.call(this, state, delay);
- }
- this.active = false;
- // If an action is rescheduled, we save allocations by mutating its state,
- // pushing it to the end of the scheduler queue, and recycling the action.
- // But since the VirtualTimeScheduler is used for testing, VirtualActions
- // must be immutable so they can be inspected later.
- var action = new VirtualAction(this.scheduler, this.work);
- this.add(action);
- return action.schedule(state, delay);
- };
- VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- this.delay = scheduler.frame + delay;
- var actions = scheduler.actions;
- actions.push(this);
- actions.sort(VirtualAction.sortActions);
- return true;
- };
- VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- return undefined;
- };
- VirtualAction.prototype._execute = function (state, delay) {
- if (this.active === true) {
- return _super.prototype._execute.call(this, state, delay);
- }
- };
- VirtualAction.sortActions = function (a, b) {
- if (a.delay === b.delay) {
- if (a.index === b.index) {
- return 0;
- }
- else if (a.index > b.index) {
- return 1;
- }
- else {
- return -1;
- }
- }
- else if (a.delay > b.delay) {
- return 1;
- }
- else {
- return -1;
- }
- };
- return VirtualAction;
- }(AsyncAction));
-
- var defaultMaxFrame = 750;
- var TestScheduler = (function (_super) {
- __extends(TestScheduler, _super);
- function TestScheduler(assertDeepEqual) {
- _super.call(this, VirtualAction, defaultMaxFrame);
- this.assertDeepEqual = assertDeepEqual;
- this.hotObservables = [];
- this.coldObservables = [];
- this.flushTests = [];
- }
- TestScheduler.prototype.createTime = function (marbles) {
- var indexOf = marbles.indexOf('|');
- if (indexOf === -1) {
- throw new Error('marble diagram for time should have a completion marker "|"');
- }
- return indexOf * TestScheduler.frameTimeFactor;
- };
- TestScheduler.prototype.createColdObservable = function (marbles, values, error) {
- if (marbles.indexOf('^') !== -1) {
- throw new Error('cold observable cannot have subscription offset "^"');
- }
- if (marbles.indexOf('!') !== -1) {
- throw new Error('cold observable cannot have unsubscription marker "!"');
- }
- var messages = TestScheduler.parseMarbles(marbles, values, error);
- var cold = new ColdObservable(messages, this);
- this.coldObservables.push(cold);
- return cold;
- };
- TestScheduler.prototype.createHotObservable = function (marbles, values, error) {
- if (marbles.indexOf('!') !== -1) {
- throw new Error('hot observable cannot have unsubscription marker "!"');
- }
- var messages = TestScheduler.parseMarbles(marbles, values, error);
- var subject = new HotObservable(messages, this);
- this.hotObservables.push(subject);
- return subject;
- };
- TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
- var _this = this;
- var messages = [];
- observable.subscribe(function (value) {
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createNext(value) });
- }, function (err) {
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createError(err) });
- }, function () {
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createComplete() });
- });
- return messages;
- };
- TestScheduler.prototype.expectObservable = function (observable, unsubscriptionMarbles) {
- var _this = this;
- if (unsubscriptionMarbles === void 0) { unsubscriptionMarbles = null; }
- var actual = [];
- var flushTest = { actual: actual, ready: false };
- var unsubscriptionFrame = TestScheduler
- .parseMarblesAsSubscriptions(unsubscriptionMarbles).unsubscribedFrame;
- var subscription;
- this.schedule(function () {
- subscription = observable.subscribe(function (x) {
- var value = x;
- // Support Observable-of-Observables
- if (x instanceof Observable) {
- value = _this.materializeInnerObservable(value, _this.frame);
- }
- actual.push({ frame: _this.frame, notification: Notification.createNext(value) });
- }, function (err) {
- actual.push({ frame: _this.frame, notification: Notification.createError(err) });
- }, function () {
- actual.push({ frame: _this.frame, notification: Notification.createComplete() });
- });
- }, 0);
- if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
- this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
- }
- this.flushTests.push(flushTest);
- return {
- toBe: function (marbles, values, errorValue) {
- flushTest.ready = true;
- flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true);
- }
- };
- };
- TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
- var flushTest = { actual: actualSubscriptionLogs, ready: false };
- this.flushTests.push(flushTest);
- return {
- toBe: function (marbles) {
- var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles;
- flushTest.ready = true;
- flushTest.expected = marblesArray.map(function (marbles) {
- return TestScheduler.parseMarblesAsSubscriptions(marbles);
- });
- }
- };
- };
- TestScheduler.prototype.flush = function () {
- var hotObservables = this.hotObservables;
- while (hotObservables.length > 0) {
- hotObservables.shift().setup();
- }
- _super.prototype.flush.call(this);
- var readyFlushTests = this.flushTests.filter(function (test) { return test.ready; });
- while (readyFlushTests.length > 0) {
- var test = readyFlushTests.shift();
- this.assertDeepEqual(test.actual, test.expected);
- }
- };
- TestScheduler.parseMarblesAsSubscriptions = function (marbles) {
- if (typeof marbles !== 'string') {
- return new SubscriptionLog(Number.POSITIVE_INFINITY);
- }
- var len = marbles.length;
- var groupStart = -1;
- var subscriptionFrame = Number.POSITIVE_INFINITY;
- var unsubscriptionFrame = Number.POSITIVE_INFINITY;
- for (var i = 0; i < len; i++) {
- var frame = i * this.frameTimeFactor;
- var c = marbles[i];
- switch (c) {
- case '-':
- case ' ':
- break;
- case '(':
- groupStart = frame;
- break;
- case ')':
- groupStart = -1;
- break;
- case '^':
- if (subscriptionFrame !== Number.POSITIVE_INFINITY) {
- throw new Error('found a second subscription point \'^\' in a ' +
- 'subscription marble diagram. There can only be one.');
- }
- subscriptionFrame = groupStart > -1 ? groupStart : frame;
- break;
- case '!':
- if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
- throw new Error('found a second subscription point \'^\' in a ' +
- 'subscription marble diagram. There can only be one.');
- }
- unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
- break;
- default:
- throw new Error('there can only be \'^\' and \'!\' markers in a ' +
- 'subscription marble diagram. Found instead \'' + c + '\'.');
- }
- }
- if (unsubscriptionFrame < 0) {
- return new SubscriptionLog(subscriptionFrame);
- }
- else {
- return new SubscriptionLog(subscriptionFrame, unsubscriptionFrame);
- }
- };
- TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables) {
- if (materializeInnerObservables === void 0) { materializeInnerObservables = false; }
- if (marbles.indexOf('!') !== -1) {
- throw new Error('conventional marble diagrams cannot have the ' +
- 'unsubscription marker "!"');
- }
- var len = marbles.length;
- var testMessages = [];
- var subIndex = marbles.indexOf('^');
- var frameOffset = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);
- var getValue = typeof values !== 'object' ?
- function (x) { return x; } :
- function (x) {
- // Support Observable-of-Observables
- if (materializeInnerObservables && values[x] instanceof ColdObservable) {
- return values[x].messages;
- }
- return values[x];
- };
- var groupStart = -1;
- for (var i = 0; i < len; i++) {
- var frame = i * this.frameTimeFactor + frameOffset;
- var notification = void 0;
- var c = marbles[i];
- switch (c) {
- case '-':
- case ' ':
- break;
- case '(':
- groupStart = frame;
- break;
- case ')':
- groupStart = -1;
- break;
- case '|':
- notification = Notification.createComplete();
- break;
- case '^':
- break;
- case '#':
- notification = Notification.createError(errorValue || 'error');
- break;
- default:
- notification = Notification.createNext(getValue(c));
- break;
- }
- if (notification) {
- testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification });
- }
- }
- return testMessages;
- };
- return TestScheduler;
- }(VirtualTimeScheduler));
-
- var RequestAnimationFrameDefinition = (function () {
- function RequestAnimationFrameDefinition(root$$1) {
- if (root$$1.requestAnimationFrame) {
- this.cancelAnimationFrame = root$$1.cancelAnimationFrame.bind(root$$1);
- this.requestAnimationFrame = root$$1.requestAnimationFrame.bind(root$$1);
- }
- else if (root$$1.mozRequestAnimationFrame) {
- this.cancelAnimationFrame = root$$1.mozCancelAnimationFrame.bind(root$$1);
- this.requestAnimationFrame = root$$1.mozRequestAnimationFrame.bind(root$$1);
- }
- else if (root$$1.webkitRequestAnimationFrame) {
- this.cancelAnimationFrame = root$$1.webkitCancelAnimationFrame.bind(root$$1);
- this.requestAnimationFrame = root$$1.webkitRequestAnimationFrame.bind(root$$1);
- }
- else if (root$$1.msRequestAnimationFrame) {
- this.cancelAnimationFrame = root$$1.msCancelAnimationFrame.bind(root$$1);
- this.requestAnimationFrame = root$$1.msRequestAnimationFrame.bind(root$$1);
- }
- else if (root$$1.oRequestAnimationFrame) {
- this.cancelAnimationFrame = root$$1.oCancelAnimationFrame.bind(root$$1);
- this.requestAnimationFrame = root$$1.oRequestAnimationFrame.bind(root$$1);
- }
- else {
- this.cancelAnimationFrame = root$$1.clearTimeout.bind(root$$1);
- this.requestAnimationFrame = function (cb) { return root$$1.setTimeout(cb, 1000 / 60); };
- }
- }
- return RequestAnimationFrameDefinition;
- }());
- var AnimationFrame = new RequestAnimationFrameDefinition(_root);
-
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @ignore
- * @extends {Ignored}
- */
- var AnimationFrameAction = (function (_super) {
- __extends(AnimationFrameAction, _super);
- function AnimationFrameAction(scheduler, work) {
- _super.call(this, scheduler, work);
- this.scheduler = scheduler;
- this.work = work;
- }
- AnimationFrameAction.prototype.requestAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- // If delay is greater than 0, request as an async action.
- if (delay !== null && delay > 0) {
- return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
- }
- // Push the action to the end of the scheduler queue.
- scheduler.actions.push(this);
- // If an animation frame has already been requested, don't request another
- // one. If an animation frame hasn't been requested yet, request one. Return
- // the current animation frame request id.
- return scheduler.scheduled || (scheduler.scheduled = AnimationFrame.requestAnimationFrame(scheduler.flush.bind(scheduler, null)));
- };
- AnimationFrameAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
- if (delay === void 0) { delay = 0; }
- // If delay exists and is greater than 0, or if the delay is null (the
- // action wasn't rescheduled) but was originally scheduled as an async
- // action, then recycle as an async action.
- if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
- return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
- }
- // If the scheduler queue is empty, cancel the requested animation frame and
- // set the scheduled flag to undefined so the next AnimationFrameAction will
- // request its own.
- if (scheduler.actions.length === 0) {
- AnimationFrame.cancelAnimationFrame(id);
- scheduler.scheduled = undefined;
- }
- // Return undefined so the action knows to request a new async id if it's rescheduled.
- return undefined;
- };
- return AnimationFrameAction;
- }(AsyncAction));
-
- var AnimationFrameScheduler = (function (_super) {
- __extends(AnimationFrameScheduler, _super);
- function AnimationFrameScheduler() {
- _super.apply(this, arguments);
- }
- AnimationFrameScheduler.prototype.flush = function (action) {
- this.active = true;
- this.scheduled = undefined;
- var actions = this.actions;
- var error;
- var index = -1;
- var count = actions.length;
- action = action || actions.shift();
- do {
- if (error = action.execute(action.state, action.delay)) {
- break;
- }
- } while (++index < count && (action = actions.shift()));
- this.active = false;
- if (error) {
- while (++index < count && (action = actions.shift())) {
- action.unsubscribe();
- }
- throw error;
- }
- };
- return AnimationFrameScheduler;
- }(AsyncScheduler));
-
- /**
- *
- * Animation Frame Scheduler
- *
- * <span class="informal">Perform task when `window.requestAnimationFrame` would fire</span>
- *
- * When `animationFrame` scheduler is used with delay, it will fall back to {@link async} scheduler
- * behaviour.
- *
- * Without delay, `animationFrame` scheduler can be used to create smooth browser animations.
- * It makes sure scheduled task will happen just before next browser content repaint,
- * thus performing animations as efficiently as possible.
- *
- * @example <caption>Schedule div height animation</caption>
- * const div = document.querySelector('.some-div');
- *
- * Rx.Scheduler.schedule(function(height) {
- * div.style.height = height + "px";
- *
- * this.schedule(height + 1); // `this` references currently executing Action,
- * // which we reschedule with new state
- * }, 0, 0);
- *
- * // You will see .some-div element growing in height
- *
- *
- * @static true
- * @name animationFrame
- * @owner Scheduler
- */
- var animationFrame = new AnimationFrameScheduler(AnimationFrameAction);
-
-
-
- var _operators = Object.freeze({
- audit: audit$1,
- auditTime: auditTime$1,
- buffer: buffer$1,
- bufferCount: bufferCount$1,
- bufferTime: bufferTime$1,
- bufferToggle: bufferToggle$1,
- bufferWhen: bufferWhen$1,
- catchError: catchError,
- combineAll: combineAll$1,
- combineLatest: combineLatest$1,
- concat: concat$2,
- concatAll: concatAll,
- concatMap: concatMap$1,
- concatMapTo: concatMapTo$1,
- count: count$1,
- debounce: debounce$1,
- debounceTime: debounceTime$1,
- defaultIfEmpty: defaultIfEmpty$1,
- delay: delay$1,
- delayWhen: delayWhen$1,
- dematerialize: dematerialize$1,
- distinct: distinct$1,
- distinctUntilChanged: distinctUntilChanged$1,
- distinctUntilKeyChanged: distinctUntilKeyChanged$1,
- elementAt: elementAt$1,
- every: every$1,
- exhaust: exhaust$1,
- exhaustMap: exhaustMap$1,
- expand: expand$1,
- filter: filter$1,
- finalize: finalize,
- find: find$1,
- findIndex: findIndex$1,
- first: first$1,
- groupBy: groupBy$1,
- ignoreElements: ignoreElements$1,
- isEmpty: isEmpty$1,
- last: last$1,
- map: map,
- mapTo: mapTo$1,
- materialize: materialize$1,
- max: max$1,
- merge: merge$2,
- mergeAll: mergeAll,
- mergeMap: mergeMap,
- flatMap: mergeMap,
- mergeMapTo: mergeMapTo$1,
- mergeScan: mergeScan$1,
- min: min$1,
- multicast: multicast$1,
- observeOn: observeOn,
- onErrorResumeNext: onErrorResumeNext$1,
- pairwise: pairwise$1,
- partition: partition$1,
- pluck: pluck$1,
- publish: publish$1,
- publishBehavior: publishBehavior$1,
- publishLast: publishLast$1,
- publishReplay: publishReplay$1,
- race: race$2,
- reduce: reduce,
- repeat: repeat$1,
- repeatWhen: repeatWhen$1,
- retry: retry$1,
- retryWhen: retryWhen$1,
- refCount: refCount,
- sample: sample$1,
- sampleTime: sampleTime$1,
- scan: scan,
- sequenceEqual: sequenceEqual$1,
- share: share$1,
- shareReplay: shareReplay$1,
- single: single$1,
- skip: skip$1,
- skipLast: skipLast$1,
- skipUntil: skipUntil$1,
- skipWhile: skipWhile$1,
- startWith: startWith$1,
- switchAll: switchAll,
- switchMap: switchMap,
- switchMapTo: switchMapTo$1,
- take: take$1,
- takeLast: takeLast,
- takeUntil: takeUntil$1,
- takeWhile: takeWhile$1,
- tap: tap,
- throttle: throttle$1,
- throttleTime: throttleTime$1,
- timeInterval: timeInterval$1,
- timeout: timeout$1,
- timeoutWith: timeoutWith$1,
- timestamp: timestamp$1,
- toArray: toArray$1,
- window: window$2,
- windowCount: windowCount$1,
- windowTime: windowTime$1,
- windowToggle: windowToggle$1,
- windowWhen: windowWhen$1,
- withLatestFrom: withLatestFrom$1,
- zip: zip$1,
- zipAll: zipAll$1
- });
-
- /* tslint:disable:no-unused-variable */
- // Subject imported before Observable to bypass circular dependency issue since
- // Subject extends Observable and Observable references Subject in it's
- // definition
- var operators = _operators;
- /* tslint:enable:no-unused-variable */
- /**
- * @typedef {Object} Rx.Scheduler
- * @property {Scheduler} queue Schedules on a queue in the current event frame
- * (trampoline scheduler). Use this for iteration operations.
- * @property {Scheduler} asap Schedules on the micro task queue, which uses the
- * fastest transport mechanism available, either Node.js' `process.nextTick()`
- * or Web Worker MessageChannel or setTimeout or others. Use this for
- * asynchronous conversions.
- * @property {Scheduler} async Schedules work with `setInterval`. Use this for
- * time-based operations.
- * @property {Scheduler} animationFrame Schedules work with `requestAnimationFrame`.
- * Use this for synchronizing with the platform's painting
- */
- var Scheduler = {
- asap: asap,
- queue: queue,
- animationFrame: animationFrame,
- async: async
- };
- /**
- * @typedef {Object} Rx.Symbol
- * @property {Symbol|string} rxSubscriber A symbol to use as a property name to
- * retrieve an "Rx safe" Observer from an object. "Rx safety" can be defined as
- * an object that has all of the traits of an Rx Subscriber, including the
- * ability to add and remove subscriptions to the subscription chain and
- * guarantees involving event triggering (can't "next" after unsubscription,
- * etc).
- * @property {Symbol|string} observable A symbol to use as a property name to
- * retrieve an Observable as defined by the [ECMAScript "Observable" spec](https://github.com/zenparsing/es-observable).
- * @property {Symbol|string} iterator The ES6 symbol to use as a property name
- * to retrieve an iterator from an object.
- */
- var Symbol$1 = {
- rxSubscriber: rxSubscriber,
- observable: observable,
- iterator: iterator
- };
-
- exports.operators = operators;
- exports.Scheduler = Scheduler;
- exports.Symbol = Symbol$1;
- exports.Subject = Subject;
- exports.AnonymousSubject = AnonymousSubject;
- exports.Observable = Observable;
- exports.Subscription = Subscription;
- exports.Subscriber = Subscriber;
- exports.AsyncSubject = AsyncSubject;
- exports.ReplaySubject = ReplaySubject;
- exports.BehaviorSubject = BehaviorSubject;
- exports.ConnectableObservable = ConnectableObservable;
- exports.Notification = Notification;
- exports.EmptyError = EmptyError;
- exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError;
- exports.ObjectUnsubscribedError = ObjectUnsubscribedError;
- exports.TimeoutError = TimeoutError;
- exports.UnsubscriptionError = UnsubscriptionError;
- exports.TimeInterval = TimeInterval;
- exports.Timestamp = Timestamp;
- exports.TestScheduler = TestScheduler;
- exports.VirtualTimeScheduler = VirtualTimeScheduler;
- exports.AjaxResponse = AjaxResponse;
- exports.AjaxError = AjaxError;
- exports.AjaxTimeoutError = AjaxTimeoutError;
- exports.pipe = pipe;
-
- Object.defineProperty(exports, '__esModule', { value: true });
-
- })));
-
-
|