From aee9c9485b9bb980a24de747d4366c18eb39464e Mon Sep 17 00:00:00 2001 From: Ayumu Sato Date: Mon, 14 May 2018 21:49:44 +0900 Subject: [PATCH] refactor: Replace to v0.13.0-beta1 --- .babelrc | 8 - .editorconfig | 13 - .eslintrc | 208 - .gitignore | 1 + .prettierignore | 1 + Makefile | 78 + dist/talkie-default.min.css | 1 - dist/talkie.css | 1 + dist/talkie.js | 36592 ++++++++++++++++++++++++++++ dist/talkie.js.map | 1 + dist/talkie.min.css | 1 - dist/talkie.min.js | 66 - dist/talkie.min.js.map | 317 - dist/talkie.theme-default.css | 1 + dist/webcomponents-hi-ce.js | 81 + dist/webcomponents-hi-sd-ce.js | 198 + dist/webcomponents-hi-sd.js | 181 + dist/webcomponents-hi.js | 55 + dist/webcomponents-lite.js | 221 + dist/webcomponents-loader.js | 74 + dist/webcomponents-sd-ce.js | 172 + index.html | 143 +- karma.conf.js | 34 - package.json | 86 +- postcss.config.js | 6 +- prettier.config.js | 11 + rollup.config.js | 54 + src/backface.ts | 46 - src/canvas.ts | 75 - src/components/TalkieBackface.ts | 62 + src/components/TalkiePager.ts | 85 + src/components/TalkieProgress.ts | 50 + src/components/TalkieSlide.ts | 174 + src/control.ts | 149 - src/event.ts | 46 + src/fullscreen.ts | 22 +- src/index.ts | 307 +- src/markdown.ts | 46 + src/paging.ts | 93 +- src/pointer.ts | 34 - src/query.ts | 21 - src/responsive.ts | 100 +- src/slide.ts | 89 - src/style/index.css | 134 +- src/style/layout-util.css | 5 +- src/style/layout.css | 32 - src/theme/default/base.css | 20 +- src/theme/default/code.css | 6 - src/theme/default/cover.css | 4 - src/theme/default/index.css | 1 - src/theme/default/title.css | 4 - src/theme/default/transparent.css | 3 - src/theme/example/base.css | 2 - src/util.ts | 113 +- test/backface.js | 56 - test/control.js | 65 - test/fullscreen.js | 69 - test/libs/click-event.js | 12 - test/libs/key-event.js | 132 - test/paging.js | 210 - test/pointer.js | 31 - test/query.js | 23 - test/responsive.js | 10 - test/slide.js | 77 - test/util.js | 127 - tsconfig.json | 26 +- typings/myself.d.ts | 0 yarn.lock | 3993 +++ 68 files changed, 42524 insertions(+), 2635 deletions(-) delete mode 100644 .babelrc delete mode 100644 .editorconfig delete mode 100644 .eslintrc create mode 100644 .prettierignore create mode 100644 Makefile delete mode 100644 dist/talkie-default.min.css create mode 100644 dist/talkie.css create mode 100644 dist/talkie.js create mode 100644 dist/talkie.js.map delete mode 100644 dist/talkie.min.css delete mode 100644 dist/talkie.min.js delete mode 100644 dist/talkie.min.js.map create mode 100644 dist/talkie.theme-default.css create mode 100644 dist/webcomponents-hi-ce.js create mode 100644 dist/webcomponents-hi-sd-ce.js create mode 100644 dist/webcomponents-hi-sd.js create mode 100644 dist/webcomponents-hi.js create mode 100644 dist/webcomponents-lite.js create mode 100644 dist/webcomponents-loader.js create mode 100644 dist/webcomponents-sd-ce.js delete mode 100644 karma.conf.js create mode 100644 prettier.config.js create mode 100644 rollup.config.js delete mode 100644 src/backface.ts delete mode 100644 src/canvas.ts create mode 100644 src/components/TalkieBackface.ts create mode 100644 src/components/TalkiePager.ts create mode 100644 src/components/TalkieProgress.ts create mode 100644 src/components/TalkieSlide.ts delete mode 100644 src/control.ts create mode 100644 src/event.ts create mode 100644 src/markdown.ts delete mode 100644 src/pointer.ts delete mode 100644 src/query.ts delete mode 100644 src/slide.ts delete mode 100644 src/style/layout.css delete mode 100644 src/theme/default/transparent.css delete mode 100644 test/backface.js delete mode 100644 test/control.js delete mode 100644 test/fullscreen.js delete mode 100644 test/libs/click-event.js delete mode 100644 test/libs/key-event.js delete mode 100644 test/paging.js delete mode 100644 test/pointer.js delete mode 100644 test/query.js delete mode 100644 test/responsive.js delete mode 100644 test/slide.js delete mode 100644 test/util.js delete mode 100644 typings/myself.d.ts create mode 100644 yarn.lock diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 7506d64..0000000 --- a/.babelrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "sourceMaps": "inline", - "presets": [ - "babel-preset-es2015" - ], - "plugins": [ - ] -} diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index e717f5e..0000000 --- a/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -# http://editorconfig.org -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index b7a13ab..0000000 --- a/.eslintrc +++ /dev/null @@ -1,208 +0,0 @@ -{ - "parser": "babel-eslint", - "env": { - "browser": true, - "node": true, - "mocha": true - }, - "rules": { - - // Possible Errors - "comma-dangle": [2, "never"], - "no-cond-assign": [2, "except-parens"], - "no-console": 0, - "no-constant-condition": 2, - "no-control-regex": 2, - "no-debugger": 2, - "no-dupe-args": 2, - "no-dupe-keys": 2, - "no-duplicate-case": 2, - "no-empty-character-class": 2, - "no-empty": 2, - "no-ex-assign": 2, - "no-extra-boolean-cast": 2, - "no-extra-parens": 0, - "no-extra-semi": 2, - "no-func-assign": 2, - "no-inner-declarations": 2, - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-negated-in-lhs": 2, - "no-obj-calls": 2, - "no-regex-spaces": 2, - "no-sparse-arrays": 2, - "no-unreachable": 2, - "use-isnan": 2, - "valid-jsdoc": 0, - "valid-typeof": 2, - "no-unexpected-multiline": 2, - - // Best Practices - "accessor-pairs": 1, - "block-scoped-var": 2, - "complexity": 0, - "consistent-return": 0, - "curly": 2, - "default-case": 2, - "dot-notation": [2, {"allowKeywords": true}], - "dot-location": [2, "property"], - "eqeqeq": [2, "allow-null"], - "guard-for-in": 1, - "no-alert": 0, - "no-caller": 2, - "no-div-regex": 2, - "no-else-return": 2, - "no-empty-label": 0, - "no-eq-null": 0, - "no-eval": 2, - "no-extend-native": [2], - "no-extra-bind": 2, - "no-fallthrough": 2, - "no-floating-decimal": 2, - "no-implicit-coercion": 0, - "no-implied-eval": 2, - "no-invalid-this": 0, - "no-iterator": 2, - "no-labels": 2, - "no-lone-blocks": 2, - "no-loop-func": 2, - "no-multi-spaces": [0, { - "exceptions": { - "VariableDeclarator": true, - "ImportDeclaration": true - } - }], - "no-multi-str": 2, - "no-native-reassign": 2, - "no-new-func": 0, - "no-new-wrappers": 2, - "no-new": 2, - "no-octal-escape": 2, - "no-octal": 2, - "no-param-reassign": 2, - "no-process-env": 2, - "no-proto": 2, - "no-redeclare": 2, - "no-return-assign": 0, - "no-script-url": 2, - "no-self-compare": 2, - "no-sequences": 2, - "no-throw-literal": 2, - "no-unused-expressions": 1, - "no-useless-call": 2, - "no-void": 2, - "no-warning-comments": 0, //??? - "no-with": 2, - "radix": 2, - "vars-on-top": 2, - "wrap-iife": 2, - "yoda": [2, "never"], - - // Strict Mode - "strict": [2, "global"], - - // Variables - "init-declarations": 0, - "no-catch-shadow": 2, - "no-delete-var": 2, - "no-label-var": 2, - "no-shadow-restricted-names": 2, - "no-shadow": 2, - "no-undef-init": 2, - "no-undef": 2, - "no-undefined": 0, - "no-unused-vars": 1, - "no-use-before-define": 0, - "callback-return": [2, ["callback", "cb", "next", "done"]], - "handle-callback-err": [2, "^(err|error)$"], - "no-mixed-requires": 0, - "no-new-require": 0, - "no-path-concat": 0, - "no-process-exit": 0, - "no-restricted-modules": 0, - "no-sync": 1, - - // Stylistic Issues - "array-bracket-spacing": [2, "never"], - "block-spacing": [2, "always"], - "brace-style": [2, "1tbs", { "allowSingleLine": true }], - "camelcase": [2, {"properties": "always"}], - "comma-spacing": [2, {"before": false, "after": true}], - "comma-style": [2, "last"], - "computed-property-spacing": [2, "never"], - "consistent-this": [2, "DO NOT USE"], - "eol-last": 2, - "func-names": 0, - "func-style": [2, "declaration"], - "id-length": 0, - "id-match": 0, - "indent": [1, 2, {"SwitchCase": 1}], - "jsx-quotes": [2, "prefer-double"], - "key-spacing": [2, { - "align": "colon", - "beforeColon": true, - "afterColon": true - }], - "lines-around-comment": 0, - "linebreak-style": [2, "unix"], - "max-nested-callbacks": [1, 4], - "new-cap": [2, {"newIsCap": true}], - "new-parens": 2, - "newline-after-var": 0, - "no-array-constructor": 0, - "no-continue": 0, - "no-inline-comments": 0, - "no-lonely-if": 2, - "no-mixed-spaces-and-tabs": 2, - "no-multiple-empty-lines": 2, - "no-nested-ternary": 2, - "no-new-object": 2, - "no-spaced-func": 2, - "no-ternary": 0, - "no-trailing-spaces": 2, - "no-underscore-dangle": 0, - "no-unneeded-ternary": 2, - "object-curly-spacing": 0, - "one-var": 0, - "operator-assignment": [2, "always"], - "operator-linebreak": 0, - "padded-blocks": 0, - "quote-props": 0, - "quotes": [1, "single"], - "semi-spacing": [2, {"before": false, "after": true}], - "semi": [2, "always"], - "sort-vars": 0, - "space-after-keywords": [2, "always"], - "space-before-blocks": [2, "always"], - "space-before-function-paren": [2, "never"], - "space-in-parens": 0, - "space-infix-ops": 0, - "space-return-throw-case": 2, - "space-unary-ops": [1, { "words": true, "nonwords": false }], - "spaced-comment": [1, "always"], - "wrap-regex": 0, - - // ECMAScript 6 - "arrow-parens": [2, "always"], - "arrow-spacing": [2, { "before": true, "after": true }], - "constructor-super": 2, - "generator-star-spacing": [2, {"before": false, "after": false}], - "no-class-assign": 0, // for higher-order components - "no-const-assign": 2, - "no-dupe-class-members": 2, - "no-this-before-super": 2, - "no-var": 2, - "prefer-arrow-callback": 0, - "object-shorthand": 0, - "prefer-const": 0, - "prefer-spread": 0, - "prefer-reflect": 0, - "prefer-template": 0, - "require-yield": 2, - - // Legacy - "max-params": [1, 3], - "max-depth": [1, 3], - "max-len": [2, 120, 4] - } -} diff --git a/.gitignore b/.gitignore index dba8a59..f7f1eca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +yarn-error.log temp diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +dist diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f8c83a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,78 @@ +#MAKEFLAGS = -j1 + +NODE_BIN := node +NPM_MOD_DIR := $(CURDIR)/node_modules +NPM_BIN_DIR := $(NPM_MOD_DIR)/.bin +WEBCOMPONENTS_DIR := $(NPM_MOD_DIR)/@webcomponents/webcomponentsjs + +DIST_DIR := ./dist + +.DEFAULT_GOAL := help + +# Self-Documented Makefile +# ref. https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + @exit 1 ## I'd like to notice to fail if user call 'make' without any target. + +# Dev + +.PHONY: build +build: format clean rollup postcss theme-default copy-webcomponentsjs ## Build All + +.PHONY: dev +dev: ## Incremental Build All + $(MAKE) copy-webcomponentsjs + $(MAKE) -j rollup-watch postcss-watch theme-default-watch serve + +.PHONY: serve +serve: ## Serve file + python -m SimpleHTTPServer + +# Build + +.PHONY: rollup +rollup: + $(NPM_BIN_DIR)/rollup --config ./rollup.config.js + +.PHONY: rollup-watch +rollup-watch: + $(NPM_BIN_DIR)/rollup --config ./rollup.config.js --watch + +.PHONY: copy-webcomponentsjs +copy-webcomponentsjs: + cp $(WEBCOMPONENTS_DIR)/webcomponents-hi.js ./dist + cp $(WEBCOMPONENTS_DIR)/webcomponents-hi-ce.js ./dist + cp $(WEBCOMPONENTS_DIR)/webcomponents-hi-sd.js ./dist + cp $(WEBCOMPONENTS_DIR)/webcomponents-hi-sd-ce.js ./dist + cp $(WEBCOMPONENTS_DIR)/webcomponents-lite.js ./dist + cp $(WEBCOMPONENTS_DIR)/webcomponents-loader.js ./dist + cp $(WEBCOMPONENTS_DIR)/webcomponents-sd-ce.js ./dist + +.PHONY: postcss +postcss: + $(NPM_BIN_DIR)/postcss --output ./dist/talkie.css ./src/style/index.css --verbose + +.PHONY: postcss-watch +postcss-watch: + $(NPM_BIN_DIR)/postcss --output ./dist/talkie.css ./src/style/index.css --verbose --watch + +.PHONY: theme-default +theme-default: + $(NPM_BIN_DIR)/postcss --output ./dist/talkie.theme-default.css ./src/theme/default/index.css --verbose + +.PHONY: theme-default-watch +theme-default-watch: + $(NPM_BIN_DIR)/postcss --output ./dist/talkie.theme-default.css ./src/theme/default/index.css --verbose --watch + +# Utilities + +.PHONY: format +format: ## Auto formatting + $(NPM_BIN_DIR)/prettier --config ./prettier.config.js --write './**/*.+(ts|js)' + +.PHONY: clean +clean: ## Clean distribution dir + rm -rf $(DIST_DIR) diff --git a/dist/talkie-default.min.css b/dist/talkie-default.min.css deleted file mode 100644 index 1752256..0000000 --- a/dist/talkie-default.min.css +++ /dev/null @@ -1 +0,0 @@ -[data-body-bg]{background:radial-gradient(#f8f8f8 0%,#e6e6e6 100%)}[data-body-bg][invert]{background:radial-gradient(#262626 0%,#080808 100%)}[layout]{line-height:1.5;color:#222;box-shadow:0 0 10px transparent;font-family:"NotoSansCJKjp-Light","Open Sans","Hiragino Kaku Gothic ProN","Meiryo",sans-serif;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center}[layout][invert]{color:#fff}[layout]>*{margin:30px 100px}[layout][horizontal]{-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-line-pack:center;align-content:center}[layout][horizontal]>*{-webkit-box-flex:1;-ms-flex:1;flex:1;margin:30px}[layout][horizontal] h1:first-child+*,[layout][horizontal] h2:first-child+*,[layout][horizontal] h3:first-child+*,[layout][horizontal] h4:first-child+*,[layout][horizontal] h5:first-child+*,[layout][horizontal] h6:first-child+*,[layout][horizontal]>:first-child{margin-left:100px}[layout][horizontal]>h1:first-child,[layout][horizontal]>h2:first-child,[layout][horizontal]>h3:first-child,[layout][horizontal]>h4:first-child,[layout][horizontal]>h5:first-child,[layout][horizontal]>h6:first-child{width:100%;margin-left:30px}[layout][horizontal]>:last-child{margin-right:100px}[layout] h1,[layout] h2,[layout] h3,[layout] h4,[layout] h5,[layout] h6{-webkit-box-flex:initial!important;-ms-flex:initial!important;flex:initial!important;text-align:center;font-family:"Lato","Hiragino Mincho ProN",serif}[layout] h1{font-size:4.8em}[layout] h2{font-size:3.6em}[layout] h3{font-size:2.4em}[layout] p{font-size:2em}[layout] a:active,[layout] a:hover,[layout] a:link,[layout] a:visited{color:#1e90ff;text-decoration:none}[layout][invert] a:active,[layout][invert] a:hover,[layout][invert] a:link,[layout][invert] a:visited{color:#3ff}[layout] em{font-size:.5em;font-style:normal}[layout] strong{font-weight:700}[layout] table{border-collapse:collapse}[layout] td,[layout] th{padding:1em;font-size:2em;font-weight:400;border:1px solid #222}[layout][invert] td,[layout][invert] th{border-color:#fff}[layout] ol,[layout] ul{font-size:1.8em;text-align:left;list-style-type:none}[layout] ol ol,[layout] ol ul,[layout] ul ol,[layout] ul ul{font-size:1em}[layout] li{margin-bottom:.5em}[layout] del{opacity:.5}[layout] img,[layout] video{max-width:100%}[layout] blockquote{position:relative;font-style:italic;opacity:.6}[layout] blockquote::before{position:absolute;top:-.6em;left:-.6em;font-size:5em;content:"\""}[layout] pre{font-size:1.6em}[layout] code{padding:.1em .2em;background:#fff;border:1px solid #999}[layout=code] code,[layout][invert] code{background:#222}[layout] pre code{padding:inherit;background:inherit;border:inherit}[layout=bullets] h1,[layout=bullets] h2,[layout=bullets] h3,[layout=bullets] h4,[layout=bullets] h5,[layout=bullets] h6{line-height:1.3;margin-top:-30px}[layout=bullets] ul{list-style-type:disc}[layout=bullets] ol{list-style-type:decimal}[layout=bullets] li{margin-right:-1em}[layout=bullets] ol ol,[layout=bullets] ol ul,[layout=bullets] ul ol,[layout=bullets] ul ul{list-style-type:none;font-size:.9em;margin:.5em 0 1.5em 2em}[data-body-bg=code]{background:radial-gradient(#262626 0%,#080808 100%)}[layout=code] h1,[layout=code] h2,[layout=code] h3,[layout=code] h4,[layout=code] h5,[layout=code] h6,[layout=code] p{color:#fff}[layout=code] .hljs{font-family:Consolas,Monaco,'Andale Mono',monospace;background-color:transparent}[layout=code] .hljs-comment{color:orange;line-height:1}[data-body-bg=cover]{background:0 0}[layout=cover] h1{text-align:center;text-transform:uppercase;letter-spacing:.25em;font-weight:500;font-family:Futura,Helvetica,Arial,"Hiragino Kaku Gothic ProN","Meiryo",sans-serif}[layout=title]>*{margin:30px 100px}[layout=title] h1,[layout=title] h2,[layout=title] h3,[layout=title] h4,[layout=title] h5,[layout=title] h6{font-weight:700}[layout=title] strong{font-size:200%;font-weight:700;line-height:1}[data-body-bg=transparent]{background:0 0} \ No newline at end of file diff --git a/dist/talkie.css b/dist/talkie.css new file mode 100644 index 0000000..a8fa1b0 --- /dev/null +++ b/dist/talkie.css @@ -0,0 +1 @@ +abbr,address,article,aside,audio,b,blockquote,body div,caption,cite,code,dd,del,details,dfn,dl,dt,em,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,p,pre,q,samp,section,span,summary,tbody,tfoot,thead,time,tr,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font-weight:400;vertical-align:baseline;background:0 0}body,html,small,sub,sup{border:0;font-weight:400;background:0 0}body,html,small,strong,sub,sup,table{vertical-align:baseline}body,html,strong{font-size:100%}strong,table,td,th{border:0;background:0 0}table{border-collapse:collapse;border-spacing:0;font:100%}td,th{font-size:100%}article,aside,details,figure,footer,header,nav,section,summary{display:block}html{-webkit-box-sizing:border-box;box-sizing:border-box;overflow-y:scroll}*,::after,::before,:after,:before{-webkit-box-sizing:inherit;box-sizing:inherit}embed,img,object{max-width:100%}ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:none}a,body,hr,html,small,strong,sub,sup,table,td,th{margin:0;padding:0}a{font-size:100%;background:0 0}del{text-decoration:line-through}abbr[title],dfn[title]{border-bottom:1px dotted #000;cursor:help}td{font-weight:400}hr{display:block;height:1px;border:0;border-top:1px solid #ccc;margin:1em 0}input,select{vertical-align:middle}pre{white-space:pre-wrap;word-wrap:break-word}input[type=radio]{vertical-align:text-bottom}input[type=checkbox],th{vertical-align:bottom}.ie7 input[type=checkbox],a{vertical-align:baseline}.ie6 input{vertical-align:text-bottom}input,select,textarea{font:99% sans-serif}small{font-size:85%}strong,th{font-weight:700}td,td img{vertical-align:top}sub,sup{font-size:75%;line-height:0;position:relative}sup{top:-.5em}sub{bottom:-.25em}code,kbd,pre,samp{font-family:monospace,sans-serif}.clickable,button,input[type=button],input[type=file],input[type=submit],label{cursor:pointer}button,input,select,textarea{margin:0}button,input[type=button]{width:auto;overflow:visible}.ie7 img{-ms-interpolation-mode:bicubic}.clearfix:after,.clearfix:before{content:"\0020";display:block;height:0;overflow:hidden}.clearfix:after{clear:both}.clearfix{zoom:1}[flex]{display:-webkit-box!important;display:-ms-flexbox!important;display:flex!important}[horizontal],[vertical]{-webkit-box-orient:vertical!important;-webkit-box-direction:normal!important;-ms-flex-direction:column!important;flex-direction:column!important}[horizontal]{-webkit-box-orient:horizontal!important;-ms-flex-direction:row!important;flex-direction:row!important}[v-center]{-webkit-box-pack:center!important;-ms-flex-pack:center!important;justify-content:center!important}[horizontal][v-center]{-webkit-box-align:center!important;-ms-flex-align:center!important;align-items:center!important}[v-top]{-webkit-box-pack:start!important;-ms-flex-pack:start!important;justify-content:flex-start!important}[horizontal][v-top]{-webkit-box-align:start!important;-ms-flex-align:start!important;align-items:flex-start!important}[v-bottom]{-webkit-box-pack:end!important;-ms-flex-pack:end!important;justify-content:flex-end!important}[horizontal][v-bottom]{-webkit-box-align:end!important;-ms-flex-align:end!important;align-items:flex-end!important}[h-center]{-webkit-box-align:center!important;-ms-flex-align:center!important;align-items:center!important}[horizontal][h-center]{-webkit-box-pack:center!important;-ms-flex-pack:center!important;justify-content:center!important}[h-left]{-webkit-box-align:start!important;-ms-flex-align:start!important;align-items:flex-start!important}[horizontal][h-left]{-webkit-box-pack:start!important;-ms-flex-pack:start!important;justify-content:flex-start!important}[h-right]{-webkit-box-align:end!important;-ms-flex-align:end!important;align-items:flex-end!important}[horizontal][h-right]{-webkit-box-pack:end!important;-ms-flex-pack:end!important;justify-content:flex-end!important}[h-left]>*{text-align:left!important}[h-right]>*{text-align:right!important}[s-center]{-ms-flex-item-align:center!important;align-self:center!important}[s-start]{-ms-flex-item-align:start!important;align-self:flex-start!important}[s-end]{-ms-flex-item-align:end!important;align-self:flex-end!important}[fixedsize]{contain:strict}body,html{min-width:100vw}html{overflow-x:hidden}html:-webkit-full-screen{overflow-y:hidden}html:-moz-full-screen{overflow-y:hidden}html:-ms-fullscreen{overflow-y:hidden}html:fullscreen{overflow-y:hidden}body>*{-webkit-font-smoothing:antialiased;visibility:hidden}body.webcomponents-ready>*{visibility:visible} \ No newline at end of file diff --git a/dist/talkie.js b/dist/talkie.js new file mode 100644 index 0000000..1f7cc87 --- /dev/null +++ b/dist/talkie.js @@ -0,0 +1,36592 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.talkie = factory()); +}(this, (function () { 'use strict'; + + var _aFunction = function (it) { + if (typeof it != 'function') throw TypeError(it + ' is not a function!'); + return it; + }; + + // optional / simple context binding + + var _ctx = function (fn, that, length) { + _aFunction(fn); + if (that === undefined) return fn; + switch (length) { + case 1: return function (a) { + return fn.call(that, a); + }; + case 2: return function (a, b) { + return fn.call(that, a, b); + }; + case 3: return function (a, b, c) { + return fn.call(that, a, b, c); + }; + } + return function (/* ...args */) { + return fn.apply(that, arguments); + }; + }; + + var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + function unwrapExports (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; + } + + function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; + } + + var _global = createCommonjsModule(function (module) { + // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 + var global = module.exports = typeof window != 'undefined' && window.Math == Math + ? window : typeof self != 'undefined' && self.Math == Math ? self + // eslint-disable-next-line no-new-func + : Function('return this')(); + if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef + }); + + var _core = createCommonjsModule(function (module) { + var core = module.exports = { version: '2.5.5' }; + if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef + }); + var _core_1 = _core.version; + + var _isObject = function (it) { + return typeof it === 'object' ? it !== null : typeof it === 'function'; + }; + + var _anObject = function (it) { + if (!_isObject(it)) throw TypeError(it + ' is not an object!'); + return it; + }; + + var _fails = function (exec) { + try { + return !!exec(); + } catch (e) { + return true; + } + }; + + // Thank's IE8 for his funny defineProperty + var _descriptors = !_fails(function () { + return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; + }); + + var document$1 = _global.document; + // typeof document.createElement is 'object' in old IE + var is = _isObject(document$1) && _isObject(document$1.createElement); + var _domCreate = function (it) { + return is ? document$1.createElement(it) : {}; + }; + + var _ie8DomDefine = !_descriptors && !_fails(function () { + return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7; + }); + + // 7.1.1 ToPrimitive(input [, PreferredType]) + + // instead of the ES6 spec version, we didn't implement @@toPrimitive case + // and the second argument - flag - preferred type is a string + var _toPrimitive = function (it, S) { + if (!_isObject(it)) return it; + var fn, val; + if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; + if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val; + if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; + throw TypeError("Can't convert object to primitive value"); + }; + + var dP = Object.defineProperty; + + var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) { + _anObject(O); + P = _toPrimitive(P, true); + _anObject(Attributes); + if (_ie8DomDefine) try { + return dP(O, P, Attributes); + } catch (e) { /* empty */ } + if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; + }; + + var _objectDp = { + f: f + }; + + var _propertyDesc = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value + }; + }; + + var _hide = _descriptors ? function (object, key, value) { + return _objectDp.f(object, key, _propertyDesc(1, value)); + } : function (object, key, value) { + object[key] = value; + return object; + }; + + var hasOwnProperty = {}.hasOwnProperty; + var _has = function (it, key) { + return hasOwnProperty.call(it, key); + }; + + var id = 0; + var px = Math.random(); + var _uid = function (key) { + return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); + }; + + var _redefine = createCommonjsModule(function (module) { + var SRC = _uid('src'); + var TO_STRING = 'toString'; + var $toString = Function[TO_STRING]; + var TPL = ('' + $toString).split(TO_STRING); + + _core.inspectSource = function (it) { + return $toString.call(it); + }; + + (module.exports = function (O, key, val, safe) { + var isFunction = typeof val == 'function'; + if (isFunction) _has(val, 'name') || _hide(val, 'name', key); + if (O[key] === val) return; + if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key))); + if (O === _global) { + O[key] = val; + } else if (!safe) { + delete O[key]; + _hide(O, key, val); + } else if (O[key]) { + O[key] = val; + } else { + _hide(O, key, val); + } + // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative + })(Function.prototype, TO_STRING, function toString() { + return typeof this == 'function' && this[SRC] || $toString.call(this); + }); + }); + + var PROTOTYPE = 'prototype'; + + var $export = function (type, name, source) { + var IS_FORCED = type & $export.F; + var IS_GLOBAL = type & $export.G; + var IS_STATIC = type & $export.S; + var IS_PROTO = type & $export.P; + var IS_BIND = type & $export.B; + var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE]; + var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}); + var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}); + var key, own, out, exp; + if (IS_GLOBAL) source = name; + for (key in source) { + // contains in native + own = !IS_FORCED && target && target[key] !== undefined; + // export native or passed + out = (own ? target : source)[key]; + // bind timers to global for call from export context + exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; + // extend global + if (target) _redefine(target, key, out, type & $export.U); + // export + if (exports[key] != out) _hide(exports, key, exp); + if (IS_PROTO && expProto[key] != out) expProto[key] = out; + } + }; + _global.core = _core; + // type bitmap + $export.F = 1; // forced + $export.G = 2; // global + $export.S = 4; // static + $export.P = 8; // proto + $export.B = 16; // bind + $export.W = 32; // wrap + $export.U = 64; // safe + $export.R = 128; // real proto method for `library` + var _export = $export; + + // 7.2.1 RequireObjectCoercible(argument) + var _defined = function (it) { + if (it == undefined) throw TypeError("Can't call method on " + it); + return it; + }; + + // 7.1.13 ToObject(argument) + + var _toObject = function (it) { + return Object(_defined(it)); + }; + + // call something on iterator step with safe closing on error + + var _iterCall = function (iterator, fn, value, entries) { + try { + return entries ? fn(_anObject(value)[0], value[1]) : fn(value); + // 7.4.6 IteratorClose(iterator, completion) + } catch (e) { + var ret = iterator['return']; + if (ret !== undefined) _anObject(ret.call(iterator)); + throw e; + } + }; + + var _iterators = {}; + + var SHARED = '__core-js_shared__'; + var store = _global[SHARED] || (_global[SHARED] = {}); + var _shared = function (key) { + return store[key] || (store[key] = {}); + }; + + var _wks = createCommonjsModule(function (module) { + var store = _shared('wks'); + + var Symbol = _global.Symbol; + var USE_SYMBOL = typeof Symbol == 'function'; + + var $exports = module.exports = function (name) { + return store[name] || (store[name] = + USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name)); + }; + + $exports.store = store; + }); + + // check on default Array iterator + + var ITERATOR = _wks('iterator'); + var ArrayProto = Array.prototype; + + var _isArrayIter = function (it) { + return it !== undefined && (_iterators.Array === it || ArrayProto[ITERATOR] === it); + }; + + // 7.1.4 ToInteger + var ceil = Math.ceil; + var floor = Math.floor; + var _toInteger = function (it) { + return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); + }; + + // 7.1.15 ToLength + + var min = Math.min; + var _toLength = function (it) { + return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 + }; + + var _createProperty = function (object, index, value) { + if (index in object) _objectDp.f(object, index, _propertyDesc(0, value)); + else object[index] = value; + }; + + var toString = {}.toString; + + var _cof = function (it) { + return toString.call(it).slice(8, -1); + }; + + // getting tag from 19.1.3.6 Object.prototype.toString() + + var TAG = _wks('toStringTag'); + // ES3 wrong here + var ARG = _cof(function () { return arguments; }()) == 'Arguments'; + + // fallback for IE11 Script Access Denied error + var tryGet = function (it, key) { + try { + return it[key]; + } catch (e) { /* empty */ } + }; + + var _classof = function (it) { + var O, T, B; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T + // builtinTag case + : ARG ? _cof(O) + // ES3 arguments fallback + : (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B; + }; + + var ITERATOR$1 = _wks('iterator'); + + var core_getIteratorMethod = _core.getIteratorMethod = function (it) { + if (it != undefined) return it[ITERATOR$1] + || it['@@iterator'] + || _iterators[_classof(it)]; + }; + + var ITERATOR$2 = _wks('iterator'); + var SAFE_CLOSING = false; + + try { + var riter = [7][ITERATOR$2](); + riter['return'] = function () { SAFE_CLOSING = true; }; + } catch (e) { /* empty */ } + + var _iterDetect = function (exec, skipClosing) { + if (!skipClosing && !SAFE_CLOSING) return false; + var safe = false; + try { + var arr = [7]; + var iter = arr[ITERATOR$2](); + iter.next = function () { return { done: safe = true }; }; + arr[ITERATOR$2] = function () { return iter; }; + exec(arr); + } catch (e) { /* empty */ } + return safe; + }; + + _export(_export.S + _export.F * !_iterDetect(function (iter) { }), 'Array', { + // 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined) + from: function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) { + var O = _toObject(arrayLike); + var C = typeof this == 'function' ? this : Array; + var aLen = arguments.length; + var mapfn = aLen > 1 ? arguments[1] : undefined; + var mapping = mapfn !== undefined; + var index = 0; + var iterFn = core_getIteratorMethod(O); + var length, result, step, iterator; + if (mapping) mapfn = _ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2); + // if object isn't iterable or it's array with default iterator - use simple case + if (iterFn != undefined && !(C == Array && _isArrayIter(iterFn))) { + for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) { + _createProperty(result, index, mapping ? _iterCall(iterator, mapfn, [step.value, index], true) : step.value); + } + } else { + length = _toLength(O.length); + for (result = new C(length); length > index; index++) { + _createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]); + } + } + result.length = index; + return result; + } + }); + + // 22.1.3.31 Array.prototype[@@unscopables] + var UNSCOPABLES = _wks('unscopables'); + var ArrayProto$1 = Array.prototype; + if (ArrayProto$1[UNSCOPABLES] == undefined) _hide(ArrayProto$1, UNSCOPABLES, {}); + var _addToUnscopables = function (key) { + ArrayProto$1[UNSCOPABLES][key] = true; + }; + + var _iterStep = function (done, value) { + return { value: value, done: !!done }; + }; + + // fallback for non-array-like ES3 and non-enumerable old V8 strings + + // eslint-disable-next-line no-prototype-builtins + var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) { + return _cof(it) == 'String' ? it.split('') : Object(it); + }; + + // to indexed object, toObject with fallback for non-array-like ES3 strings + + + var _toIobject = function (it) { + return _iobject(_defined(it)); + }; + + var _library = false; + + var max = Math.max; + var min$1 = Math.min; + var _toAbsoluteIndex = function (index, length) { + index = _toInteger(index); + return index < 0 ? max(index + length, 0) : min$1(index, length); + }; + + // false -> Array#indexOf + // true -> Array#includes + + + + var _arrayIncludes = function (IS_INCLUDES) { + return function ($this, el, fromIndex) { + var O = _toIobject($this); + var length = _toLength(O.length); + var index = _toAbsoluteIndex(fromIndex, length); + var value; + // Array#includes uses SameValueZero equality algorithm + // eslint-disable-next-line no-self-compare + if (IS_INCLUDES && el != el) while (length > index) { + value = O[index++]; + // eslint-disable-next-line no-self-compare + if (value != value) return true; + // Array#indexOf ignores holes, Array#includes - not + } else for (;length > index; index++) if (IS_INCLUDES || index in O) { + if (O[index] === el) return IS_INCLUDES || index || 0; + } return !IS_INCLUDES && -1; + }; + }; + + var shared = _shared('keys'); + + var _sharedKey = function (key) { + return shared[key] || (shared[key] = _uid(key)); + }; + + var arrayIndexOf = _arrayIncludes(false); + var IE_PROTO = _sharedKey('IE_PROTO'); + + var _objectKeysInternal = function (object, names) { + var O = _toIobject(object); + var i = 0; + var result = []; + var key; + for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key); + // Don't enum bug & hidden keys + while (names.length > i) if (_has(O, key = names[i++])) { + ~arrayIndexOf(result, key) || result.push(key); + } + return result; + }; + + // IE 8- don't enum bug keys + var _enumBugKeys = ( + 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' + ).split(','); + + // 19.1.2.14 / 15.2.3.14 Object.keys(O) + + + + var _objectKeys = Object.keys || function keys(O) { + return _objectKeysInternal(O, _enumBugKeys); + }; + + var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) { + _anObject(O); + var keys = _objectKeys(Properties); + var length = keys.length; + var i = 0; + var P; + while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]); + return O; + }; + + var document$2 = _global.document; + var _html = document$2 && document$2.documentElement; + + // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties]) + + + + var IE_PROTO$1 = _sharedKey('IE_PROTO'); + var Empty = function () { /* empty */ }; + var PROTOTYPE$1 = 'prototype'; + + // Create object with fake `null` prototype: use iframe Object with cleared prototype + var createDict = function () { + // Thrash, waste and sodomy: IE GC bug + var iframe = _domCreate('iframe'); + var i = _enumBugKeys.length; + var lt = '<'; + var gt = '>'; + var iframeDocument; + iframe.style.display = 'none'; + _html.appendChild(iframe); + iframe.src = 'javascript:'; // eslint-disable-line no-script-url + // createDict = iframe.contentWindow.Object; + // html.removeChild(iframe); + iframeDocument = iframe.contentWindow.document; + iframeDocument.open(); + iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt); + iframeDocument.close(); + createDict = iframeDocument.F; + while (i--) delete createDict[PROTOTYPE$1][_enumBugKeys[i]]; + return createDict(); + }; + + var _objectCreate = Object.create || function create(O, Properties) { + var result; + if (O !== null) { + Empty[PROTOTYPE$1] = _anObject(O); + result = new Empty(); + Empty[PROTOTYPE$1] = null; + // add "__proto__" for Object.getPrototypeOf polyfill + result[IE_PROTO$1] = O; + } else result = createDict(); + return Properties === undefined ? result : _objectDps(result, Properties); + }; + + var def = _objectDp.f; + + var TAG$1 = _wks('toStringTag'); + + var _setToStringTag = function (it, tag, stat) { + if (it && !_has(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag }); + }; + + var IteratorPrototype = {}; + + // 25.1.2.1.1 %IteratorPrototype%[@@iterator]() + _hide(IteratorPrototype, _wks('iterator'), function () { return this; }); + + var _iterCreate = function (Constructor, NAME, next) { + Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) }); + _setToStringTag(Constructor, NAME + ' Iterator'); + }; + + // 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O) + + + var IE_PROTO$2 = _sharedKey('IE_PROTO'); + var ObjectProto = Object.prototype; + + var _objectGpo = Object.getPrototypeOf || function (O) { + O = _toObject(O); + if (_has(O, IE_PROTO$2)) return O[IE_PROTO$2]; + if (typeof O.constructor == 'function' && O instanceof O.constructor) { + return O.constructor.prototype; + } return O instanceof Object ? ObjectProto : null; + }; + + var ITERATOR$3 = _wks('iterator'); + var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next` + var FF_ITERATOR = '@@iterator'; + var KEYS = 'keys'; + var VALUES = 'values'; + + var returnThis = function () { return this; }; + + var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) { + _iterCreate(Constructor, NAME, next); + var getMethod = function (kind) { + if (!BUGGY && kind in proto) return proto[kind]; + switch (kind) { + case KEYS: return function keys() { return new Constructor(this, kind); }; + case VALUES: return function values() { return new Constructor(this, kind); }; + } return function entries() { return new Constructor(this, kind); }; + }; + var TAG = NAME + ' Iterator'; + var DEF_VALUES = DEFAULT == VALUES; + var VALUES_BUG = false; + var proto = Base.prototype; + var $native = proto[ITERATOR$3] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT]; + var $default = $native || getMethod(DEFAULT); + var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined; + var $anyNative = NAME == 'Array' ? proto.entries || $native : $native; + var methods, key, IteratorPrototype; + // Fix native + if ($anyNative) { + IteratorPrototype = _objectGpo($anyNative.call(new Base())); + if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) { + // Set @@toStringTag to native iterators + _setToStringTag(IteratorPrototype, TAG, true); + // fix for some old engines + if (!_library && typeof IteratorPrototype[ITERATOR$3] != 'function') _hide(IteratorPrototype, ITERATOR$3, returnThis); + } + } + // fix Array#{values, @@iterator}.name in V8 / FF + if (DEF_VALUES && $native && $native.name !== VALUES) { + VALUES_BUG = true; + $default = function values() { return $native.call(this); }; + } + // Define iterator + if ((!_library || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR$3])) { + _hide(proto, ITERATOR$3, $default); + } + // Plug for library + _iterators[NAME] = $default; + _iterators[TAG] = returnThis; + if (DEFAULT) { + methods = { + values: DEF_VALUES ? $default : getMethod(VALUES), + keys: IS_SET ? $default : getMethod(KEYS), + entries: $entries + }; + if (FORCED) for (key in methods) { + if (!(key in proto)) _redefine(proto, key, methods[key]); + } else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods); + } + return methods; + }; + + // 22.1.3.4 Array.prototype.entries() + // 22.1.3.13 Array.prototype.keys() + // 22.1.3.29 Array.prototype.values() + // 22.1.3.30 Array.prototype[@@iterator]() + var es6_array_iterator = _iterDefine(Array, 'Array', function (iterated, kind) { + this._t = _toIobject(iterated); // target + this._i = 0; // next index + this._k = kind; // kind + // 22.1.5.2.1 %ArrayIteratorPrototype%.next() + }, function () { + var O = this._t; + var kind = this._k; + var index = this._i++; + if (!O || index >= O.length) { + this._t = undefined; + return _iterStep(1); + } + if (kind == 'keys') return _iterStep(0, index); + if (kind == 'values') return _iterStep(0, O[index]); + return _iterStep(0, [index, O[index]]); + }, 'values'); + + // argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7) + _iterators.Arguments = _iterators.Array; + + _addToUnscopables('keys'); + _addToUnscopables('values'); + _addToUnscopables('entries'); + + var ITERATOR$4 = _wks('iterator'); + var TO_STRING_TAG = _wks('toStringTag'); + var ArrayValues = _iterators.Array; + + var DOMIterables = { + CSSRuleList: true, // TODO: Not spec compliant, should be false. + CSSStyleDeclaration: false, + CSSValueList: false, + ClientRectList: false, + DOMRectList: false, + DOMStringList: false, + DOMTokenList: true, + DataTransferItemList: false, + FileList: false, + HTMLAllCollection: false, + HTMLCollection: false, + HTMLFormElement: false, + HTMLSelectElement: false, + MediaList: true, // TODO: Not spec compliant, should be false. + MimeTypeArray: false, + NamedNodeMap: false, + NodeList: true, + PaintRequestList: false, + Plugin: false, + PluginArray: false, + SVGLengthList: false, + SVGNumberList: false, + SVGPathSegList: false, + SVGPointList: false, + SVGStringList: false, + SVGTransformList: false, + SourceBufferList: false, + StyleSheetList: true, // TODO: Not spec compliant, should be false. + TextTrackCueList: false, + TextTrackList: false, + TouchList: false + }; + + for (var collections = _objectKeys(DOMIterables), i = 0; i < collections.length; i++) { + var NAME = collections[i]; + var explicit = DOMIterables[NAME]; + var Collection = _global[NAME]; + var proto = Collection && Collection.prototype; + var key; + if (proto) { + if (!proto[ITERATOR$4]) _hide(proto, ITERATOR$4, ArrayValues); + if (!proto[TO_STRING_TAG]) _hide(proto, TO_STRING_TAG, NAME); + _iterators[NAME] = ArrayValues; + if (explicit) for (key in es6_array_iterator) if (!proto[key]) _redefine(proto, key, es6_array_iterator[key], true); + } + } + + var f$1 = _wks; + + var _wksExt = { + f: f$1 + }; + + var defineProperty = _objectDp.f; + var _wksDefine = function (name) { + var $Symbol = _core.Symbol || (_core.Symbol = _library ? {} : _global.Symbol || {}); + if (name.charAt(0) != '_' && !(name in $Symbol)) defineProperty($Symbol, name, { value: _wksExt.f(name) }); + }; + + _wksDefine('asyncIterator'); + + var _meta = createCommonjsModule(function (module) { + var META = _uid('meta'); + + + var setDesc = _objectDp.f; + var id = 0; + var isExtensible = Object.isExtensible || function () { + return true; + }; + var FREEZE = !_fails(function () { + return isExtensible(Object.preventExtensions({})); + }); + var setMeta = function (it) { + setDesc(it, META, { value: { + i: 'O' + ++id, // object ID + w: {} // weak collections IDs + } }); + }; + var fastKey = function (it, create) { + // return primitive with prefix + if (!_isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; + if (!_has(it, META)) { + // can't set metadata to uncaught frozen object + if (!isExtensible(it)) return 'F'; + // not necessary to add metadata + if (!create) return 'E'; + // add missing metadata + setMeta(it); + // return object ID + } return it[META].i; + }; + var getWeak = function (it, create) { + if (!_has(it, META)) { + // can't set metadata to uncaught frozen object + if (!isExtensible(it)) return true; + // not necessary to add metadata + if (!create) return false; + // add missing metadata + setMeta(it); + // return hash weak collections IDs + } return it[META].w; + }; + // add metadata on freeze-family methods calling + var onFreeze = function (it) { + if (FREEZE && meta.NEED && isExtensible(it) && !_has(it, META)) setMeta(it); + return it; + }; + var meta = module.exports = { + KEY: META, + NEED: false, + fastKey: fastKey, + getWeak: getWeak, + onFreeze: onFreeze + }; + }); + var _meta_1 = _meta.KEY; + var _meta_2 = _meta.NEED; + var _meta_3 = _meta.fastKey; + var _meta_4 = _meta.getWeak; + var _meta_5 = _meta.onFreeze; + + var f$2 = Object.getOwnPropertySymbols; + + var _objectGops = { + f: f$2 + }; + + var f$3 = {}.propertyIsEnumerable; + + var _objectPie = { + f: f$3 + }; + + // all enumerable object keys, includes symbols + + + + var _enumKeys = function (it) { + var result = _objectKeys(it); + var getSymbols = _objectGops.f; + if (getSymbols) { + var symbols = getSymbols(it); + var isEnum = _objectPie.f; + var i = 0; + var key; + while (symbols.length > i) if (isEnum.call(it, key = symbols[i++])) result.push(key); + } return result; + }; + + // 7.2.2 IsArray(argument) + + var _isArray = Array.isArray || function isArray(arg) { + return _cof(arg) == 'Array'; + }; + + // 19.1.2.7 / 15.2.3.4 Object.getOwnPropertyNames(O) + + var hiddenKeys = _enumBugKeys.concat('length', 'prototype'); + + var f$4 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { + return _objectKeysInternal(O, hiddenKeys); + }; + + var _objectGopn = { + f: f$4 + }; + + // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window + + var gOPN = _objectGopn.f; + var toString$1 = {}.toString; + + var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames + ? Object.getOwnPropertyNames(window) : []; + + var getWindowNames = function (it) { + try { + return gOPN(it); + } catch (e) { + return windowNames.slice(); + } + }; + + var f$5 = function getOwnPropertyNames(it) { + return windowNames && toString$1.call(it) == '[object Window]' ? getWindowNames(it) : gOPN(_toIobject(it)); + }; + + var _objectGopnExt = { + f: f$5 + }; + + var gOPD = Object.getOwnPropertyDescriptor; + + var f$6 = _descriptors ? gOPD : function getOwnPropertyDescriptor(O, P) { + O = _toIobject(O); + P = _toPrimitive(P, true); + if (_ie8DomDefine) try { + return gOPD(O, P); + } catch (e) { /* empty */ } + if (_has(O, P)) return _propertyDesc(!_objectPie.f.call(O, P), O[P]); + }; + + var _objectGopd = { + f: f$6 + }; + + // ECMAScript 6 symbols shim + + + + + + var META = _meta.KEY; + + + + + + + + + + + + + + + + + + + + var gOPD$1 = _objectGopd.f; + var dP$1 = _objectDp.f; + var gOPN$1 = _objectGopnExt.f; + var $Symbol = _global.Symbol; + var $JSON = _global.JSON; + var _stringify = $JSON && $JSON.stringify; + var PROTOTYPE$2 = 'prototype'; + var HIDDEN = _wks('_hidden'); + var TO_PRIMITIVE = _wks('toPrimitive'); + var isEnum = {}.propertyIsEnumerable; + var SymbolRegistry = _shared('symbol-registry'); + var AllSymbols = _shared('symbols'); + var OPSymbols = _shared('op-symbols'); + var ObjectProto$1 = Object[PROTOTYPE$2]; + var USE_NATIVE = typeof $Symbol == 'function'; + var QObject = _global.QObject; + // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173 + var setter = !QObject || !QObject[PROTOTYPE$2] || !QObject[PROTOTYPE$2].findChild; + + // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687 + var setSymbolDesc = _descriptors && _fails(function () { + return _objectCreate(dP$1({}, 'a', { + get: function () { return dP$1(this, 'a', { value: 7 }).a; } + })).a != 7; + }) ? function (it, key, D) { + var protoDesc = gOPD$1(ObjectProto$1, key); + if (protoDesc) delete ObjectProto$1[key]; + dP$1(it, key, D); + if (protoDesc && it !== ObjectProto$1) dP$1(ObjectProto$1, key, protoDesc); + } : dP$1; + + var wrap = function (tag) { + var sym = AllSymbols[tag] = _objectCreate($Symbol[PROTOTYPE$2]); + sym._k = tag; + return sym; + }; + + var isSymbol = USE_NATIVE && typeof $Symbol.iterator == 'symbol' ? function (it) { + return typeof it == 'symbol'; + } : function (it) { + return it instanceof $Symbol; + }; + + var $defineProperty = function defineProperty(it, key, D) { + if (it === ObjectProto$1) $defineProperty(OPSymbols, key, D); + _anObject(it); + key = _toPrimitive(key, true); + _anObject(D); + if (_has(AllSymbols, key)) { + if (!D.enumerable) { + if (!_has(it, HIDDEN)) dP$1(it, HIDDEN, _propertyDesc(1, {})); + it[HIDDEN][key] = true; + } else { + if (_has(it, HIDDEN) && it[HIDDEN][key]) it[HIDDEN][key] = false; + D = _objectCreate(D, { enumerable: _propertyDesc(0, false) }); + } return setSymbolDesc(it, key, D); + } return dP$1(it, key, D); + }; + var $defineProperties = function defineProperties(it, P) { + _anObject(it); + var keys = _enumKeys(P = _toIobject(P)); + var i = 0; + var l = keys.length; + var key; + while (l > i) $defineProperty(it, key = keys[i++], P[key]); + return it; + }; + var $create = function create(it, P) { + return P === undefined ? _objectCreate(it) : $defineProperties(_objectCreate(it), P); + }; + var $propertyIsEnumerable = function propertyIsEnumerable(key) { + var E = isEnum.call(this, key = _toPrimitive(key, true)); + if (this === ObjectProto$1 && _has(AllSymbols, key) && !_has(OPSymbols, key)) return false; + return E || !_has(this, key) || !_has(AllSymbols, key) || _has(this, HIDDEN) && this[HIDDEN][key] ? E : true; + }; + var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key) { + it = _toIobject(it); + key = _toPrimitive(key, true); + if (it === ObjectProto$1 && _has(AllSymbols, key) && !_has(OPSymbols, key)) return; + var D = gOPD$1(it, key); + if (D && _has(AllSymbols, key) && !(_has(it, HIDDEN) && it[HIDDEN][key])) D.enumerable = true; + return D; + }; + var $getOwnPropertyNames = function getOwnPropertyNames(it) { + var names = gOPN$1(_toIobject(it)); + var result = []; + var i = 0; + var key; + while (names.length > i) { + if (!_has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META) result.push(key); + } return result; + }; + var $getOwnPropertySymbols = function getOwnPropertySymbols(it) { + var IS_OP = it === ObjectProto$1; + var names = gOPN$1(IS_OP ? OPSymbols : _toIobject(it)); + var result = []; + var i = 0; + var key; + while (names.length > i) { + if (_has(AllSymbols, key = names[i++]) && (IS_OP ? _has(ObjectProto$1, key) : true)) result.push(AllSymbols[key]); + } return result; + }; + + // 19.4.1.1 Symbol([description]) + if (!USE_NATIVE) { + $Symbol = function Symbol() { + if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor!'); + var tag = _uid(arguments.length > 0 ? arguments[0] : undefined); + var $set = function (value) { + if (this === ObjectProto$1) $set.call(OPSymbols, value); + if (_has(this, HIDDEN) && _has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; + setSymbolDesc(this, tag, _propertyDesc(1, value)); + }; + if (_descriptors && setter) setSymbolDesc(ObjectProto$1, tag, { configurable: true, set: $set }); + return wrap(tag); + }; + _redefine($Symbol[PROTOTYPE$2], 'toString', function toString() { + return this._k; + }); + + _objectGopd.f = $getOwnPropertyDescriptor; + _objectDp.f = $defineProperty; + _objectGopn.f = _objectGopnExt.f = $getOwnPropertyNames; + _objectPie.f = $propertyIsEnumerable; + _objectGops.f = $getOwnPropertySymbols; + + if (_descriptors && !_library) { + _redefine(ObjectProto$1, 'propertyIsEnumerable', $propertyIsEnumerable, true); + } + + _wksExt.f = function (name) { + return wrap(_wks(name)); + }; + } + + _export(_export.G + _export.W + _export.F * !USE_NATIVE, { Symbol: $Symbol }); + + for (var es6Symbols = ( + // 19.4.2.2, 19.4.2.3, 19.4.2.4, 19.4.2.6, 19.4.2.8, 19.4.2.9, 19.4.2.10, 19.4.2.11, 19.4.2.12, 19.4.2.13, 19.4.2.14 + 'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables' + ).split(','), j = 0; es6Symbols.length > j;)_wks(es6Symbols[j++]); + + for (var wellKnownSymbols = _objectKeys(_wks.store), k = 0; wellKnownSymbols.length > k;) _wksDefine(wellKnownSymbols[k++]); + + _export(_export.S + _export.F * !USE_NATIVE, 'Symbol', { + // 19.4.2.1 Symbol.for(key) + 'for': function (key) { + return _has(SymbolRegistry, key += '') + ? SymbolRegistry[key] + : SymbolRegistry[key] = $Symbol(key); + }, + // 19.4.2.5 Symbol.keyFor(sym) + keyFor: function keyFor(sym) { + if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol!'); + for (var key in SymbolRegistry) if (SymbolRegistry[key] === sym) return key; + }, + useSetter: function () { setter = true; }, + useSimple: function () { setter = false; } + }); + + _export(_export.S + _export.F * !USE_NATIVE, 'Object', { + // 19.1.2.2 Object.create(O [, Properties]) + create: $create, + // 19.1.2.4 Object.defineProperty(O, P, Attributes) + defineProperty: $defineProperty, + // 19.1.2.3 Object.defineProperties(O, Properties) + defineProperties: $defineProperties, + // 19.1.2.6 Object.getOwnPropertyDescriptor(O, P) + getOwnPropertyDescriptor: $getOwnPropertyDescriptor, + // 19.1.2.7 Object.getOwnPropertyNames(O) + getOwnPropertyNames: $getOwnPropertyNames, + // 19.1.2.8 Object.getOwnPropertySymbols(O) + getOwnPropertySymbols: $getOwnPropertySymbols + }); + + // 24.3.2 JSON.stringify(value [, replacer [, space]]) + $JSON && _export(_export.S + _export.F * (!USE_NATIVE || _fails(function () { + var S = $Symbol(); + // MS Edge converts symbol values to JSON as {} + // WebKit converts symbol values to JSON as null + // V8 throws on boxed symbols + return _stringify([S]) != '[null]' || _stringify({ a: S }) != '{}' || _stringify(Object(S)) != '{}'; + })), 'JSON', { + stringify: function stringify(it) { + var args = [it]; + var i = 1; + var replacer, $replacer; + while (arguments.length > i) args.push(arguments[i++]); + $replacer = replacer = args[1]; + if (!_isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined + if (!_isArray(replacer)) replacer = function (key, value) { + if (typeof $replacer == 'function') value = $replacer.call(this, key, value); + if (!isSymbol(value)) return value; + }; + args[1] = replacer; + return _stringify.apply($JSON, args); + } + }); + + // 19.4.3.4 Symbol.prototype[@@toPrimitive](hint) + $Symbol[PROTOTYPE$2][TO_PRIMITIVE] || _hide($Symbol[PROTOTYPE$2], TO_PRIMITIVE, $Symbol[PROTOTYPE$2].valueOf); + // 19.4.3.5 Symbol.prototype[@@toStringTag] + _setToStringTag($Symbol, 'Symbol'); + // 20.2.1.9 Math[@@toStringTag] + _setToStringTag(Math, 'Math', true); + // 24.3.3 JSON[@@toStringTag] + _setToStringTag(_global.JSON, 'JSON', true); + + var _anInstance = function (it, Constructor, name, forbiddenField) { + if (!(it instanceof Constructor) || (forbiddenField !== undefined && forbiddenField in it)) { + throw TypeError(name + ': incorrect invocation!'); + } return it; + }; + + var _forOf = createCommonjsModule(function (module) { + var BREAK = {}; + var RETURN = {}; + var exports = module.exports = function (iterable, entries, fn, that, ITERATOR) { + var iterFn = ITERATOR ? function () { return iterable; } : core_getIteratorMethod(iterable); + var f = _ctx(fn, that, entries ? 2 : 1); + var index = 0; + var length, step, iterator, result; + if (typeof iterFn != 'function') throw TypeError(iterable + ' is not iterable!'); + // fast case for arrays with default iterator + if (_isArrayIter(iterFn)) for (length = _toLength(iterable.length); length > index; index++) { + result = entries ? f(_anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); + if (result === BREAK || result === RETURN) return result; + } else for (iterator = iterFn.call(iterable); !(step = iterator.next()).done;) { + result = _iterCall(iterator, f, step.value, entries); + if (result === BREAK || result === RETURN) return result; + } + }; + exports.BREAK = BREAK; + exports.RETURN = RETURN; + }); + + // 7.3.20 SpeciesConstructor(O, defaultConstructor) + + + var SPECIES = _wks('species'); + var _speciesConstructor = function (O, D) { + var C = _anObject(O).constructor; + var S; + return C === undefined || (S = _anObject(C)[SPECIES]) == undefined ? D : _aFunction(S); + }; + + // fast apply, http://jsperf.lnkit.com/fast-apply/5 + var _invoke = function (fn, args, that) { + var un = that === undefined; + switch (args.length) { + case 0: return un ? fn() + : fn.call(that); + case 1: return un ? fn(args[0]) + : fn.call(that, args[0]); + case 2: return un ? fn(args[0], args[1]) + : fn.call(that, args[0], args[1]); + case 3: return un ? fn(args[0], args[1], args[2]) + : fn.call(that, args[0], args[1], args[2]); + case 4: return un ? fn(args[0], args[1], args[2], args[3]) + : fn.call(that, args[0], args[1], args[2], args[3]); + } return fn.apply(that, args); + }; + + var process = _global.process; + var setTask = _global.setImmediate; + var clearTask = _global.clearImmediate; + var MessageChannel = _global.MessageChannel; + var Dispatch = _global.Dispatch; + var counter = 0; + var queue = {}; + var ONREADYSTATECHANGE = 'onreadystatechange'; + var defer, channel, port; + var run = function () { + var id = +this; + // eslint-disable-next-line no-prototype-builtins + if (queue.hasOwnProperty(id)) { + var fn = queue[id]; + delete queue[id]; + fn(); + } + }; + var listener = function (event) { + run.call(event.data); + }; + // Node.js 0.9+ & IE10+ has setImmediate, otherwise: + if (!setTask || !clearTask) { + setTask = function setImmediate(fn) { + var args = []; + var i = 1; + while (arguments.length > i) args.push(arguments[i++]); + queue[++counter] = function () { + // eslint-disable-next-line no-new-func + _invoke(typeof fn == 'function' ? fn : Function(fn), args); + }; + defer(counter); + return counter; + }; + clearTask = function clearImmediate(id) { + delete queue[id]; + }; + // Node.js 0.8- + if (_cof(process) == 'process') { + defer = function (id) { + process.nextTick(_ctx(run, id, 1)); + }; + // Sphere (JS game engine) Dispatch API + } else if (Dispatch && Dispatch.now) { + defer = function (id) { + Dispatch.now(_ctx(run, id, 1)); + }; + // Browsers with MessageChannel, includes WebWorkers + } else if (MessageChannel) { + channel = new MessageChannel(); + port = channel.port2; + channel.port1.onmessage = listener; + defer = _ctx(port.postMessage, port, 1); + // Browsers with postMessage, skip WebWorkers + // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' + } else if (_global.addEventListener && typeof postMessage == 'function' && !_global.importScripts) { + defer = function (id) { + _global.postMessage(id + '', '*'); + }; + _global.addEventListener('message', listener, false); + // IE8- + } else if (ONREADYSTATECHANGE in _domCreate('script')) { + defer = function (id) { + _html.appendChild(_domCreate('script'))[ONREADYSTATECHANGE] = function () { + _html.removeChild(this); + run.call(id); + }; + }; + // Rest old browsers + } else { + defer = function (id) { + setTimeout(_ctx(run, id, 1), 0); + }; + } + } + var _task = { + set: setTask, + clear: clearTask + }; + + var macrotask = _task.set; + var Observer = _global.MutationObserver || _global.WebKitMutationObserver; + var process$1 = _global.process; + var Promise$1 = _global.Promise; + var isNode = _cof(process$1) == 'process'; + + var _microtask = function () { + var head, last, notify; + + var flush = function () { + var parent, fn; + if (isNode && (parent = process$1.domain)) parent.exit(); + while (head) { + fn = head.fn; + head = head.next; + try { + fn(); + } catch (e) { + if (head) notify(); + else last = undefined; + throw e; + } + } last = undefined; + if (parent) parent.enter(); + }; + + // Node.js + if (isNode) { + notify = function () { + process$1.nextTick(flush); + }; + // browsers with MutationObserver, except iOS Safari - https://github.com/zloirock/core-js/issues/339 + } else if (Observer && !(_global.navigator && _global.navigator.standalone)) { + var toggle = true; + var node = document.createTextNode(''); + new Observer(flush).observe(node, { characterData: true }); // eslint-disable-line no-new + notify = function () { + node.data = toggle = !toggle; + }; + // environments with maybe non-completely correct, but existent Promise + } else if (Promise$1 && Promise$1.resolve) { + var promise = Promise$1.resolve(); + notify = function () { + promise.then(flush); + }; + // for other environments - macrotask based on: + // - setImmediate + // - MessageChannel + // - window.postMessag + // - onreadystatechange + // - setTimeout + } else { + notify = function () { + // strange IE + webpack dev server bug - use .call(global) + macrotask.call(_global, flush); + }; + } + + return function (fn) { + var task = { fn: fn, next: undefined }; + if (last) last.next = task; + if (!head) { + head = task; + notify(); + } last = task; + }; + }; + + // 25.4.1.5 NewPromiseCapability(C) + + + function PromiseCapability(C) { + var resolve, reject; + this.promise = new C(function ($$resolve, $$reject) { + if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); + resolve = $$resolve; + reject = $$reject; + }); + this.resolve = _aFunction(resolve); + this.reject = _aFunction(reject); + } + + var f$7 = function (C) { + return new PromiseCapability(C); + }; + + var _newPromiseCapability = { + f: f$7 + }; + + var _perform = function (exec) { + try { + return { e: false, v: exec() }; + } catch (e) { + return { e: true, v: e }; + } + }; + + var _promiseResolve = function (C, x) { + _anObject(C); + if (_isObject(x) && x.constructor === C) return x; + var promiseCapability = _newPromiseCapability.f(C); + var resolve = promiseCapability.resolve; + resolve(x); + return promiseCapability.promise; + }; + + var _redefineAll = function (target, src, safe) { + for (var key in src) _redefine(target, key, src[key], safe); + return target; + }; + + var SPECIES$1 = _wks('species'); + + var _setSpecies = function (KEY) { + var C = _global[KEY]; + if (_descriptors && C && !C[SPECIES$1]) _objectDp.f(C, SPECIES$1, { + configurable: true, + get: function () { return this; } + }); + }; + + var task = _task.set; + var microtask = _microtask(); + + + + var PROMISE = 'Promise'; + var TypeError$1 = _global.TypeError; + var process$2 = _global.process; + var $Promise = _global[PROMISE]; + var isNode$1 = _classof(process$2) == 'process'; + var empty = function () { /* empty */ }; + var Internal, newGenericPromiseCapability, OwnPromiseCapability, Wrapper; + var newPromiseCapability = newGenericPromiseCapability = _newPromiseCapability.f; + + var USE_NATIVE$1 = !!function () { + try { + // correct subclassing with @@species support + var promise = $Promise.resolve(1); + var FakePromise = (promise.constructor = {})[_wks('species')] = function (exec) { + exec(empty, empty); + }; + // unhandled rejections tracking support, NodeJS Promise without it fails @@species test + return (isNode$1 || typeof PromiseRejectionEvent == 'function') && promise.then(empty) instanceof FakePromise; + } catch (e) { /* empty */ } + }(); + + // helpers + var isThenable = function (it) { + var then; + return _isObject(it) && typeof (then = it.then) == 'function' ? then : false; + }; + var notify = function (promise, isReject) { + if (promise._n) return; + promise._n = true; + var chain = promise._c; + microtask(function () { + var value = promise._v; + var ok = promise._s == 1; + var i = 0; + var run = function (reaction) { + var handler = ok ? reaction.ok : reaction.fail; + var resolve = reaction.resolve; + var reject = reaction.reject; + var domain = reaction.domain; + var result, then, exited; + try { + if (handler) { + if (!ok) { + if (promise._h == 2) onHandleUnhandled(promise); + promise._h = 1; + } + if (handler === true) result = value; + else { + if (domain) domain.enter(); + result = handler(value); // may throw + if (domain) { + domain.exit(); + exited = true; + } + } + if (result === reaction.promise) { + reject(TypeError$1('Promise-chain cycle')); + } else if (then = isThenable(result)) { + then.call(result, resolve, reject); + } else resolve(result); + } else reject(value); + } catch (e) { + if (domain && !exited) domain.exit(); + reject(e); + } + }; + while (chain.length > i) run(chain[i++]); // variable length - can't use forEach + promise._c = []; + promise._n = false; + if (isReject && !promise._h) onUnhandled(promise); + }); + }; + var onUnhandled = function (promise) { + task.call(_global, function () { + var value = promise._v; + var unhandled = isUnhandled(promise); + var result, handler, console; + if (unhandled) { + result = _perform(function () { + if (isNode$1) { + process$2.emit('unhandledRejection', value, promise); + } else if (handler = _global.onunhandledrejection) { + handler({ promise: promise, reason: value }); + } else if ((console = _global.console) && console.error) { + console.error('Unhandled promise rejection', value); + } + }); + // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should + promise._h = isNode$1 || isUnhandled(promise) ? 2 : 1; + } promise._a = undefined; + if (unhandled && result.e) throw result.v; + }); + }; + var isUnhandled = function (promise) { + return promise._h !== 1 && (promise._a || promise._c).length === 0; + }; + var onHandleUnhandled = function (promise) { + task.call(_global, function () { + var handler; + if (isNode$1) { + process$2.emit('rejectionHandled', promise); + } else if (handler = _global.onrejectionhandled) { + handler({ promise: promise, reason: promise._v }); + } + }); + }; + var $reject = function (value) { + var promise = this; + if (promise._d) return; + promise._d = true; + promise = promise._w || promise; // unwrap + promise._v = value; + promise._s = 2; + if (!promise._a) promise._a = promise._c.slice(); + notify(promise, true); + }; + var $resolve = function (value) { + var promise = this; + var then; + if (promise._d) return; + promise._d = true; + promise = promise._w || promise; // unwrap + try { + if (promise === value) throw TypeError$1("Promise can't be resolved itself"); + if (then = isThenable(value)) { + microtask(function () { + var wrapper = { _w: promise, _d: false }; // wrap + try { + then.call(value, _ctx($resolve, wrapper, 1), _ctx($reject, wrapper, 1)); + } catch (e) { + $reject.call(wrapper, e); + } + }); + } else { + promise._v = value; + promise._s = 1; + notify(promise, false); + } + } catch (e) { + $reject.call({ _w: promise, _d: false }, e); // wrap + } + }; + + // constructor polyfill + if (!USE_NATIVE$1) { + // 25.4.3.1 Promise(executor) + $Promise = function Promise(executor) { + _anInstance(this, $Promise, PROMISE, '_h'); + _aFunction(executor); + Internal.call(this); + try { + executor(_ctx($resolve, this, 1), _ctx($reject, this, 1)); + } catch (err) { + $reject.call(this, err); + } + }; + // eslint-disable-next-line no-unused-vars + Internal = function Promise(executor) { + this._c = []; // <- awaiting reactions + this._a = undefined; // <- checked in isUnhandled reactions + this._s = 0; // <- state + this._d = false; // <- done + this._v = undefined; // <- value + this._h = 0; // <- rejection state, 0 - default, 1 - handled, 2 - unhandled + this._n = false; // <- notify + }; + Internal.prototype = _redefineAll($Promise.prototype, { + // 25.4.5.3 Promise.prototype.then(onFulfilled, onRejected) + then: function then(onFulfilled, onRejected) { + var reaction = newPromiseCapability(_speciesConstructor(this, $Promise)); + reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; + reaction.fail = typeof onRejected == 'function' && onRejected; + reaction.domain = isNode$1 ? process$2.domain : undefined; + this._c.push(reaction); + if (this._a) this._a.push(reaction); + if (this._s) notify(this, false); + return reaction.promise; + }, + // 25.4.5.1 Promise.prototype.catch(onRejected) + 'catch': function (onRejected) { + return this.then(undefined, onRejected); + } + }); + OwnPromiseCapability = function () { + var promise = new Internal(); + this.promise = promise; + this.resolve = _ctx($resolve, promise, 1); + this.reject = _ctx($reject, promise, 1); + }; + _newPromiseCapability.f = newPromiseCapability = function (C) { + return C === $Promise || C === Wrapper + ? new OwnPromiseCapability(C) + : newGenericPromiseCapability(C); + }; + } + + _export(_export.G + _export.W + _export.F * !USE_NATIVE$1, { Promise: $Promise }); + _setToStringTag($Promise, PROMISE); + _setSpecies(PROMISE); + Wrapper = _core[PROMISE]; + + // statics + _export(_export.S + _export.F * !USE_NATIVE$1, PROMISE, { + // 25.4.4.5 Promise.reject(r) + reject: function reject(r) { + var capability = newPromiseCapability(this); + var $$reject = capability.reject; + $$reject(r); + return capability.promise; + } + }); + _export(_export.S + _export.F * (_library || !USE_NATIVE$1), PROMISE, { + // 25.4.4.6 Promise.resolve(x) + resolve: function resolve(x) { + return _promiseResolve(_library && this === Wrapper ? $Promise : this, x); + } + }); + _export(_export.S + _export.F * !(USE_NATIVE$1 && _iterDetect(function (iter) { + $Promise.all(iter)['catch'](empty); + })), PROMISE, { + // 25.4.4.1 Promise.all(iterable) + all: function all(iterable) { + var C = this; + var capability = newPromiseCapability(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = _perform(function () { + var values = []; + var index = 0; + var remaining = 1; + _forOf(iterable, false, function (promise) { + var $index = index++; + var alreadyCalled = false; + values.push(undefined); + remaining++; + C.resolve(promise).then(function (value) { + if (alreadyCalled) return; + alreadyCalled = true; + values[$index] = value; + --remaining || resolve(values); + }, reject); + }); + --remaining || resolve(values); + }); + if (result.e) reject(result.v); + return capability.promise; + }, + // 25.4.4.4 Promise.race(iterable) + race: function race(iterable) { + var C = this; + var capability = newPromiseCapability(C); + var reject = capability.reject; + var result = _perform(function () { + _forOf(iterable, false, function (promise) { + C.resolve(promise).then(capability.resolve, reject); + }); + }); + if (result.e) reject(result.v); + return capability.promise; + } + }); + + // 19.1.2.1 Object.assign(target, source, ...) + + + + + + var $assign = Object.assign; + + // should work with symbols and should have deterministic property order (V8 bug) + var _objectAssign = !$assign || _fails(function () { + var A = {}; + var B = {}; + // eslint-disable-next-line no-undef + var S = Symbol(); + var K = 'abcdefghijklmnopqrst'; + A[S] = 7; + K.split('').forEach(function (k) { B[k] = k; }); + return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K; + }) ? function assign(target, source) { // eslint-disable-line no-unused-vars + var T = _toObject(target); + var aLen = arguments.length; + var index = 1; + var getSymbols = _objectGops.f; + var isEnum = _objectPie.f; + while (aLen > index) { + var S = _iobject(arguments[index++]); + var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S); + var length = keys.length; + var j = 0; + var key; + while (length > j) if (isEnum.call(S, key = keys[j++])) T[key] = S[key]; + } return T; + } : $assign; + + // 19.1.3.1 Object.assign(target, source) + + + _export(_export.S + _export.F, 'Object', { assign: _objectAssign }); + + /*! ***************************************************************************** + 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 __()); + } + + // typeof any so that it we don't have to cast when comparing a result to the error object + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var errorObject = { + e: {} + }; + + /** PURE_IMPORTS_START ._errorObject PURE_IMPORTS_END */ + var tryCatchTarget; + + function tryCatcher() { + try { + return tryCatchTarget.apply(this, arguments); + } catch (e) { + errorObject.e = e; + return errorObject; + } + } + + function tryCatch(fn) { + tryCatchTarget = fn; + return tryCatcher; + } + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function isFunction(x) { + return typeof x === 'function'; + } + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var empty$1 = { + closed: true, + next: function next(value) {}, + error: function error(err) { + throw err; + }, + complete: function complete() {} + }; + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var isArray = Array.isArray || function (x) { + return x && typeof x.length === 'number'; + }; + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function isObject(x) { + return x != null && typeof x === 'object'; + } + + /** PURE_IMPORTS_START tslib PURE_IMPORTS_END */ + /** + * An error thrown when one or more errors have occurred during the + * `unsubscribe` of a {@link Subscription}. + */ + + var UnsubscriptionError = + /*@__PURE__*/ + function (_super) { + __extends(UnsubscriptionError, _super); + + function UnsubscriptionError(errors) { + var _this = _super.call(this, errors ? errors.length + " errors occurred during unsubscription:\n " + errors.map(function (err, i) { + return i + 1 + ") " + err.toString(); + }).join('\n ') : '') || this; + + _this.errors = errors; + _this.name = 'UnsubscriptionError'; + Object.setPrototypeOf(_this, UnsubscriptionError.prototype); + return _this; + } + + return UnsubscriptionError; + }(Error); + + /** PURE_IMPORTS_START ._util_isArray,._util_isObject,._util_isFunction,._util_tryCatch,._util_errorObject,._util_UnsubscriptionError PURE_IMPORTS_END */ + /** + * 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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; + /** @internal */ + + this._parent = null; + /** @internal */ + + this._parents = null; + /** @internal */ + + 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); + } + } + }; + /** @internal */ + + + 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); + }, []); + } + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var rxSubscriber = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? + /*@__PURE__*/ + Symbol.for('rxSubscriber') : '@@rxSubscriber'; + + /** PURE_IMPORTS_START tslib,._util_isFunction,._Observer,._Subscription,.._internal_symbol_rxSubscriber PURE_IMPORTS_END */ + /** + * 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 + */ + + var Subscriber = + /*@__PURE__*/ + 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) { + var _this = _super.call(this) || this; + + _this.isStopped = false; + + switch (arguments.length) { + case 0: + _this.destination = empty$1; + break; + + case 1: + if (!destinationOrNext) { + _this.destination = empty$1; + break; + } + + if (typeof destinationOrNext === 'object') { + if (destinationOrNext instanceof Subscriber) { + _this.destination = destinationOrNext; + + _this.destination.add(_this); + } else { + _this.destination = new SafeSubscriber(destinationOrNext); + } + + break; + } + + default: + _this.destination = new SafeSubscriber(destinationOrNext, error, complete); + break; + } + + return _this; + } + + 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} 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); + 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(); + }; + + 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 = + /*@__PURE__*/ + function (_super) { + __extends(SafeSubscriber, _super); + + function SafeSubscriber(observerOrNext, error, complete) { + var _this = _super.call(this) || this; + + 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$1) { + 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; + return _this; + } + + SafeSubscriber.prototype.next = function (value) { + if (!this.isStopped && this._next) { + try { + this._next.call(this._context, value); + } catch (err) { + this._hostReportError(err); + + this.unsubscribe(); + } + } + }; + + SafeSubscriber.prototype.error = function (err) { + if (!this.isStopped) { + if (this._error) { + try { + this._error.call(this._context, err); + } catch (err) { + this._hostReportError(err); + } + } else { + this._hostReportError(err); + } + + this.unsubscribe(); + } + }; + + SafeSubscriber.prototype.complete = function () { + if (!this.isStopped) { + if (this._complete) { + try { + this._complete.call(this._context); + } catch (err) { + this._hostReportError(err); + } + } + + this.unsubscribe(); + } + }; + + SafeSubscriber.prototype._unsubscribe = function () { + this._context = null; + }; + + SafeSubscriber.prototype._hostReportError = function (err) { + setTimeout(function () { + throw err; + }); + }; + + return SafeSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var OuterSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(OuterSubscriber, _super); + + function OuterSubscriber() { + return _super !== null && _super.apply(this, arguments) || this; + } + + 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); + + /** PURE_IMPORTS_START tslib,._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @internal + * @ignore + * @extends {Ignored} + */ + + var InnerSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(InnerSubscriber, _super); + + function InnerSubscriber(parent, outerValue, outerIndex) { + var _this = _super.call(this) || this; + + _this.parent = parent; + _this.outerValue = outerValue; + _this.outerIndex = outerIndex; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._Subscriber,.._symbol_rxSubscriber,.._Observer PURE_IMPORTS_END */ + 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$1); + } + + return new Subscriber(nextOrObserver, error, complete); + } + + /** Symbol.observable or a string "@@observable". Used for interop */ + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var observable = typeof Symbol === 'function' && Symbol.observable || '@@observable'; + + /* tslint:disable:no-empty */ + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function noop() {} + + /** PURE_IMPORTS_START ._noop PURE_IMPORTS_END */ + /* @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); + }; + } + + /** + * The global configuration object for RxJS, used to configure things + * like what Promise contructor should used to create Promises + */ + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var config = { + /** + * The promise constructor used by default for methods such as + * {@link toPromise} and {@link forEach} + */ + Promise: Promise + }; + + /** + * A representation of any set of values over any amount of time. This is the most basic building block + * of RxJS. + * + * @class Observable + */ + + var Observable = + /*@__PURE__*/ + + /*@__PURE__*/ + 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) { + /** @internal */ + 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. + * + * Use it when you have all these Observables, but still nothing is happening. + * + * `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 Subscribe with an Observer + * 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 Subscribe with functions + * 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 Cancel a subscription + * 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 ? this._subscribe(sink) : this._trySubscribe(sink)); + } + + return sink; + }; + + Observable.prototype._trySubscribe = function (sink) { + try { + return this._subscribe(sink); + } catch (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; + + promiseCtor = getPromiseCtor(promiseCtor); + 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) { + try { + next(value); + } catch (err) { + reject(err); + + if (subscription) { + subscription.unsubscribe(); + } + } + }, reject, resolve); + }); + }; + /** @internal */ + + + 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/internal/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] = 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; + + promiseCtor = getPromiseCtor(promiseCtor); + 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; + }(); + /** + * Decides between a passed promise constructor from consuming code, + * A default configured promise constructor, and the native promise + * constructor and returns it. If nothing can be found, it will throw + * an error. + * @param promiseCtor The optional promise constructor to passed by consuming code + */ + + function getPromiseCtor(promiseCtor) { + if (!promiseCtor) { + promiseCtor = config.Promise || Promise; + } + + if (!promiseCtor) { + throw new Error('no Promise impl found'); + } + + return promiseCtor; + } + + /** + * Subscribes to an ArrayLike with a subscriber + * @param array The array or array-like to subscribe to + * @param subscriber The subscriber to subscribe with. + */ + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var subscribeToArray = function subscribeToArray(array) { + return function (subscriber) { + for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) { + subscriber.next(array[i]); + } + + if (!subscriber.closed) { + subscriber.complete(); + } + }; + }; + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var subscribeToPromise = function subscribeToPromise(promise) { + return function (subscriber) { + promise.then(function (value) { + if (!subscriber.closed) { + subscriber.next(value); + subscriber.complete(); + } + }, function (err) { + return subscriber.error(err); + }).then(null, function (err) { + // Escaping the Promise trap: globally throw unhandled errors + setTimeout(function () { + throw err; + }); + }); + return subscriber; + }; + }; + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function getSymbolIterator() { + if (typeof Symbol !== 'function' || !Symbol.iterator) { + return '@@iterator'; + } + + return Symbol.iterator; + } + var iterator = + /*@__PURE__*/ + getSymbolIterator(); + + /** PURE_IMPORTS_START .._symbol_iterator PURE_IMPORTS_END */ + var subscribeToIterable = function subscribeToIterable(iterable) { + return function (subscriber) { + var iterator$$1 = iterable[iterator](); + + do { + var item = iterator$$1.next(); + + if (item.done) { + subscriber.complete(); + break; + } + + subscriber.next(item.value); + + if (subscriber.closed) { + break; + } + } while (true); // Finalize the iterator if it happens to be a Generator + + + if (typeof iterator$$1.return === 'function') { + subscriber.add(function () { + if (iterator$$1.return) { + iterator$$1.return(); + } + }); + } + + return subscriber; + }; + }; + + /** PURE_IMPORTS_START .._symbol_observable PURE_IMPORTS_END */ + /** + * Subscribes to an object that implements Symbol.observable with the given + * Subscriber. + * @param obj An object that implements Symbol.observable + * @param subscriber The Subscriber to use to subscribe to the observable + */ + + var subscribeToObservable = function subscribeToObservable(obj) { + return function (subscriber) { + var obs = obj[observable](); + + if (typeof obs.subscribe !== 'function') { + // Should be caught by observable subscribe function error handling. + throw new TypeError('Provided object does not correctly implement Symbol.observable'); + } else { + return obs.subscribe(subscriber); + } + }; + }; + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + var isArrayLike = function isArrayLike(x) { + return x && typeof x.length === 'number'; + }; + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function isPromise(value) { + return value && typeof value.subscribe !== 'function' && typeof value.then === 'function'; + } + + /** PURE_IMPORTS_START .._Observable,._subscribeToArray,._subscribeToPromise,._subscribeToIterable,._subscribeToObservable,._isArrayLike,._isPromise,._isObject,.._symbol_iterator,.._symbol_observable PURE_IMPORTS_END */ + var subscribeTo = function subscribeTo(result) { + if (result instanceof Observable) { + return function (subscriber) { + if (result._isScalar) { + subscriber.next(result.value); + subscriber.complete(); + return undefined; + } else { + return result.subscribe(subscriber); + } + }; + } else if (isArrayLike(result)) { + return subscribeToArray(result); + } else if (isPromise(result)) { + return subscribeToPromise(result); + } else if (result && typeof result[iterator] === 'function') { + return subscribeToIterable(result); + } else if (result && typeof result[observable] === 'function') { + return subscribeToObservable(result); + } 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.'; + throw new TypeError(msg); + } + }; + + /** PURE_IMPORTS_START .._InnerSubscriber,._subscribeTo PURE_IMPORTS_END */ + function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) { + var destination = new InnerSubscriber(outerSubscriber, outerValue, outerIndex); + return subscribeTo(result)(destination); + } + + /** PURE_IMPORTS_START tslib,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var AuditSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(AuditSubscriber, _super); + + function AuditSubscriber(destination, durationSelector) { + var _this = _super.call(this, destination) || this; + + _this.durationSelector = durationSelector; + _this.hasValue = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscription PURE_IMPORTS_END */ + /** + * 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 extends Subscription { + * new (scheduler: Scheduler, work: (state?: T) => void); + * schedule(state?: T, delay: number = 0): Subscription; + * } + * ``` + * + * @class Action + */ + + var Action = + /*@__PURE__*/ + function (_super) { + __extends(Action, _super); + + function Action(scheduler, work) { + return _super.call(this) || 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); + + /** PURE_IMPORTS_START tslib,._Action PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var AsyncAction = + /*@__PURE__*/ + function (_super) { + __extends(AsyncAction, _super); + + function AsyncAction(scheduler, work) { + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + _this.pending = false; + return _this; + } + + 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; + 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); + } // Set the pending flag indicating that this action has been scheduled, or + // has recursively rescheduled itself. + + + this.pending = true; + 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 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 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; + } + }; + + 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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; + }(); + + /** PURE_IMPORTS_START tslib,.._Scheduler PURE_IMPORTS_END */ + + var AsyncScheduler = + /*@__PURE__*/ + function (_super) { + __extends(AsyncScheduler, _super); + + function AsyncScheduler() { + var _this = _super !== null && _super.apply(this, arguments) || this; + + _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; + return _this; + } + + 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); + + /** PURE_IMPORTS_START ._AsyncAction,._AsyncScheduler PURE_IMPORTS_END */ + /** + * + * Async Scheduler + * + * Schedule task as if you used setTimeout(task, duration) + * + * `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 Use async scheduler to delay task + * const task = () => console.log('it works!'); + * + * Rx.Scheduler.async.schedule(task, 2000); + * + * // After 2 seconds logs: + * // "it works!" + * + * + * @example Use async scheduler to repeat task in intervals + * 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 = + /*@__PURE__*/ + new AsyncScheduler(AsyncAction); + + /** PURE_IMPORTS_START ._isArray PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function isScheduler(value) { + return value && typeof value.schedule === 'function'; + } + + /** PURE_IMPORTS_START .._Observable,.._scheduler_async,.._util_isNumeric,.._util_isScheduler PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._scheduler_async,._audit,.._observable_timer PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var BufferSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(BufferSubscriber, _super); + + function BufferSubscriber(destination, closingNotifier) { + var _this = _super.call(this, destination) || this; + + _this.buffer = []; + + _this.add(subscribeToResult(_this, closingNotifier)); + + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var BufferCountSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(BufferCountSubscriber, _super); + + function BufferCountSubscriber(destination, bufferSize) { + var _this = _super.call(this, destination) || this; + + _this.bufferSize = bufferSize; + _this.buffer = []; + return _this; + } + + 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 = + /*@__PURE__*/ + function (_super) { + __extends(BufferSkipCountSubscriber, _super); + + function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) { + var _this = _super.call(this, destination) || this; + + _this.bufferSize = bufferSize; + _this.startBufferEvery = startBufferEvery; + _this.buffers = []; + _this.count = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._scheduler_async,.._Subscriber,.._util_isScheduler PURE_IMPORTS_END */ + + var Context = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function Context() { + this.buffer = []; + } + + return Context; + }(); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var BufferTimeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(BufferTimeSubscriber, _super); + + function BufferTimeSubscriber(destination, bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) { + var _this = _super.call(this, destination) || this; + + _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)); + } + + return _this; + } + + BufferTimeSubscriber.prototype._next = function (value) { + var contexts = this.contexts; + var len = contexts.length; + var filledBufferContext; + + for (var i = 0; i < len; i++) { + var context_1 = contexts[i]; + var buffer = context_1.buffer; + buffer.push(value); + + if (buffer.length == this.maxBufferSize) { + filledBufferContext = context_1; + } + } + + 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_2 = contexts.shift(); + destination.next(context_2.buffer); + } + + _super.prototype._complete.call(this); + }; + + 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); + } + + /** PURE_IMPORTS_START tslib,.._Subscription,.._util_subscribeToResult,.._OuterSubscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var BufferToggleSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(BufferToggleSubscriber, _super); + + function BufferToggleSubscriber(destination, openings, closingSelector) { + var _this = _super.call(this, destination) || this; + + _this.openings = openings; + _this.closingSelector = closingSelector; + _this.contexts = []; + + _this.add(subscribeToResult(_this, openings)); + + return _this; + } + + 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_1 = contexts.shift(); + context_1.subscription.unsubscribe(); + context_1.buffer = null; + context_1.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_2 = contexts.shift(); + this.destination.next(context_2.buffer); + context_2.subscription.unsubscribe(); + context_2.buffer = null; + context_2.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); + + /** PURE_IMPORTS_START tslib,.._Subscription,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var BufferWhenSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(BufferWhenSubscriber, _super); + + function BufferWhenSubscriber(destination, closingSelector) { + var _this = _super.call(this, destination) || this; + + _this.closingSelector = closingSelector; + _this.subscribing = false; + + _this.openBuffer(); + + return _this; + } + + 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); + }; + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var CatchSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(CatchSubscriber, _super); + + function CatchSubscriber(destination, selector, caught) { + var _this = _super.call(this, destination) || this; + + _this.selector = selector; + _this.caught = caught; + return _this; + } // 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); + + /** PURE_IMPORTS_START .._Observable,.._Subscription,.._util_subscribeToArray PURE_IMPORTS_END */ + function fromArray(input, scheduler) { + if (!scheduler) { + return new Observable(subscribeToArray(input)); + } else { + return new Observable(function (subscriber) { + var sub = new Subscription(); + var i = 0; + sub.add(scheduler.schedule(function () { + if (i === input.length) { + subscriber.complete(); + return; + } + + subscriber.next(input[i++]); + + if (!subscriber.closed) { + sub.add(this.schedule()); + } + })); + return sub; + }); + } + } + + /** PURE_IMPORTS_START tslib,.._util_isScheduler,.._util_isArray,.._OuterSubscriber,.._util_subscribeToResult,._fromArray PURE_IMPORTS_END */ + 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. + * + * 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. + * + * + * + * `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 Combine two timer Observables + * 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 Combine an array of Observables + * 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 Use project function to dynamically calculate the Body-Mass Index + * 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() { + var observables = []; + + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i] = 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 fromArray(observables, scheduler).lift(new CombineLatestOperator(project)); + } + + var CombineLatestOperator = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(CombineLatestSubscriber, _super); + + function CombineLatestSubscriber(destination, project) { + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.active = 0; + _this.values = []; + _this.observables = []; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._observable_combineLatest PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._util_subscribeToResult,.._OuterSubscriber PURE_IMPORTS_END */ + /* tslint:enable:max-line-length */ + + /** + * Projects each source value to an Observable which is merged in the output + * Observable. + * + * Maps each value to an Observable, then flattens all of + * these inner Observables using {@link mergeAll}. + * + * + * + * 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 Map and flatten each letter to an Observable ticking every 1 second + * 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 {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, concurrent) { + if (concurrent === void 0) { + concurrent = Number.POSITIVE_INFINITY; + } + + return function mergeMapOperatorFunction(source) { + return source.lift(new MergeMapOperator(project, concurrent)); + }; + } + + var MergeMapOperator = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function MergeMapOperator(project, concurrent) { + if (concurrent === void 0) { + concurrent = Number.POSITIVE_INFINITY; + } + + this.project = project; + this.concurrent = concurrent; + } + + MergeMapOperator.prototype.call = function (observer, source) { + return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent)); + }; + + return MergeMapOperator; + }(); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var MergeMapSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(MergeMapSubscriber, _super); + + function MergeMapSubscriber(destination, project, concurrent) { + if (concurrent === void 0) { + concurrent = Number.POSITIVE_INFINITY; + } + + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.concurrent = concurrent; + _this.hasCompleted = false; + _this.buffer = []; + _this.active = 0; + _this.index = 0; + return _this; + } + + 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) { + this.destination.next(innerValue); + }; + + 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); + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + function identity(x) { + return x; + } + + /** PURE_IMPORTS_START ._mergeMap,.._util_identity PURE_IMPORTS_END */ + /** + * Converts a higher-order Observable into a first-order Observable which + * concurrently delivers all values that are emitted on the inner Observables. + * + * Flattens an Observable-of-Observables. + * + * + * + * `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 Spawn a new interval Observable for each click event, and blend their outputs as one Observable + * 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 Count from 0 to 9 every second for each click, but only allow 2 concurrent timers + * 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, concurrent); + } + + /** PURE_IMPORTS_START ._mergeAll PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START ._mergeMap PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START ._concatMap PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var CountSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(CountSubscriber, _super); + + function CountSubscriber(destination, predicate, source) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.source = source; + _this.count = 0; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DebounceSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DebounceSubscriber, _super); + + function DebounceSubscriber(destination, durationSelector) { + var _this = _super.call(this, destination) || this; + + _this.durationSelector = durationSelector; + _this.hasValue = false; + _this.durationSubscription = null; + return _this; + } + + 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 && !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 must be done *before* passing the value + // along to the destination because it's possible for + // the value to synchronously re-enter this operator + // recursively if the duration selector Observable + // emits synchronously + + + this.value = null; + this.hasValue = false; + + _super.prototype._next.call(this, value); + } + }; + + return DebounceSubscriber; + }(OuterSubscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._scheduler_async PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DebounceTimeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DebounceTimeSubscriber, _super); + + function DebounceTimeSubscriber(destination, dueTime, scheduler) { + var _this = _super.call(this, destination) || this; + + _this.dueTime = dueTime; + _this.scheduler = scheduler; + _this.debouncedSubscription = null; + _this.lastValue = null; + _this.hasValue = false; + return _this; + } + + DebounceTimeSubscriber.prototype._next = function (value) { + this.clearDebounce(); + this.lastValue = value; + this.hasValue = true; + this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this)); + }; + + DebounceTimeSubscriber.prototype._complete = function () { + this.debouncedNext(); + this.destination.complete(); + }; + + DebounceTimeSubscriber.prototype.debouncedNext = function () { + this.clearDebounce(); + + if (this.hasValue) { + var lastValue = this.lastValue; // This must be done *before* passing the value + // along to the destination because it's possible for + // the value to synchronously re-enter this operator + // recursively when scheduled with things like + // VirtualScheduler/TestScheduler. + + this.lastValue = null; + this.hasValue = false; + this.destination.next(lastValue); + } + }; + + DebounceTimeSubscriber.prototype.clearDebounce = function () { + var debouncedSubscription = this.debouncedSubscription; + + if (debouncedSubscription !== null) { + this.remove(debouncedSubscription); + debouncedSubscription.unsubscribe(); + this.debouncedSubscription = null; + } + }; + + return DebounceTimeSubscriber; + }(Subscriber); + + function dispatchNext(subscriber) { + subscriber.debouncedNext(); + } + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DefaultIfEmptySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DefaultIfEmptySubscriber, _super); + + function DefaultIfEmptySubscriber(destination, defaultValue) { + var _this = _super.call(this, destination) || this; + + _this.defaultValue = defaultValue; + _this.isEmpty = true; + return _this; + } + + 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); + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._Observable PURE_IMPORTS_END */ + /** + * The same Observable instance returned by any call to {@link empty} without a + * {@link Scheduler}. It is preferrable to use this over `empty()`. + */ + + var EMPTY = + /*@__PURE__*/ + new Observable(function (subscriber) { + return subscriber.complete(); + }); + /** + * Creates an Observable that emits no items to the Observer and immediately + * emits a complete notification. + * + * Just emits 'complete', and nothing else. + * + * + * + * + * 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 Emit the number 7, then complete. + * var result = Rx.Observable.empty().startWith(7); + * result.subscribe(x => console.log(x)); + * + * @example Map and flatten only odd numbers to the sequence 'a', 'b', 'c' + * 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 + */ + + function empty$2(scheduler) { + return scheduler ? emptyScheduled(scheduler) : EMPTY; + } + function emptyScheduled(scheduler) { + return new Observable(function (subscriber) { + return scheduler.schedule(function () { + return subscriber.complete(); + }); + }); + } + + /** PURE_IMPORTS_START .._Observable PURE_IMPORTS_END */ + function scalar(value) { + var result = new Observable(function (subscriber) { + subscriber.next(value); + subscriber.complete(); + }); + result._isScalar = true; + result.value = value; + return result; + } + + /** PURE_IMPORTS_START .._util_isScheduler,._fromArray,._empty,._scalar PURE_IMPORTS_END */ + function of() { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + var scheduler = args[args.length - 1]; + + if (isScheduler(scheduler)) { + args.pop(); + } else { + scheduler = undefined; + } + + switch (args.length) { + case 0: + return empty$2(scheduler); + + case 1: + return scheduler ? fromArray(args, scheduler) : scalar(args[0]); + + default: + return fromArray(args, scheduler); + } + } + + /** PURE_IMPORTS_START .._Observable PURE_IMPORTS_END */ + /** + * Creates an Observable that emits no items to the Observer and immediately + * emits an error notification. + * + * Just emits 'error', and nothing else. + * + * + * + * + * 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 Emit the number 7, then emit an error. + * import { throwError, concat, of } from 'rxjs/create'; + * + * const result = concat(of(7), throwError(new Error('oops!'))); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @example Map and flatten numbers to the sequence 'a', 'b', 'c', but throw an error for 13 + * import { throwError, interval, of } from 'rxjs/create'; + * import { mergeMap } from 'rxjs/operators'; + * + * interval(1000).pipe( + * mergeMap(x => x === 13 ? + * throwError('Thirteens are bad') : + * of('a', 'b', 'c') + * ) + * ).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 + */ + + function throwError(error, scheduler) { + if (!scheduler) { + return new Observable(function (subscriber) { + return subscriber.error(error); + }); + } else { + return new Observable(function (subscriber) { + return scheduler.schedule(dispatch$1, 0, { + error: error, + subscriber: subscriber + }); + }); + } + } + + function dispatch$1(_a) { + var error = _a.error, + subscriber = _a.subscriber; + subscriber.error(error); + } + + /** PURE_IMPORTS_START ._observable_empty,._observable_of,._observable_throwError PURE_IMPORTS_END */ + /** + * 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 + */ + + var Notification = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 of(this.value); + + case 'E': + return throwError(this.error); + + case 'C': + return empty$2(); + } + + 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} 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} 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} The valueless "complete" Notification. + */ + + + Notification.createComplete = function () { + return Notification.completeNotification; + }; + + Notification.completeNotification = new Notification('C'); + Notification.undefinedValueNotification = new Notification('N', undefined); + return Notification; + }(); + + /** PURE_IMPORTS_START tslib,.._scheduler_async,.._util_isDate,.._Subscriber,.._Notification PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DelaySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DelaySubscriber, _super); + + function DelaySubscriber(destination, delay, scheduler) { + var _this = _super.call(this, destination) || this; + + _this.delay = delay; + _this.scheduler = scheduler; + _this.queue = []; + _this.active = false; + _this.errored = false; + return _this; + } + + 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 { + 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function DelayMessage(time, notification) { + this.time = time; + this.notification = notification; + } + + return DelayMessage; + }(); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._Observable,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DelayWhenSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DelayWhenSubscriber, _super); + + function DelayWhenSubscriber(destination, delayDurationSelector) { + var _this = _super.call(this, destination) || this; + + _this.delayDurationSelector = delayDurationSelector; + _this.completed = false; + _this.delayNotifierSubscriptions = []; + _this.values = []; + return _this; + } + + 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 = + /*@__PURE__*/ + function (_super) { + __extends(SubscriptionDelayObservable, _super); + + function SubscriptionDelayObservable(source, subscriptionDelay) { + var _this = _super.call(this) || this; + + _this.source = source; + _this.subscriptionDelay = subscriptionDelay; + return _this; + } + + 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 = + /*@__PURE__*/ + function (_super) { + __extends(SubscriptionDelaySubscriber, _super); + + function SubscriptionDelaySubscriber(parent, source) { + var _this = _super.call(this) || this; + + _this.parent = parent; + _this.source = source; + _this.sourceSubscribed = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DeMaterializeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DeMaterializeSubscriber, _super); + + function DeMaterializeSubscriber(destination) { + return _super.call(this, destination) || this; + } + + DeMaterializeSubscriber.prototype._next = function (value) { + value.observe(this.destination); + }; + + return DeMaterializeSubscriber; + }(Subscriber); + + var _validateCollection = function (it, TYPE) { + if (!_isObject(it) || it._t !== TYPE) throw TypeError('Incompatible receiver, ' + TYPE + ' required!'); + return it; + }; + + var dP$2 = _objectDp.f; + + + + + + + + + + var fastKey = _meta.fastKey; + + var SIZE = _descriptors ? '_s' : 'size'; + + var getEntry = function (that, key) { + // fast case + var index = fastKey(key); + var entry; + if (index !== 'F') return that._i[index]; + // frozen object case + for (entry = that._f; entry; entry = entry.n) { + if (entry.k == key) return entry; + } + }; + + var _collectionStrong = { + getConstructor: function (wrapper, NAME, IS_MAP, ADDER) { + var C = wrapper(function (that, iterable) { + _anInstance(that, C, NAME, '_i'); + that._t = NAME; // collection type + that._i = _objectCreate(null); // index + that._f = undefined; // first entry + that._l = undefined; // last entry + that[SIZE] = 0; // size + if (iterable != undefined) _forOf(iterable, IS_MAP, that[ADDER], that); + }); + _redefineAll(C.prototype, { + // 23.1.3.1 Map.prototype.clear() + // 23.2.3.2 Set.prototype.clear() + clear: function clear() { + for (var that = _validateCollection(this, NAME), data = that._i, entry = that._f; entry; entry = entry.n) { + entry.r = true; + if (entry.p) entry.p = entry.p.n = undefined; + delete data[entry.i]; + } + that._f = that._l = undefined; + that[SIZE] = 0; + }, + // 23.1.3.3 Map.prototype.delete(key) + // 23.2.3.4 Set.prototype.delete(value) + 'delete': function (key) { + var that = _validateCollection(this, NAME); + var entry = getEntry(that, key); + if (entry) { + var next = entry.n; + var prev = entry.p; + delete that._i[entry.i]; + entry.r = true; + if (prev) prev.n = next; + if (next) next.p = prev; + if (that._f == entry) that._f = next; + if (that._l == entry) that._l = prev; + that[SIZE]--; + } return !!entry; + }, + // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined) + // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined) + forEach: function forEach(callbackfn /* , that = undefined */) { + _validateCollection(this, NAME); + var f = _ctx(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3); + var entry; + while (entry = entry ? entry.n : this._f) { + f(entry.v, entry.k, this); + // revert to the last existing entry + while (entry && entry.r) entry = entry.p; + } + }, + // 23.1.3.7 Map.prototype.has(key) + // 23.2.3.7 Set.prototype.has(value) + has: function has(key) { + return !!getEntry(_validateCollection(this, NAME), key); + } + }); + if (_descriptors) dP$2(C.prototype, 'size', { + get: function () { + return _validateCollection(this, NAME)[SIZE]; + } + }); + return C; + }, + def: function (that, key, value) { + var entry = getEntry(that, key); + var prev, index; + // change existing entry + if (entry) { + entry.v = value; + // create new entry + } else { + that._l = entry = { + i: index = fastKey(key, true), // <- index + k: key, // <- key + v: value, // <- value + p: prev = that._l, // <- previous entry + n: undefined, // <- next entry + r: false // <- removed + }; + if (!that._f) that._f = entry; + if (prev) prev.n = entry; + that[SIZE]++; + // add to index + if (index !== 'F') that._i[index] = entry; + } return that; + }, + getEntry: getEntry, + setStrong: function (C, NAME, IS_MAP) { + // add .keys, .values, .entries, [@@iterator] + // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11 + _iterDefine(C, NAME, function (iterated, kind) { + this._t = _validateCollection(iterated, NAME); // target + this._k = kind; // kind + this._l = undefined; // previous + }, function () { + var that = this; + var kind = that._k; + var entry = that._l; + // revert to the last existing entry + while (entry && entry.r) entry = entry.p; + // get next entry + if (!that._t || !(that._l = entry = entry ? entry.n : that._t._f)) { + // or finish the iteration + that._t = undefined; + return _iterStep(1); + } + // return step by kind + if (kind == 'keys') return _iterStep(0, entry.k); + if (kind == 'values') return _iterStep(0, entry.v); + return _iterStep(0, [entry.k, entry.v]); + }, IS_MAP ? 'entries' : 'values', !IS_MAP, true); + + // add [@@species], 23.1.2.2, 23.2.2.2 + _setSpecies(NAME); + } + }; + + // Works with __proto__ only. Old v8 can't work with null proto objects. + /* eslint-disable no-proto */ + + + var check = function (O, proto) { + _anObject(O); + if (!_isObject(proto) && proto !== null) throw TypeError(proto + ": can't set as prototype!"); + }; + var _setProto = { + set: Object.setPrototypeOf || ('__proto__' in {} ? // eslint-disable-line + function (test, buggy, set) { + try { + set = _ctx(Function.call, _objectGopd.f(Object.prototype, '__proto__').set, 2); + set(test, []); + buggy = !(test instanceof Array); + } catch (e) { buggy = true; } + return function setPrototypeOf(O, proto) { + check(O, proto); + if (buggy) O.__proto__ = proto; + else set(O, proto); + return O; + }; + }({}, false) : undefined), + check: check + }; + + var setPrototypeOf = _setProto.set; + var _inheritIfRequired = function (that, target, C) { + var S = target.constructor; + var P; + if (S !== C && typeof S == 'function' && (P = S.prototype) !== C.prototype && _isObject(P) && setPrototypeOf) { + setPrototypeOf(that, P); + } return that; + }; + + var _collection = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) { + var Base = _global[NAME]; + var C = Base; + var ADDER = IS_MAP ? 'set' : 'add'; + var proto = C && C.prototype; + var O = {}; + var fixMethod = function (KEY) { + var fn = proto[KEY]; + _redefine(proto, KEY, + KEY == 'delete' ? function (a) { + return IS_WEAK && !_isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'has' ? function has(a) { + return IS_WEAK && !_isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'get' ? function get(a) { + return IS_WEAK && !_isObject(a) ? undefined : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'add' ? function add(a) { fn.call(this, a === 0 ? 0 : a); return this; } + : function set(a, b) { fn.call(this, a === 0 ? 0 : a, b); return this; } + ); + }; + if (typeof C != 'function' || !(IS_WEAK || proto.forEach && !_fails(function () { + new C().entries().next(); + }))) { + // create collection constructor + C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER); + _redefineAll(C.prototype, methods); + _meta.NEED = true; + } else { + var instance = new C(); + // early implementations not supports chaining + var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance; + // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false + var THROWS_ON_PRIMITIVES = _fails(function () { instance.has(1); }); + // most early implementations doesn't supports iterables, most modern - not close it correctly + var ACCEPT_ITERABLES = _iterDetect(function (iter) { new C(iter); }); // eslint-disable-line no-new + // for early implementations -0 and +0 not the same + var BUGGY_ZERO = !IS_WEAK && _fails(function () { + // V8 ~ Chromium 42- fails only with 5+ elements + var $instance = new C(); + var index = 5; + while (index--) $instance[ADDER](index, index); + return !$instance.has(-0); + }); + if (!ACCEPT_ITERABLES) { + C = wrapper(function (target, iterable) { + _anInstance(target, C, NAME); + var that = _inheritIfRequired(new Base(), target, C); + if (iterable != undefined) _forOf(iterable, IS_MAP, that[ADDER], that); + return that; + }); + C.prototype = proto; + proto.constructor = C; + } + if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) { + fixMethod('delete'); + fixMethod('has'); + IS_MAP && fixMethod('get'); + } + if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER); + // weak collections should not contains .clear method + if (IS_WEAK && proto.clear) delete proto.clear; + } + + _setToStringTag(C, NAME); + + O[NAME] = C; + _export(_export.G + _export.W + _export.F * (C != Base), O); + + if (!IS_WEAK) common.setStrong(C, NAME, IS_MAP); + + return C; + }; + + var SET = 'Set'; + + // 23.2 Set Objects + var es6_set = _collection(SET, function (get) { + return function Set() { return get(this, arguments.length > 0 ? arguments[0] : undefined); }; + }, { + // 23.2.3.1 Set.prototype.add(value) + add: function add(value) { + return _collectionStrong.def(_validateCollection(this, SET), value = value === 0 ? 0 : value, value); + } + }, _collectionStrong); + + if (!Set) { + throw ( + /*@__PURE__*/ + new Error('Set is not present, please polyfill') + ); + } + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var DistinctSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(DistinctSubscriber, _super); + + function DistinctSubscriber(destination, keySelector, flushes) { + var _this = _super.call(this, destination) || this; + + _this.keySelector = keySelector; + _this.values = new Set(); + + if (flushes) { + _this.add(subscribeToResult(_this, flushes)); + } + + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_tryCatch,.._util_errorObject PURE_IMPORTS_END */ + /* 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 A simple example with numbers + * 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 An example using a compare function + * interface Person { + * age: number, + * name: string + * } + * + * Observable.of( + * { 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(compare, keySelector) { + return function (source) { + return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); + }; + } + + var DistinctUntilChangedOperator = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(DistinctUntilChangedSubscriber, _super); + + function DistinctUntilChangedSubscriber(destination, compare, keySelector) { + var _this = _super.call(this, destination) || this; + + _this.keySelector = keySelector; + _this.hasKey = false; + + if (typeof compare === 'function') { + _this.compare = compare; + } + + return _this; + } + + 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); + + /** PURE_IMPORTS_START ._distinctUntilChanged PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib PURE_IMPORTS_END */ + /** + * 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 = + /*@__PURE__*/ + function (_super) { + __extends(ArgumentOutOfRangeError, _super); + + function ArgumentOutOfRangeError() { + var _this = _super.call(this, 'argument out of range') || this; + + _this.name = 'ArgumentOutOfRangeError'; + Object.setPrototypeOf(_this, ArgumentOutOfRangeError.prototype); + return _this; + } + + return ArgumentOutOfRangeError; + }(Error); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_ArgumentOutOfRangeError PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var ElementAtSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ElementAtSubscriber, _super); + + function ElementAtSubscriber(destination, index, defaultValue) { + var _this = _super.call(this, destination) || this; + + _this.index = index; + _this.defaultValue = defaultValue; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var EverySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(EverySubscriber, _super); + + function EverySubscriber(destination, predicate, thisArg, source) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.thisArg = thisArg; + _this.source = source; + _this.index = 0; + _this.thisArg = thisArg || _this; + return _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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SwitchFirstSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SwitchFirstSubscriber, _super); + + function SwitchFirstSubscriber(destination) { + var _this = _super.call(this, destination) || this; + + _this.hasCompleted = false; + _this.hasSubscription = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SwitchFirstMapSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SwitchFirstMapSubscriber, _super); + + function SwitchFirstMapSubscriber(destination, project) { + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.hasSubscription = false; + _this.hasCompleted = false; + _this.index = 0; + return _this; + } + + 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) { + this.destination.next(innerValue); + }; + + 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); + + /** PURE_IMPORTS_START tslib,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var ExpandSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ExpandSubscriber, _super); + + function ExpandSubscriber(destination, project, concurrent, scheduler) { + var _this = _super.call(this, destination) || this; + + _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 = []; + } + + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /* tslint:enable:max-line-length */ + + /** + * Filter items emitted by the source Observable by only emitting those that + * satisfy a specified predicate. + * + * 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. + * + * + * + * 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 Emit only click events whose target was a DIV element + * 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(predicate, thisArg) { + return function filterOperatorFunction(source) { + return source.lift(new FilterOperator(predicate, thisArg)); + }; + } + + var FilterOperator = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(FilterSubscriber, _super); + + function FilterSubscriber(destination, predicate, thisArg) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.thisArg = thisArg; + _this.count = 0; + return _this; + } // 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._Subscription PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var FinallySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(FinallySubscriber, _super); + + function FinallySubscriber(destination, callback) { + var _this = _super.call(this, destination) || this; + + _this.add(new Subscription(callback)); + + return _this; + } + + return FinallySubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var FindValueSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(FindValueSubscriber, _super); + + function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.source = source; + _this.yieldIndex = yieldIndex; + _this.thisArg = thisArg; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._operators_find PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib PURE_IMPORTS_END */ + /** + * 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 = + /*@__PURE__*/ + function (_super) { + __extends(EmptyError, _super); + + function EmptyError() { + var _this = _super.call(this, 'no elements in sequence') || this; + + _this.name = 'EmptyError'; + Object.setPrototypeOf(_this, EmptyError.prototype); + return _this; + } + + return EmptyError; + }(Error); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_EmptyError PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var FirstSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(FirstSubscriber, _super); + + function FirstSubscriber(destination, predicate, defaultValue, source) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.defaultValue = defaultValue; + _this.source = source; + _this.index = 0; + _this.hasCompleted = false; + _this._emitted = false; + return _this; + } + + FirstSubscriber.prototype._next = function (value) { + var index = this.index++; + + if (this.predicate) { + this._tryPredicate(value, index); + } else { + this._emit(value); + } + }; + + 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); + } + }; + + FirstSubscriber.prototype._emit = 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); + + var MAP = 'Map'; + + // 23.1 Map Objects + var es6_map = _collection(MAP, function (get) { + return function Map() { return get(this, arguments.length > 0 ? arguments[0] : undefined); }; + }, { + // 23.1.3.6 Map.prototype.get(key) + get: function get(key) { + var entry = _collectionStrong.getEntry(_validateCollection(this, MAP), key); + return entry && entry.v; + }, + // 23.1.3.9 Map.prototype.set(key, value) + set: function set(key, value) { + return _collectionStrong.def(_validateCollection(this, MAP), key === 0 ? 0 : key, value); + } + }, _collectionStrong, true); + + /** PURE_IMPORTS_START tslib PURE_IMPORTS_END */ + /** + * An error thrown when an action is invalid because the object has been + * unsubscribed. + * + * @see {@link Subject} + * @see {@link BehaviorSubject} + * + * @class ObjectUnsubscribedError + */ + + var ObjectUnsubscribedError = + /*@__PURE__*/ + function (_super) { + __extends(ObjectUnsubscribedError, _super); + + function ObjectUnsubscribedError() { + var _this = _super.call(this, 'object unsubscribed') || this; + + _this.name = 'ObjectUnsubscribedError'; + Object.setPrototypeOf(_this, ObjectUnsubscribedError.prototype); + return _this; + } + + return ObjectUnsubscribedError; + }(Error); + + /** PURE_IMPORTS_START tslib,._Subscription PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var SubjectSubscription = + /*@__PURE__*/ + function (_super) { + __extends(SubjectSubscription, _super); + + function SubjectSubscription(subject, subscriber) { + var _this = _super.call(this) || this; + + _this.subject = subject; + _this.subscriber = subscriber; + _this.closed = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,._Observable,._Subscriber,._Subscription,._util_ObjectUnsubscribedError,._SubjectSubscription,.._internal_symbol_rxSubscriber PURE_IMPORTS_END */ + /** + * @class SubjectSubscriber + */ + + var SubjectSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SubjectSubscriber, _super); + + function SubjectSubscriber(destination) { + var _this = _super.call(this, destination) || this; + + _this.destination = destination; + return _this; + } + + return SubjectSubscriber; + }(Subscriber); + /** + * @class Subject + */ + + var Subject = + /*@__PURE__*/ + function (_super) { + __extends(Subject, _super); + + function Subject() { + var _this = _super.call(this) || this; + + _this.observers = []; + _this.closed = false; + _this.isStopped = false; + _this.hasError = false; + _this.thrownError = null; + return _this; + } + + 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); + } + }; + + 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 + */ + + var AnonymousSubject = + /*@__PURE__*/ + function (_super) { + __extends(AnonymousSubject, _super); + + function AnonymousSubject(destination, source) { + var _this = _super.call(this) || this; + + _this.destination = destination; + _this.source = source; + return _this; + } + + 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(); + } + }; + + AnonymousSubject.prototype._subscribe = function (subscriber) { + var source = this.source; + + if (source) { + return this.source.subscribe(subscriber); + } else { + return Subscription.EMPTY; + } + }; + + return AnonymousSubject; + }(Subject); + + /** Assert that map is present for this operator */ + + if (!Map) { + throw ( + /*@__PURE__*/ + new Error('Map not found, please polyfill') + ); + } + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var GroupBySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(GroupBySubscriber, _super); + + function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector, subjectSelector) { + var _this = _super.call(this, destination) || this; + + _this.keySelector = keySelector; + _this.elementSelector = elementSelector; + _this.durationSelector = durationSelector; + _this.subjectSelector = subjectSelector; + _this.groups = null; + _this.attemptedToUnsubscribe = false; + _this.count = 0; + return _this; + } + + 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 = 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 = + /*@__PURE__*/ + function (_super) { + __extends(GroupDurationSubscriber, _super); + + function GroupDurationSubscriber(key, group, parent) { + var _this = _super.call(this, group) || this; + + _this.key = key; + _this.group = group; + _this.parent = parent; + return _this; + } + + GroupDurationSubscriber.prototype._next = function (value) { + this.complete(); + }; + + 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 + */ + + + var GroupedObservable = + /*@__PURE__*/ + function (_super) { + __extends(GroupedObservable, _super); + + function GroupedObservable(key, groupSubject, refCountSubscription) { + var _this = _super.call(this) || this; + + _this.key = key; + _this.groupSubject = groupSubject; + _this.refCountSubscription = refCountSubscription; + return _this; + } + + 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 = + /*@__PURE__*/ + function (_super) { + __extends(InnerRefCountSubscription, _super); + + function InnerRefCountSubscription(parent) { + var _this = _super.call(this) || this; + + _this.parent = parent; + parent.count++; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var IgnoreElementsSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(IgnoreElementsSubscriber, _super); + + function IgnoreElementsSubscriber() { + return _super !== null && _super.apply(this, arguments) || this; + } + + IgnoreElementsSubscriber.prototype._next = function (unused) {// Do nothing + }; + + return IgnoreElementsSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var IsEmptySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(IsEmptySubscriber, _super); + + function IsEmptySubscriber(destination) { + return _super.call(this, destination) || this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_EmptyError PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var LastSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(LastSubscriber, _super); + + function LastSubscriber(destination, predicate, defaultValue, source) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.defaultValue = defaultValue; + _this.source = source; + _this.hasValue = false; + _this.index = 0; + + if (typeof defaultValue !== 'undefined') { + _this.lastValue = defaultValue; + _this.hasValue = true; + } + + return _this; + } + + LastSubscriber.prototype._next = function (value) { + var index = this.index++; + + if (this.predicate) { + this._tryPredicate(value, index); + } else { + 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) { + this.lastValue = value; + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * Applies a given `project` function to each value emitted by the source + * Observable, and emits the resulting values as an Observable. + * + * 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. + * + * + * + * 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 Map every click to the clientX position of that click + * 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} 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(MapSubscriber, _super); + + function MapSubscriber(destination, project, thisArg) { + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.count = 0; + _this.thisArg = thisArg || _this; + return _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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var MapToSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(MapToSubscriber, _super); + + function MapToSubscriber(destination, value) { + var _this = _super.call(this, destination) || this; + + _this.value = value; + return _this; + } + + MapToSubscriber.prototype._next = function (x) { + this.destination.next(this.value); + }; + + return MapToSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._Notification PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var MaterializeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(MaterializeSubscriber, _super); + + function MaterializeSubscriber(destination) { + return _super.call(this, destination) || this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var ScanSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ScanSubscriber, _super); + + function ScanSubscriber(destination, accumulator, _seed, hasSeed) { + var _this = _super.call(this, destination) || this; + + _this.accumulator = accumulator; + _this._seed = _seed; + _this.hasSeed = hasSeed; + _this.index = 0; + return _this; + } + + Object.defineProperty(ScanSubscriber.prototype, "seed", { + get: function get() { + return this._seed; + }, + set: function set(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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_ArgumentOutOfRangeError,.._observable_empty PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TakeLastSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TakeLastSubscriber, _super); + + function TakeLastSubscriber(destination, total) { + var _this = _super.call(this, destination) || this; + + _this.total = total; + _this.ring = new Array(); + _this.count = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START ._scan,._takeLast,._defaultIfEmpty,.._util_pipe PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START ._reduce PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START ._mergeMap PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._util_tryCatch,.._util_errorObject,.._util_subscribeToResult,.._OuterSubscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var MergeScanSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(MergeScanSubscriber, _super); + + function MergeScanSubscriber(destination, accumulator, acc, concurrent) { + var _this = _super.call(this, destination) || this; + + _this.accumulator = accumulator; + _this.acc = acc; + _this.concurrent = concurrent; + _this.hasValue = false; + _this.hasCompleted = false; + _this.buffer = []; + _this.active = 0; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START ._reduce PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + function refCount() { + return function refCountOperatorFunction(source) { + return source.lift(new RefCountOperator(source)); + }; + } + + var RefCountOperator = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function RefCountOperator(connectable) { + this.connectable = connectable; + } + + RefCountOperator.prototype.call = function (subscriber, source) { + var connectable = this.connectable; + connectable._refCount++; + var refCounter = new RefCountSubscriber(subscriber, connectable); + var subscription = source.subscribe(refCounter); + + if (!refCounter.closed) { + refCounter.connection = connectable.connect(); + } + + return subscription; + }; + + return RefCountOperator; + }(); + + var RefCountSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(RefCountSubscriber, _super); + + function RefCountSubscriber(destination, connectable) { + var _this = _super.call(this, destination) || this; + + _this.connectable = connectable; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subject,.._Observable,.._Subscriber,.._Subscription,.._.._internal_operators_refCount PURE_IMPORTS_END */ + /** + * @class ConnectableObservable + */ + + var ConnectableObservable = + /*@__PURE__*/ + function (_super) { + __extends(ConnectableObservable, _super); + + function ConnectableObservable(source, subjectFactory) { + var _this = _super.call(this) || this; + + _this.source = source; + _this.subjectFactory = subjectFactory; + _this._refCount = 0; + /** @internal */ + + _this._isComplete = false; + return _this; + } + + ConnectableObservable.prototype._subscribe = function (subscriber) { + return this.getSubject().subscribe(subscriber); + }; + + 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 ConnectableSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ConnectableSubscriber, _super); + + function ConnectableSubscriber(destination, connectable) { + var _this = _super.call(this, destination) || this; + + _this.connectable = connectable; + return _this; + } + + 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); + }; + + 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$1 = + /*@__PURE__*/ + function (_super) { + __extends(RefCountSubscriber, _super); + + function RefCountSubscriber(destination, connectable) { + var _this = _super.call(this, destination) || this; + + _this.connectable = connectable; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._observable_ConnectableObservable PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._Notification PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var ObserveOnSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ObserveOnSubscriber, _super); + + function ObserveOnSubscriber(destination, scheduler, delay) { + if (delay === void 0) { + delay = 0; + } + + var _this = _super.call(this, destination) || this; + + _this.scheduler = scheduler; + _this.delay = delay; + return _this; + } + + 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function ObserveOnMessage(notification, destination) { + this.notification = notification; + this.destination = destination; + } + + return ObserveOnMessage; + }(); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var PairwiseSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(PairwiseSubscriber, _super); + + function PairwiseSubscriber(destination) { + var _this = _super.call(this, destination) || this; + + _this.hasPrev = false; + return _this; + } + + PairwiseSubscriber.prototype._next = function (value) { + if (this.hasPrev) { + this.destination.next([this.prev, value]); + } else { + this.hasPrev = true; + } + + this.prev = value; + }; + + return PairwiseSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._util_not,._filter PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START ._map PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._Subject,._multicast PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,._Subject,._util_ObjectUnsubscribedError PURE_IMPORTS_END */ + /** + * @class BehaviorSubject + */ + + var BehaviorSubject = + /*@__PURE__*/ + function (_super) { + __extends(BehaviorSubject, _super); + + function BehaviorSubject(_value) { + var _this = _super.call(this) || this; + + _this._value = _value; + return _this; + } + + Object.defineProperty(BehaviorSubject.prototype, "value", { + get: function get() { + return this.getValue(); + }, + enumerable: true, + configurable: true + }); + + 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); + + /** PURE_IMPORTS_START .._BehaviorSubject,._multicast PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,._Subject,._Subscription PURE_IMPORTS_END */ + /** + * @class AsyncSubject + */ + + var AsyncSubject = + /*@__PURE__*/ + function (_super) { + __extends(AsyncSubject, _super); + + function AsyncSubject() { + var _this = _super !== null && _super.apply(this, arguments) || this; + + _this.value = null; + _this.hasNext = false; + _this.hasCompleted = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._AsyncSubject,._multicast PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,._AsyncAction PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var QueueAction = + /*@__PURE__*/ + function (_super) { + __extends(QueueAction, _super); + + function QueueAction(scheduler, work) { + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,._AsyncScheduler PURE_IMPORTS_END */ + + var QueueScheduler = + /*@__PURE__*/ + function (_super) { + __extends(QueueScheduler, _super); + + function QueueScheduler() { + return _super !== null && _super.apply(this, arguments) || this; + } + + return QueueScheduler; + }(AsyncScheduler); + + /** PURE_IMPORTS_START ._QueueAction,._QueueScheduler PURE_IMPORTS_END */ + /** + * + * Queue Scheduler + * + * Put every next task on a queue, instead of executing it immediately + * + * `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 Schedule recursively first, then do something + * + * 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 Reschedule itself recursively + * + * 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$1 = + /*@__PURE__*/ + new QueueScheduler(QueueAction); + + /** PURE_IMPORTS_START tslib,._Subject,._scheduler_queue,._Subscription,._operators_observeOn,._util_ObjectUnsubscribedError,._SubjectSubscription PURE_IMPORTS_END */ + /** + * @class ReplaySubject + */ + + var ReplaySubject = + /*@__PURE__*/ + 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; + } + + var _this = _super.call(this) || this; + + _this.scheduler = scheduler; + _this._events = []; + _this._bufferSize = bufferSize < 1 ? 1 : bufferSize; + _this._windowTime = windowTime < 1 ? 1 : windowTime; + return _this; + } + + ReplaySubject.prototype.next = function (value) { + var now = this._getNow(); + + this._events.push(new ReplayEvent(now, value)); + + this._trimBufferThenGetEvents(); + + _super.prototype.next.call(this, value); + }; + + 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$1).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 = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function ReplayEvent(time, value) { + this.time = time; + this.value = value; + } + + return ReplayEvent; + }(); + + /** PURE_IMPORTS_START .._ReplaySubject,._multicast PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._observable_empty PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var RepeatSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(RepeatSubscriber, _super); + + function RepeatSubscriber(destination, count, source) { + var _this = _super.call(this, destination) || this; + + _this.count = count; + _this.source = source; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subject,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var RepeatWhenSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(RepeatWhenSubscriber, _super); + + function RepeatWhenSubscriber(destination, notifier, source) { + var _this = _super.call(this, destination) || this; + + _this.notifier = notifier; + _this.source = source; + _this.sourceIsBeingSubscribedTo = true; + return _this; + } + + 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(); + } else if (this.retriesSubscription.closed) { + return _super.prototype.complete.call(this); + } + + this._unsubscribeAndRecycle(); + + this.notifications.next(); + } + }; + + 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; + }; + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var RetrySubscriber = + /*@__PURE__*/ + function (_super) { + __extends(RetrySubscriber, _super); + + function RetrySubscriber(destination, count, source) { + var _this = _super.call(this, destination) || this; + + _this.count = count; + _this.source = source; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subject,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var RetryWhenSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(RetryWhenSubscriber, _super); + + function RetryWhenSubscriber(destination, notifier, source) { + var _this = _super.call(this, destination) || this; + + _this.notifier = notifier; + _this.source = source; + return _this; + } + + 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); + } + }; + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SampleSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SampleSubscriber, _super); + + function SampleSubscriber() { + var _this = _super !== null && _super.apply(this, arguments) || this; + + _this.hasValue = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._scheduler_async PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SampleTimeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SampleTimeSubscriber, _super); + + function SampleTimeSubscriber(destination, period, scheduler) { + var _this = _super.call(this, destination) || this; + + _this.period = period; + _this.scheduler = scheduler; + _this.hasValue = false; + + _this.add(scheduler.schedule(dispatchNotification, period, { + subscriber: _this, + period: period + })); + + return _this; + } + + 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); + } + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_tryCatch,.._util_errorObject PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var SequenceEqualSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SequenceEqualSubscriber, _super); + + function SequenceEqualSubscriber(destination, compareTo, comparor) { + var _this = _super.call(this, destination) || this; + + _this.compareTo = compareTo; + _this.comparor = comparor; + _this._a = []; + _this._b = []; + _this._oneComplete = false; + + _this.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, _this))); + + return _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 = + /*@__PURE__*/ + function (_super) { + __extends(SequenceEqualCompareToSubscriber, _super); + + function SequenceEqualCompareToSubscriber(destination, parent) { + var _this = _super.call(this, destination) || this; + + _this.parent = parent; + return _this; + } + + 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); + + /** PURE_IMPORTS_START ._multicast,._refCount,.._Subject PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._ReplaySubject PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_EmptyError PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SingleSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SingleSubscriber, _super); + + function SingleSubscriber(destination, predicate, source) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.source = source; + _this.seenValue = false; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SkipSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SkipSubscriber, _super); + + function SkipSubscriber(destination, total) { + var _this = _super.call(this, destination) || this; + + _this.total = total; + _this.count = 0; + return _this; + } + + SkipSubscriber.prototype._next = function (x) { + if (++this.count > this.total) { + this.destination.next(x); + } + }; + + return SkipSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_ArgumentOutOfRangeError PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SkipLastSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SkipLastSubscriber, _super); + + function SkipLastSubscriber(destination, _skipCount) { + var _this = _super.call(this, destination) || this; + + _this._skipCount = _skipCount; + _this._count = 0; + _this._ring = new Array(_skipCount); + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SkipUntilSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SkipUntilSubscriber, _super); + + function SkipUntilSubscriber(destination, notifier) { + var _this = _super.call(this, destination) || this; + + _this.hasValue = false; + _this.isInnerStopped = false; + + _this.add(subscribeToResult(_this, notifier)); + + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SkipWhileSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SkipWhileSubscriber, _super); + + function SkipWhileSubscriber(destination, predicate) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.skipping = true; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._symbol_observable PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._symbol_iterator PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._Observable,.._Subscription,.._util_subscribeToPromise PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._Observable,.._Subscription,.._symbol_iterator,.._util_subscribeToIterable PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._Observable,.._Subscription,.._symbol_observable,.._util_subscribeToObservable PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._Observable,.._util_isPromise,.._util_isArrayLike,.._util_isObservable,.._util_isIterable,._fromArray,._fromPromise,._fromIterable,._fromObservable,.._util_subscribeTo PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._util_isScheduler,._of,._from,.._.._internal_operators_concatAll PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START .._observable_fromArray,.._observable_scalar,.._observable_empty,.._observable_concat,.._util_isScheduler PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SwitchMapSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SwitchMapSubscriber, _super); + + function SwitchMapSubscriber(destination, project) { + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.index = 0; + return _this; + } + + 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); + } + }; + + 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) { + this.destination.next(innerValue); + }; + + return SwitchMapSubscriber; + }(OuterSubscriber); + + /** PURE_IMPORTS_START ._switchMap,.._util_identity PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var SwitchMapToSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(SwitchMapToSubscriber, _super); + + function SwitchMapToSubscriber(destination, inner) { + var _this = _super.call(this, destination) || this; + + _this.inner = inner; + _this.index = 0; + return _this; + } + + 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); + } + }; + + 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) { + this.destination.next(innerValue); + }; + + return SwitchMapToSubscriber; + }(OuterSubscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_ArgumentOutOfRangeError,.._observable_empty PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TakeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TakeSubscriber, _super); + + function TakeSubscriber(destination, total) { + var _this = _super.call(this, destination) || this; + + _this.total = total; + _this.count = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TakeUntilSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TakeUntilSubscriber, _super); + + function TakeUntilSubscriber(destination, notifier) { + var _this = _super.call(this, destination) || this; + + _this.notifier = notifier; + + _this.add(subscribeToResult(_this, notifier)); + + return _this; + } + + TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.complete(); + }; + + TakeUntilSubscriber.prototype.notifyComplete = function () {// noop + }; + + return TakeUntilSubscriber; + }(OuterSubscriber); + + /** PURE_IMPORTS_START tslib,.._Subscriber PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TakeWhileSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TakeWhileSubscriber, _super); + + function TakeWhileSubscriber(destination, predicate) { + var _this = _super.call(this, destination) || this; + + _this.predicate = predicate; + _this.index = 0; + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._util_noop,.._util_isFunction PURE_IMPORTS_END */ + /* 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. + * + * 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. + * + * + * + * 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 Map every click to the clientX position of that click, while also logging the click event + * 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 TapSubscriber(subscriber, this.nextOrObserver, this.error, this.complete)); + }; + + return DoOperator; + }(); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TapSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TapSubscriber, _super); + + function TapSubscriber(destination, observerOrNext, error, complete) { + var _this = _super.call(this, destination) || this; + + _this._tapNext = noop; + _this._tapError = noop; + _this._tapComplete = noop; + _this._tapError = error || noop; + _this._tapComplete = complete || noop; + + if (isFunction(observerOrNext)) { + _this._context = _this; + _this._tapNext = observerOrNext; + } else if (observerOrNext) { + _this._context = observerOrNext; + _this._tapNext = observerOrNext.next || noop; + _this._tapError = observerOrNext.error || noop; + _this._tapComplete = observerOrNext.complete || noop; + } + + return _this; + } + + TapSubscriber.prototype._next = function (value) { + try { + this._tapNext.call(this._context, value); + } catch (err) { + this.destination.error(err); + return; + } + + this.destination.next(value); + }; + + TapSubscriber.prototype._error = function (err) { + try { + this._tapError.call(this._context, err); + } catch (err) { + this.destination.error(err); + return; + } + + this.destination.error(err); + }; + + TapSubscriber.prototype._complete = function () { + try { + this._tapComplete.call(this._context); + } catch (err) { + this.destination.error(err); + return; + } + + return this.destination.complete(); + }; + + return TapSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + var defaultThrottleConfig = { + leading: true, + trailing: false + }; + /** + * We need this JSDoc comment for affecting ESDoc + * @ignore + * @extends {Ignored} + */ + + + var ThrottleSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ThrottleSubscriber, _super); + + function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) { + var _this = _super.call(this, destination) || this; + + _this.destination = destination; + _this.durationSelector = durationSelector; + _this._leading = _leading; + _this._trailing = _trailing; + _this._hasTrailingValue = false; + return _this; + } + + 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; + } + }; + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._scheduler_async,._throttle PURE_IMPORTS_END */ + /** + * Emits a value from the source Observable, then ignores subsequent source + * values for `duration` milliseconds, then repeats this process. + * + * Lets a value pass, then ignores source values for the + * next `duration` milliseconds. + * + * + * + * `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 Emit clicks at a rate of at most one click per second + * 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} An Observable that performs the throttle operation to + * limit the rate of emissions from the source. + * @method throttleTime + * @owner Observable + */ + + function throttleTime(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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(ThrottleTimeSubscriber, _super); + + function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) { + var _this = _super.call(this, destination) || this; + + _this.duration = duration; + _this.scheduler = scheduler; + _this.leading = leading; + _this.trailing = trailing; + _this._hasTrailingValue = false; + _this._trailingValue = null; + return _this; + } + + 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$1, 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$1(arg) { + var subscriber = arg.subscriber; + subscriber.clearThrottle(); + } + + /** PURE_IMPORTS_START ._tap,.._util_EmptyError PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._scheduler_async PURE_IMPORTS_END */ + + var TimeInterval = + /*@__PURE__*/ + + /*@__PURE__*/ + function () { + function TimeInterval(value, interval) { + this.value = value; + this.interval = interval; + } + + return TimeInterval; + }(); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TimeIntervalSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TimeIntervalSubscriber, _super); + + function TimeIntervalSubscriber(destination, scheduler) { + var _this = _super.call(this, destination) || this; + + _this.scheduler = scheduler; + _this.lastTime = 0; + _this.lastTime = scheduler.now(); + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib PURE_IMPORTS_END */ + /** + * An error thrown when duetime elapses. + * + * @see {@link timeout} + * + * @class TimeoutError + */ + + var TimeoutError = + /*@__PURE__*/ + function (_super) { + __extends(TimeoutError, _super); + + function TimeoutError() { + var _this = _super.call(this, 'Timeout has occurred') || this; + + Object.setPrototypeOf(_this, TimeoutError.prototype); + return _this; + } + + return TimeoutError; + }(Error); + + /** PURE_IMPORTS_START tslib,.._scheduler_async,.._util_isDate,.._Subscriber,.._util_TimeoutError PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TimeoutSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TimeoutSubscriber, _super); + + function TimeoutSubscriber(destination, absoluteTimeout, waitFor, scheduler, errorInstance) { + var _this = _super.call(this, destination) || this; + + _this.absoluteTimeout = absoluteTimeout; + _this.waitFor = waitFor; + _this.scheduler = scheduler; + _this.errorInstance = errorInstance; + _this.action = null; + + _this.scheduleTimeout(); + + return _this; + } + + 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); + }; + + TimeoutSubscriber.prototype._unsubscribe = function () { + this.action = null; + this.scheduler = null; + this.errorInstance = null; + }; + + return TimeoutSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._scheduler_async,.._util_isDate,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var TimeoutWithSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(TimeoutWithSubscriber, _super); + + function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) { + var _this = _super.call(this, destination) || this; + + _this.absoluteTimeout = absoluteTimeout; + _this.waitFor = waitFor; + _this.withObservable = withObservable; + _this.scheduler = scheduler; + _this.action = null; + + _this.scheduleTimeout(); + + return _this; + } + + 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); + }; + + TimeoutWithSubscriber.prototype._unsubscribe = function () { + this.action = null; + this.scheduler = null; + this.withObservable = null; + }; + + return TimeoutWithSubscriber; + }(OuterSubscriber); + + /** PURE_IMPORTS_START .._scheduler_async,._map PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START ._reduce PURE_IMPORTS_END */ + + /** PURE_IMPORTS_START tslib,.._Subject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var WindowSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(WindowSubscriber, _super); + + function WindowSubscriber(destination) { + var _this = _super.call(this, destination) || this; + + _this.window = new Subject(); + destination.next(_this.window); + return _this; + } + + 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(); + }; + + 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); + + /** PURE_IMPORTS_START tslib,.._Subscriber,.._Subject PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var WindowCountSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(WindowCountSubscriber, _super); + + function WindowCountSubscriber(destination, windowSize, startWindowEvery) { + var _this = _super.call(this, destination) || this; + + _this.destination = destination; + _this.windowSize = windowSize; + _this.startWindowEvery = startWindowEvery; + _this.windows = [new Subject()]; + _this.count = 0; + destination.next(_this.windows[0]); + return _this; + } + + 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(); + }; + + WindowCountSubscriber.prototype._unsubscribe = function () { + this.count = 0; + this.windows = null; + }; + + return WindowCountSubscriber; + }(Subscriber); + + /** PURE_IMPORTS_START tslib,.._Subject,.._scheduler_async,.._Subscriber,.._util_isNumeric,.._util_isScheduler PURE_IMPORTS_END */ + + var CountedSubject = + /*@__PURE__*/ + function (_super) { + __extends(CountedSubject, _super); + + function CountedSubject() { + var _this = _super !== null && _super.apply(this, arguments) || this; + + _this._numberOfNextedValues = 0; + return _this; + } + + CountedSubject.prototype.next = function (value) { + this._numberOfNextedValues++; + + _super.prototype.next.call(this, value); + }; + + Object.defineProperty(CountedSubject.prototype, "numberOfNextedValues", { + get: function get() { + return this._numberOfNextedValues; + }, + enumerable: true, + configurable: true + }); + return CountedSubject; + }(Subject); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var WindowTimeSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(WindowTimeSubscriber, _super); + + function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) { + var _this = _super.call(this, destination) || this; + + _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)); + } + + return _this; + } + + 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); + } + + /** PURE_IMPORTS_START tslib,.._Subject,.._Subscription,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var WindowToggleSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(WindowToggleSubscriber, _super); + + function WindowToggleSubscriber(destination, openings, closingSelector) { + var _this = _super.call(this, destination) || this; + + _this.openings = openings; + _this.closingSelector = closingSelector; + _this.contexts = []; + + _this.add(_this.openSubscription = subscribeToResult(_this, openings, openings)); + + return _this; + } + + 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_1 = contexts[index]; + context_1.window.error(err); + context_1.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_2 = contexts[index]; + context_2.window.complete(); + context_2.subscription.unsubscribe(); + } + } + + _super.prototype._complete.call(this); + }; + + 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_3 = contexts[index]; + context_3.window.unsubscribe(); + context_3.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_4 = { + window: window_1, + subscription: subscription + }; + this.contexts.push(context_4); + var innerSubscription = subscribeToResult(this, closingNotifier, context_4); + + if (innerSubscription.closed) { + this.closeWindow(this.contexts.length - 1); + } else { + innerSubscription.context = context_4; + 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); + + /** PURE_IMPORTS_START tslib,.._Subject,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + + var WindowSubscriber$1 = + /*@__PURE__*/ + function (_super) { + __extends(WindowSubscriber, _super); + + function WindowSubscriber(destination, closingSelector) { + var _this = _super.call(this, destination) || this; + + _this.destination = destination; + _this.closingSelector = closingSelector; + + _this.openWindow(); + + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */ + /* 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. + * + * 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. + * + * + * + * `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 On every click event, emit an array with the latest timer event plus the click event + * 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() { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(WithLatestFromSubscriber, _super); + + function WithLatestFromSubscriber(destination, observables, project) { + var _this = _super.call(this, destination) || this; + + _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)); + } + + return _this; + } + + 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); + + /** PURE_IMPORTS_START tslib,._fromArray,.._util_isArray,.._Subscriber,.._OuterSubscriber,.._util_subscribeToResult,.._.._internal_symbol_iterator PURE_IMPORTS_END */ + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var ZipSubscriber = + /*@__PURE__*/ + function (_super) { + __extends(ZipSubscriber, _super); + + function ZipSubscriber(destination, project, values) { + if (values === void 0) { + values = Object.create(null); + } + + var _this = _super.call(this, destination) || this; + + _this.iterators = []; + _this.active = 0; + _this.project = typeof project === 'function' ? project : null; + _this.values = values; + return _this; + } + + 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + + /*@__PURE__*/ + 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 = + /*@__PURE__*/ + function (_super) { + __extends(ZipBufferIterator, _super); + + function ZipBufferIterator(destination, parent, observable) { + var _this = _super.call(this, destination) || this; + + _this.parent = parent; + _this.observable = observable; + _this.stillUnsubscribed = true; + _this.buffer = []; + _this.isComplete = false; + return _this; + } + + 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); + + /** PURE_IMPORTS_START .._observable_zip PURE_IMPORTS_END */ + + /* Operator exports */ + + var isFunction_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function isFunction(x) { + return typeof x === 'function'; + } + + exports.isFunction = isFunction; + }); + unwrapExports(isFunction_1); + var isFunction_2 = isFunction_1.isFunction; + + var Observer$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.empty = { + closed: true, + next: function next(value) {}, + error: function error(err) { + throw err; + }, + complete: function complete() {} + }; + }); + unwrapExports(Observer$1); + var Observer_1 = Observer$1.empty; + + var isArray$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + exports.isArray = Array.isArray || function (x) { + return x && typeof x.length === 'number'; + }; + + }); + unwrapExports(isArray$1); + var isArray_1 = isArray$1.isArray; + + var isObject_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function isObject(x) { + return x != null && typeof x === 'object'; + } + + exports.isObject = isObject; + }); + unwrapExports(isObject_1); + var isObject_2 = isObject_1.isObject; + + var errorObject$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); // typeof any so that it we don't have to cast when comparing a result to the error object + + exports.errorObject = { + e: {} + }; + }); + unwrapExports(errorObject$1); + var errorObject_1 = errorObject$1.errorObject; + + var tryCatch_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var tryCatchTarget; + + function tryCatcher() { + try { + return tryCatchTarget.apply(this, arguments); + } catch (e) { + errorObject$1.errorObject.e = e; + return errorObject$1.errorObject; + } + } + + function tryCatch(fn) { + tryCatchTarget = fn; + return tryCatcher; + } + + exports.tryCatch = tryCatch; + }); + unwrapExports(tryCatch_1); + var tryCatch_2 = tryCatch_1.tryCatch; + + var UnsubscriptionError_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * An error thrown when one or more errors have occurred during the + * `unsubscribe` of a {@link Subscription}. + */ + + var UnsubscriptionError = + /** @class */ + function (_super) { + __extends(UnsubscriptionError, _super); + + function UnsubscriptionError(errors) { + var _this = _super.call(this, errors ? errors.length + " errors occurred during unsubscription:\n " + errors.map(function (err, i) { + return i + 1 + ") " + err.toString(); + }).join('\n ') : '') || this; + + _this.errors = errors; + _this.name = 'UnsubscriptionError'; + Object.setPrototypeOf(_this, UnsubscriptionError.prototype); + return _this; + } + + return UnsubscriptionError; + }(Error); + + exports.UnsubscriptionError = UnsubscriptionError; + }); + unwrapExports(UnsubscriptionError_1); + var UnsubscriptionError_2 = UnsubscriptionError_1.UnsubscriptionError; + + var Subscription_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 = + /** @class */ + 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; + /** @internal */ + + this._parent = null; + /** @internal */ + + this._parents = null; + /** @internal */ + + 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_1.isFunction(_unsubscribe)) { + var trial = tryCatch_1.tryCatch(_unsubscribe).call(this); + + if (trial === errorObject$1.errorObject) { + hasErrors = true; + errors = errors || (errorObject$1.errorObject.e instanceof UnsubscriptionError_1.UnsubscriptionError ? flattenUnsubscriptionErrors(errorObject$1.errorObject.e.errors) : [errorObject$1.errorObject.e]); + } + } + + if (isArray$1.isArray(_subscriptions)) { + index = -1; + len = _subscriptions.length; + + while (++index < len) { + var sub = _subscriptions[index]; + + if (isObject_1.isObject(sub)) { + var trial = tryCatch_1.tryCatch(sub.unsubscribe).call(sub); + + if (trial === errorObject$1.errorObject) { + hasErrors = true; + errors = errors || []; + var err = errorObject$1.errorObject.e; + + if (err instanceof UnsubscriptionError_1.UnsubscriptionError) { + errors = errors.concat(flattenUnsubscriptionErrors(err.errors)); + } else { + errors.push(err); + } + } + } + } + } + + if (hasErrors) { + throw new UnsubscriptionError_1.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); + } + } + }; + /** @internal */ + + + 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; + }(); + + exports.Subscription = Subscription; + + function flattenUnsubscriptionErrors(errors) { + return errors.reduce(function (errs, err) { + return errs.concat(err instanceof UnsubscriptionError_1.UnsubscriptionError ? err.errors : err); + }, []); + } + + }); + unwrapExports(Subscription_1); + var Subscription_2 = Subscription_1.Subscription; + + var rxSubscriber$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.rxSubscriber = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('rxSubscriber') : '@@rxSubscriber'; + /** + * @deprecated use rxSubscriber instead + */ + + exports.$$rxSubscriber = exports.rxSubscriber; + }); + unwrapExports(rxSubscriber$1); + var rxSubscriber_1 = rxSubscriber$1.rxSubscriber; + var rxSubscriber_2 = rxSubscriber$1.$$rxSubscriber; + + var Subscriber_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 + */ + + var Subscriber = + /** @class */ + 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) { + var _this = _super.call(this) || this; + + _this.isStopped = false; + + switch (arguments.length) { + case 0: + _this.destination = Observer$1.empty; + break; + + case 1: + if (!destinationOrNext) { + _this.destination = Observer$1.empty; + break; + } + + if (typeof destinationOrNext === 'object') { + if (destinationOrNext instanceof Subscriber) { + _this.destination = destinationOrNext; + + _this.destination.add(_this); + } else { + _this.destination = new SafeSubscriber(destinationOrNext); + } + + break; + } + + default: + _this.destination = new SafeSubscriber(destinationOrNext, error, complete); + break; + } + + return _this; + } + + Subscriber.prototype[rxSubscriber$1.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} 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); + 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(); + }; + + 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_1.Subscription); + + exports.Subscriber = Subscriber; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var SafeSubscriber = + /** @class */ + function (_super) { + __extends(SafeSubscriber, _super); + + function SafeSubscriber(observerOrNext, error, complete) { + var _this = _super.call(this) || this; + + var next; + var context = _this; + + if (isFunction_1.isFunction(observerOrNext)) { + next = observerOrNext; + } else if (observerOrNext) { + next = observerOrNext.next; + error = observerOrNext.error; + complete = observerOrNext.complete; + + if (observerOrNext !== Observer$1.empty) { + context = Object.create(observerOrNext); + + if (isFunction_1.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; + return _this; + } + + SafeSubscriber.prototype.next = function (value) { + if (!this.isStopped && this._next) { + try { + this._next.call(this._context, value); + } catch (err) { + this._hostReportError(err); + + this.unsubscribe(); + } + } + }; + + SafeSubscriber.prototype.error = function (err) { + if (!this.isStopped) { + if (this._error) { + try { + this._error.call(this._context, err); + } catch (err) { + this._hostReportError(err); + } + } else { + this._hostReportError(err); + } + + this.unsubscribe(); + } + }; + + SafeSubscriber.prototype.complete = function () { + if (!this.isStopped) { + if (this._complete) { + try { + this._complete.call(this._context); + } catch (err) { + this._hostReportError(err); + } + } + + this.unsubscribe(); + } + }; + + SafeSubscriber.prototype._unsubscribe = function () { + this._context = null; + }; + + SafeSubscriber.prototype._hostReportError = function (err) { + setTimeout(function () { + throw err; + }); + }; + + return SafeSubscriber; + }(Subscriber); + + }); + unwrapExports(Subscriber_1); + var Subscriber_2 = Subscriber_1.Subscriber; + + var toSubscriber_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function toSubscriber(nextOrObserver, error, complete) { + if (nextOrObserver) { + if (nextOrObserver instanceof Subscriber_1.Subscriber) { + return nextOrObserver; + } + + if (nextOrObserver[rxSubscriber$1.rxSubscriber]) { + return nextOrObserver[rxSubscriber$1.rxSubscriber](); + } + } + + if (!nextOrObserver && !error && !complete) { + return new Subscriber_1.Subscriber(Observer$1.empty); + } + + return new Subscriber_1.Subscriber(nextOrObserver, error, complete); + } + + exports.toSubscriber = toSubscriber; + }); + unwrapExports(toSubscriber_1); + var toSubscriber_2 = toSubscriber_1.toSubscriber; + + var observable$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** Symbol.observable or a string "@@observable". Used for interop */ + + exports.observable = typeof Symbol === 'function' && Symbol.observable || '@@observable'; + }); + unwrapExports(observable$1); + var observable_1 = observable$1.observable; + + var noop_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:disable:no-empty */ + + function noop() {} + + exports.noop = noop; + }); + unwrapExports(noop_1); + var noop_2 = noop_1.noop; + + var pipe_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:enable:max-line-length */ + + function pipe() { + var fns = []; + + for (var _i = 0; _i < arguments.length; _i++) { + fns[_i] = arguments[_i]; + } + + return pipeFromArray(fns); + } + + exports.pipe = pipe; + /* @internal */ + + function pipeFromArray(fns) { + if (!fns) { + return noop_1.noop; + } + + if (fns.length === 1) { + return fns[0]; + } + + return function piped(input) { + return fns.reduce(function (prev, fn) { + return fn(prev); + }, input); + }; + } + + exports.pipeFromArray = pipeFromArray; + }); + unwrapExports(pipe_1); + var pipe_2 = pipe_1.pipe; + var pipe_3 = pipe_1.pipeFromArray; + + var config$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * The global configuration object for RxJS, used to configure things + * like what Promise contructor should used to create Promises + */ + + exports.config = { + /** + * The promise constructor used by default for methods such as + * {@link toPromise} and {@link forEach} + */ + Promise: Promise + }; + }); + unwrapExports(config$1); + var config_1 = config$1.config; + + var Observable_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * A representation of any set of values over any amount of time. This is the most basic building block + * of RxJS. + * + * @class Observable + */ + + var Observable = + /** @class */ + 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) { + /** @internal */ + 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 = new Observable(); + observable.source = this; + observable.operator = operator; + return observable; + }; + /** + * Invokes an execution of an Observable and registers Observer handlers for notifications it will emit. + * + * Use it when you have all these Observables, but still nothing is happening. + * + * `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 Subscribe with an Observer + * 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 Subscribe with functions + * 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 Cancel a subscription + * 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_1.toSubscriber(observerOrNext, error, complete); + + if (operator) { + operator.call(sink, this.source); + } else { + sink.add(this.source ? this._subscribe(sink) : this._trySubscribe(sink)); + } + + return sink; + }; + + Observable.prototype._trySubscribe = function (sink) { + try { + return this._subscribe(sink); + } catch (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; + + promiseCtor = getPromiseCtor(promiseCtor); + 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) { + try { + next(value); + } catch (err) { + reject(err); + + if (subscription) { + subscription.unsubscribe(); + } + } + }, reject, resolve); + }); + }; + /** @internal */ + + + 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$1.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/internal/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] = arguments[_i]; + } + + if (operations.length === 0) { + return this; + } + + return pipe_1.pipeFromArray(operations)(this); + }; + /* tslint:enable:max-line-length */ + + + Observable.prototype.toPromise = function (promiseCtor) { + var _this = this; + + promiseCtor = getPromiseCtor(promiseCtor); + 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; + }(); + + exports.Observable = Observable; + /** + * Decides between a passed promise constructor from consuming code, + * A default configured promise constructor, and the native promise + * constructor and returns it. If nothing can be found, it will throw + * an error. + * @param promiseCtor The optional promise constructor to passed by consuming code + */ + + function getPromiseCtor(promiseCtor) { + if (!promiseCtor) { + promiseCtor = config$1.config.Promise || Promise; + } + + if (!promiseCtor) { + throw new Error('no Promise impl found'); + } + + return promiseCtor; + } + + }); + unwrapExports(Observable_1); + var Observable_2 = Observable_1.Observable; + + var ObjectUnsubscribedError_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * An error thrown when an action is invalid because the object has been + * unsubscribed. + * + * @see {@link Subject} + * @see {@link BehaviorSubject} + * + * @class ObjectUnsubscribedError + */ + + var ObjectUnsubscribedError = + /** @class */ + function (_super) { + __extends(ObjectUnsubscribedError, _super); + + function ObjectUnsubscribedError() { + var _this = _super.call(this, 'object unsubscribed') || this; + + _this.name = 'ObjectUnsubscribedError'; + Object.setPrototypeOf(_this, ObjectUnsubscribedError.prototype); + return _this; + } + + return ObjectUnsubscribedError; + }(Error); + + exports.ObjectUnsubscribedError = ObjectUnsubscribedError; + }); + unwrapExports(ObjectUnsubscribedError_1); + var ObjectUnsubscribedError_2 = ObjectUnsubscribedError_1.ObjectUnsubscribedError; + + var SubjectSubscription_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var SubjectSubscription = + /** @class */ + function (_super) { + __extends(SubjectSubscription, _super); + + function SubjectSubscription(subject, subscriber) { + var _this = _super.call(this) || this; + + _this.subject = subject; + _this.subscriber = subscriber; + _this.closed = false; + return _this; + } + + 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_1.Subscription); + + exports.SubjectSubscription = SubjectSubscription; + }); + unwrapExports(SubjectSubscription_1); + var SubjectSubscription_2 = SubjectSubscription_1.SubjectSubscription; + + var Subject_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * @class SubjectSubscriber + */ + + var SubjectSubscriber = + /** @class */ + function (_super) { + __extends(SubjectSubscriber, _super); + + function SubjectSubscriber(destination) { + var _this = _super.call(this, destination) || this; + + _this.destination = destination; + return _this; + } + + return SubjectSubscriber; + }(Subscriber_1.Subscriber); + + exports.SubjectSubscriber = SubjectSubscriber; + /** + * @class Subject + */ + + var Subject = + /** @class */ + function (_super) { + __extends(Subject, _super); + + function Subject() { + var _this = _super.call(this) || this; + + _this.observers = []; + _this.closed = false; + _this.isStopped = false; + _this.hasError = false; + _this.thrownError = null; + return _this; + } + + Subject.prototype[rxSubscriber$1.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_1.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_1.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_1.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_1.ObjectUnsubscribedError(); + } else { + return _super.prototype._trySubscribe.call(this, subscriber); + } + }; + + Subject.prototype._subscribe = function (subscriber) { + if (this.closed) { + throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError(); + } else if (this.hasError) { + subscriber.error(this.thrownError); + return Subscription_1.Subscription.EMPTY; + } else if (this.isStopped) { + subscriber.complete(); + return Subscription_1.Subscription.EMPTY; + } else { + this.observers.push(subscriber); + return new SubjectSubscription_1.SubjectSubscription(this, subscriber); + } + }; + + Subject.prototype.asObservable = function () { + var observable = new Observable_1.Observable(); + observable.source = this; + return observable; + }; + + Subject.create = function (destination, source) { + return new AnonymousSubject(destination, source); + }; + + return Subject; + }(Observable_1.Observable); + + exports.Subject = Subject; + /** + * @class AnonymousSubject + */ + + var AnonymousSubject = + /** @class */ + function (_super) { + __extends(AnonymousSubject, _super); + + function AnonymousSubject(destination, source) { + var _this = _super.call(this) || this; + + _this.destination = destination; + _this.source = source; + return _this; + } + + 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(); + } + }; + + AnonymousSubject.prototype._subscribe = function (subscriber) { + var source = this.source; + + if (source) { + return this.source.subscribe(subscriber); + } else { + return Subscription_1.Subscription.EMPTY; + } + }; + + return AnonymousSubject; + }(Subject); + + exports.AnonymousSubject = AnonymousSubject; + }); + unwrapExports(Subject_1); + var Subject_2 = Subject_1.SubjectSubscriber; + var Subject_3 = Subject_1.Subject; + var Subject_4 = Subject_1.AnonymousSubject; + + var refCount_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function refCount() { + return function refCountOperatorFunction(source) { + return source.lift(new RefCountOperator(source)); + }; + } + + exports.refCount = refCount; + + var RefCountOperator = + /** @class */ + function () { + function RefCountOperator(connectable) { + this.connectable = connectable; + } + + RefCountOperator.prototype.call = function (subscriber, source) { + var connectable = this.connectable; + connectable._refCount++; + var refCounter = new RefCountSubscriber(subscriber, connectable); + var subscription = source.subscribe(refCounter); + + if (!refCounter.closed) { + refCounter.connection = connectable.connect(); + } + + return subscription; + }; + + return RefCountOperator; + }(); + + var RefCountSubscriber = + /** @class */ + function (_super) { + __extends(RefCountSubscriber, _super); + + function RefCountSubscriber(destination, connectable) { + var _this = _super.call(this, destination) || this; + + _this.connectable = connectable; + return _this; + } + + 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_1.Subscriber); + + }); + unwrapExports(refCount_1); + var refCount_2 = refCount_1.refCount; + + var ConnectableObservable_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * @class ConnectableObservable + */ + + var ConnectableObservable = + /** @class */ + function (_super) { + __extends(ConnectableObservable, _super); + + function ConnectableObservable(source, subjectFactory) { + var _this = _super.call(this) || this; + + _this.source = source; + _this.subjectFactory = subjectFactory; + _this._refCount = 0; + /** @internal */ + + _this._isComplete = false; + return _this; + } + + ConnectableObservable.prototype._subscribe = function (subscriber) { + return this.getSubject().subscribe(subscriber); + }; + + 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_1.Subscription(); + connection.add(this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this))); + + if (connection.closed) { + this._connection = null; + connection = Subscription_1.Subscription.EMPTY; + } else { + this._connection = connection; + } + } + + return connection; + }; + + ConnectableObservable.prototype.refCount = function () { + return refCount_1.refCount()(this); + }; + + return ConnectableObservable; + }(Observable_1.Observable); + + exports.ConnectableObservable = ConnectableObservable; + var connectableProto = ConnectableObservable.prototype; + exports.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 = + /** @class */ + function (_super) { + __extends(ConnectableSubscriber, _super); + + function ConnectableSubscriber(destination, connectable) { + var _this = _super.call(this, destination) || this; + + _this.connectable = connectable; + return _this; + } + + 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); + }; + + 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; + }(Subject_1.SubjectSubscriber); + + var RefCountSubscriber = + /** @class */ + function (_super) { + __extends(RefCountSubscriber, _super); + + function RefCountSubscriber(destination, connectable) { + var _this = _super.call(this, destination) || this; + + _this.connectable = connectable; + return _this; + } + + 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_1.Subscriber); + + }); + unwrapExports(ConnectableObservable_1); + var ConnectableObservable_2 = ConnectableObservable_1.ConnectableObservable; + var ConnectableObservable_3 = ConnectableObservable_1.connectableObservableDescriptor; + + var BehaviorSubject_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * @class BehaviorSubject + */ + + var BehaviorSubject = + /** @class */ + function (_super) { + __extends(BehaviorSubject, _super); + + function BehaviorSubject(_value) { + var _this = _super.call(this) || this; + + _this._value = _value; + return _this; + } + + Object.defineProperty(BehaviorSubject.prototype, "value", { + get: function get() { + return this.getValue(); + }, + enumerable: true, + configurable: true + }); + + 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_1.ObjectUnsubscribedError(); + } else { + return this._value; + } + }; + + BehaviorSubject.prototype.next = function (value) { + _super.prototype.next.call(this, this._value = value); + }; + + return BehaviorSubject; + }(Subject_1.Subject); + + exports.BehaviorSubject = BehaviorSubject; + }); + unwrapExports(BehaviorSubject_1); + var BehaviorSubject_2 = BehaviorSubject_1.BehaviorSubject; + + var Action_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 extends Subscription { + * new (scheduler: Scheduler, work: (state?: T) => void); + * schedule(state?: T, delay: number = 0): Subscription; + * } + * ``` + * + * @class Action + */ + + var Action = + /** @class */ + function (_super) { + __extends(Action, _super); + + function Action(scheduler, work) { + return _super.call(this) || 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_1.Subscription); + + exports.Action = Action; + }); + unwrapExports(Action_1); + var Action_2 = Action_1.Action; + + var AsyncAction_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var AsyncAction = + /** @class */ + function (_super) { + __extends(AsyncAction, _super); + + function AsyncAction(scheduler, work) { + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + _this.pending = false; + return _this; + } + + 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; + 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); + } // Set the pending flag indicating that this action has been scheduled, or + // has recursively rescheduled itself. + + + this.pending = true; + 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 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 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; + } + }; + + 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_1.Action); + + exports.AsyncAction = AsyncAction; + }); + unwrapExports(AsyncAction_1); + var AsyncAction_2 = AsyncAction_1.AsyncAction; + + var QueueAction_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var QueueAction = + /** @class */ + function (_super) { + __extends(QueueAction, _super); + + function QueueAction(scheduler, work) { + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + return _this; + } + + 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_1.AsyncAction); + + exports.QueueAction = QueueAction; + }); + unwrapExports(QueueAction_1); + var QueueAction_2 = QueueAction_1.QueueAction; + + var Scheduler_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 = + /** @class */ + 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; + }(); + + exports.Scheduler = Scheduler; + }); + unwrapExports(Scheduler_1); + var Scheduler_2 = Scheduler_1.Scheduler; + + var AsyncScheduler_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var AsyncScheduler = + /** @class */ + function (_super) { + __extends(AsyncScheduler, _super); + + function AsyncScheduler() { + var _this = _super !== null && _super.apply(this, arguments) || this; + + _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; + return _this; + } + + 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.Scheduler); + + exports.AsyncScheduler = AsyncScheduler; + }); + unwrapExports(AsyncScheduler_1); + var AsyncScheduler_2 = AsyncScheduler_1.AsyncScheduler; + + var QueueScheduler_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var QueueScheduler = + /** @class */ + function (_super) { + __extends(QueueScheduler, _super); + + function QueueScheduler() { + return _super !== null && _super.apply(this, arguments) || this; + } + + return QueueScheduler; + }(AsyncScheduler_1.AsyncScheduler); + + exports.QueueScheduler = QueueScheduler; + }); + unwrapExports(QueueScheduler_1); + var QueueScheduler_2 = QueueScheduler_1.QueueScheduler; + + var queue$2 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * + * Queue Scheduler + * + * Put every next task on a queue, instead of executing it immediately + * + * `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 Schedule recursively first, then do something + * + * 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 Reschedule itself recursively + * + * 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 + */ + + exports.queue = new QueueScheduler_1.QueueScheduler(QueueAction_1.QueueAction); + }); + unwrapExports(queue$2); + var queue_1 = queue$2.queue; + + var empty_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * The same Observable instance returned by any call to {@link empty} without a + * {@link Scheduler}. It is preferrable to use this over `empty()`. + */ + + exports.EMPTY = new Observable_1.Observable(function (subscriber) { + return subscriber.complete(); + }); + /** + * Creates an Observable that emits no items to the Observer and immediately + * emits a complete notification. + * + * Just emits 'complete', and nothing else. + * + * + * + * + * 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 Emit the number 7, then complete. + * var result = Rx.Observable.empty().startWith(7); + * result.subscribe(x => console.log(x)); + * + * @example Map and flatten only odd numbers to the sequence 'a', 'b', 'c' + * 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 + */ + + function empty(scheduler) { + return scheduler ? emptyScheduled(scheduler) : exports.EMPTY; + } + + exports.empty = empty; + + function emptyScheduled(scheduler) { + return new Observable_1.Observable(function (subscriber) { + return scheduler.schedule(function () { + return subscriber.complete(); + }); + }); + } + + exports.emptyScheduled = emptyScheduled; + }); + unwrapExports(empty_1); + var empty_2 = empty_1.EMPTY; + var empty_3 = empty_1.empty; + var empty_4 = empty_1.emptyScheduled; + + var isScheduler_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function isScheduler(value) { + return value && typeof value.schedule === 'function'; + } + + exports.isScheduler = isScheduler; + }); + unwrapExports(isScheduler_1); + var isScheduler_2 = isScheduler_1.isScheduler; + + var subscribeToArray$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Subscribes to an ArrayLike with a subscriber + * @param array The array or array-like to subscribe to + * @param subscriber The subscriber to subscribe with. + */ + + exports.subscribeToArray = function (array) { + return function (subscriber) { + for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) { + subscriber.next(array[i]); + } + + if (!subscriber.closed) { + subscriber.complete(); + } + }; + }; + + }); + unwrapExports(subscribeToArray$1); + var subscribeToArray_1 = subscribeToArray$1.subscribeToArray; + + var fromArray_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function fromArray(input, scheduler) { + if (!scheduler) { + return new Observable_1.Observable(subscribeToArray$1.subscribeToArray(input)); + } else { + return new Observable_1.Observable(function (subscriber) { + var sub = new Subscription_1.Subscription(); + var i = 0; + sub.add(scheduler.schedule(function () { + if (i === input.length) { + subscriber.complete(); + return; + } + + subscriber.next(input[i++]); + + if (!subscriber.closed) { + sub.add(this.schedule()); + } + })); + return sub; + }); + } + } + + exports.fromArray = fromArray; + }); + unwrapExports(fromArray_1); + var fromArray_2 = fromArray_1.fromArray; + + var scalar_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function scalar(value) { + var result = new Observable_1.Observable(function (subscriber) { + subscriber.next(value); + subscriber.complete(); + }); + result._isScalar = true; + result.value = value; + return result; + } + + exports.scalar = scalar; + }); + unwrapExports(scalar_1); + var scalar_2 = scalar_1.scalar; + + var of_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function of() { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + var scheduler = args[args.length - 1]; + + if (isScheduler_1.isScheduler(scheduler)) { + args.pop(); + } else { + scheduler = undefined; + } + + switch (args.length) { + case 0: + return empty_1.empty(scheduler); + + case 1: + return scheduler ? fromArray_1.fromArray(args, scheduler) : scalar_1.scalar(args[0]); + + default: + return fromArray_1.fromArray(args, scheduler); + } + } + + exports.of = of; + }); + unwrapExports(of_1); + var of_2 = of_1.of; + + var throwError_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Creates an Observable that emits no items to the Observer and immediately + * emits an error notification. + * + * Just emits 'error', and nothing else. + * + * + * + * + * 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 Emit the number 7, then emit an error. + * import { throwError, concat, of } from 'rxjs/create'; + * + * const result = concat(of(7), throwError(new Error('oops!'))); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @example Map and flatten numbers to the sequence 'a', 'b', 'c', but throw an error for 13 + * import { throwError, interval, of } from 'rxjs/create'; + * import { mergeMap } from 'rxjs/operators'; + * + * interval(1000).pipe( + * mergeMap(x => x === 13 ? + * throwError('Thirteens are bad') : + * of('a', 'b', 'c') + * ) + * ).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 + */ + + function throwError(error, scheduler) { + if (!scheduler) { + return new Observable_1.Observable(function (subscriber) { + return subscriber.error(error); + }); + } else { + return new Observable_1.Observable(function (subscriber) { + return scheduler.schedule(dispatch, 0, { + error: error, + subscriber: subscriber + }); + }); + } + } + + exports.throwError = throwError; + + function dispatch(_a) { + var error = _a.error, + subscriber = _a.subscriber; + subscriber.error(error); + } + + }); + unwrapExports(throwError_1); + var throwError_2 = throwError_1.throwError; + + var Notification_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 + */ + + var Notification = + /** @class */ + 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 of_1.of(this.value); + + case 'E': + return throwError_1.throwError(this.error); + + case 'C': + return empty_1.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} 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} 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} The valueless "complete" Notification. + */ + + + Notification.createComplete = function () { + return Notification.completeNotification; + }; + + Notification.completeNotification = new Notification('C'); + Notification.undefinedValueNotification = new Notification('N', undefined); + return Notification; + }(); + + exports.Notification = Notification; + }); + unwrapExports(Notification_1); + var Notification_2 = Notification_1.Notification; + + var observeOn_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * + * Re-emits all notifications from source Observable with specified scheduler. + * + * Ensure a specific scheduler is used, from outside of an Observable. + * + * `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 Ensure values in subscribe are called just before browser repaint. + * 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 {SchedulerLike} 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} 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)); + }; + } + + exports.observeOn = observeOn; + + var ObserveOnOperator = + /** @class */ + 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; + }(); + + exports.ObserveOnOperator = ObserveOnOperator; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var ObserveOnSubscriber = + /** @class */ + function (_super) { + __extends(ObserveOnSubscriber, _super); + + function ObserveOnSubscriber(destination, scheduler, delay) { + if (delay === void 0) { + delay = 0; + } + + var _this = _super.call(this, destination) || this; + + _this.scheduler = scheduler; + _this.delay = delay; + return _this; + } + + 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_1.Notification.createNext(value)); + }; + + ObserveOnSubscriber.prototype._error = function (err) { + this.scheduleMessage(Notification_1.Notification.createError(err)); + }; + + ObserveOnSubscriber.prototype._complete = function () { + this.scheduleMessage(Notification_1.Notification.createComplete()); + }; + + return ObserveOnSubscriber; + }(Subscriber_1.Subscriber); + + exports.ObserveOnSubscriber = ObserveOnSubscriber; + + var ObserveOnMessage = + /** @class */ + function () { + function ObserveOnMessage(notification, destination) { + this.notification = notification; + this.destination = destination; + } + + return ObserveOnMessage; + }(); + + exports.ObserveOnMessage = ObserveOnMessage; + }); + unwrapExports(observeOn_1); + var observeOn_2 = observeOn_1.observeOn; + var observeOn_3 = observeOn_1.ObserveOnOperator; + var observeOn_4 = observeOn_1.ObserveOnSubscriber; + var observeOn_5 = observeOn_1.ObserveOnMessage; + + var ReplaySubject_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * @class ReplaySubject + */ + + var ReplaySubject = + /** @class */ + 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; + } + + var _this = _super.call(this) || this; + + _this.scheduler = scheduler; + _this._events = []; + _this._bufferSize = bufferSize < 1 ? 1 : bufferSize; + _this._windowTime = windowTime < 1 ? 1 : windowTime; + return _this; + } + + ReplaySubject.prototype.next = function (value) { + var now = this._getNow(); + + this._events.push(new ReplayEvent(now, value)); + + this._trimBufferThenGetEvents(); + + _super.prototype.next.call(this, value); + }; + + ReplaySubject.prototype._subscribe = function (subscriber) { + var _events = this._trimBufferThenGetEvents(); + + var scheduler = this.scheduler; + var subscription; + + if (this.closed) { + throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError(); + } else if (this.hasError) { + subscription = Subscription_1.Subscription.EMPTY; + } else if (this.isStopped) { + subscription = Subscription_1.Subscription.EMPTY; + } else { + this.observers.push(subscriber); + subscription = new SubjectSubscription_1.SubjectSubscription(this, subscriber); + } + + if (scheduler) { + subscriber.add(subscriber = new observeOn_1.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$2.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_1.Subject); + + exports.ReplaySubject = ReplaySubject; + + var ReplayEvent = + /** @class */ + function () { + function ReplayEvent(time, value) { + this.time = time; + this.value = value; + } + + return ReplayEvent; + }(); + + }); + unwrapExports(ReplaySubject_1); + var ReplaySubject_2 = ReplaySubject_1.ReplaySubject; + + var AsyncSubject_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * @class AsyncSubject + */ + + var AsyncSubject = + /** @class */ + function (_super) { + __extends(AsyncSubject, _super); + + function AsyncSubject() { + var _this = _super !== null && _super.apply(this, arguments) || this; + + _this.value = null; + _this.hasNext = false; + _this.hasCompleted = false; + return _this; + } + + AsyncSubject.prototype._subscribe = function (subscriber) { + if (this.hasError) { + subscriber.error(this.thrownError); + return Subscription_1.Subscription.EMPTY; + } else if (this.hasCompleted && this.hasNext) { + subscriber.next(this.value); + subscriber.complete(); + return Subscription_1.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_1.Subject); + + exports.AsyncSubject = AsyncSubject; + }); + unwrapExports(AsyncSubject_1); + var AsyncSubject_2 = AsyncSubject_1.AsyncSubject; + + var Immediate = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var nextHandle = 0; + var tasksByHandle = {}; + + function runIfPresent(handle) { + var cb = tasksByHandle[handle]; + + if (cb) { + cb(); + } + } + + exports.Immediate = { + setImmediate: function setImmediate(cb) { + var handle = nextHandle++; + tasksByHandle[handle] = cb; + Promise.resolve().then(function () { + return runIfPresent(handle); + }); + return handle; + }, + clearImmediate: function clearImmediate(handle) { + delete tasksByHandle[handle]; + } + }; + }); + unwrapExports(Immediate); + var Immediate_1 = Immediate.Immediate; + + var AsapAction_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var AsapAction = + /** @class */ + function (_super) { + __extends(AsapAction, _super); + + function AsapAction(scheduler, work) { + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + return _this; + } + + 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.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.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_1.AsyncAction); + + exports.AsapAction = AsapAction; + }); + unwrapExports(AsapAction_1); + var AsapAction_2 = AsapAction_1.AsapAction; + + var AsapScheduler_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var AsapScheduler = + /** @class */ + function (_super) { + __extends(AsapScheduler, _super); + + function AsapScheduler() { + return _super !== null && _super.apply(this, arguments) || this; + } + + 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_1.AsyncScheduler); + + exports.AsapScheduler = AsapScheduler; + }); + unwrapExports(AsapScheduler_1); + var AsapScheduler_2 = AsapScheduler_1.AsapScheduler; + + var asap = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * + * Asap Scheduler + * + * Perform task as fast as it can be performed asynchronously + * + * `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 Compare async and asap scheduler + * + * 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 + */ + + exports.asap = new AsapScheduler_1.AsapScheduler(AsapAction_1.AsapAction); + }); + unwrapExports(asap); + var asap_1 = asap.asap; + + var async$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * + * Async Scheduler + * + * Schedule task as if you used setTimeout(task, duration) + * + * `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 Use async scheduler to delay task + * const task = () => console.log('it works!'); + * + * Rx.Scheduler.async.schedule(task, 2000); + * + * // After 2 seconds logs: + * // "it works!" + * + * + * @example Use async scheduler to repeat task in intervals + * 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 + */ + + exports.async = new AsyncScheduler_1.AsyncScheduler(AsyncAction_1.AsyncAction); + }); + unwrapExports(async$1); + var async_1 = async$1.async; + + var AnimationFrameAction_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var AnimationFrameAction = + /** @class */ + function (_super) { + __extends(AnimationFrameAction, _super); + + function AnimationFrameAction(scheduler, work) { + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + return _this; + } + + 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 = requestAnimationFrame(function () { + return scheduler.flush(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) { + 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_1.AsyncAction); + + exports.AnimationFrameAction = AnimationFrameAction; + }); + unwrapExports(AnimationFrameAction_1); + var AnimationFrameAction_2 = AnimationFrameAction_1.AnimationFrameAction; + + var AnimationFrameScheduler_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var AnimationFrameScheduler = + /** @class */ + function (_super) { + __extends(AnimationFrameScheduler, _super); + + function AnimationFrameScheduler() { + return _super !== null && _super.apply(this, arguments) || this; + } + + 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_1.AsyncScheduler); + + exports.AnimationFrameScheduler = AnimationFrameScheduler; + }); + unwrapExports(AnimationFrameScheduler_1); + var AnimationFrameScheduler_2 = AnimationFrameScheduler_1.AnimationFrameScheduler; + + var animationFrame = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * + * Animation Frame Scheduler + * + * Perform task when `window.requestAnimationFrame` would fire + * + * 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 Schedule div height animation + * const div = document.querySelector('.some-div'); + * + * Rx.Scheduler.animationFrame.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 + */ + + exports.animationFrame = new AnimationFrameScheduler_1.AnimationFrameScheduler(AnimationFrameAction_1.AnimationFrameAction); + }); + unwrapExports(animationFrame); + var animationFrame_1 = animationFrame.animationFrame; + + var _strictMethod = function (method, arg) { + return !!method && _fails(function () { + // eslint-disable-next-line no-useless-call + arg ? method.call(null, function () { /* empty */ }, 1) : method.call(null); + }); + }; + + var $sort = [].sort; + var test = [1, 2, 3]; + + _export(_export.P + _export.F * (_fails(function () { + // IE8- + test.sort(undefined); + }) || !_fails(function () { + // V8 bug + test.sort(null); + // Old WebKit + }) || !_strictMethod($sort)), 'Array', { + // 22.1.3.25 Array.prototype.sort(comparefn) + sort: function sort(comparefn) { + return comparefn === undefined + ? $sort.call(_toObject(this)) + : $sort.call(_toObject(this), _aFunction(comparefn)); + } + }); + + var VirtualTimeScheduler_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var VirtualTimeScheduler = + /** @class */ + function (_super) { + __extends(VirtualTimeScheduler, _super); + + function VirtualTimeScheduler(SchedulerAction, maxFrames) { + if (SchedulerAction === void 0) { + SchedulerAction = VirtualAction; + } + + if (maxFrames === void 0) { + maxFrames = Number.POSITIVE_INFINITY; + } + + var _this = _super.call(this, SchedulerAction, function () { + return _this.frame; + }) || this; + + _this.maxFrames = maxFrames; + _this.frame = 0; + _this.index = -1; + return _this; + } + /** + * 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_1.AsyncScheduler); + + exports.VirtualTimeScheduler = VirtualTimeScheduler; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var VirtualAction = + /** @class */ + function (_super) { + __extends(VirtualAction, _super); + + function VirtualAction(scheduler, work, index) { + if (index === void 0) { + index = scheduler.index += 1; + } + + var _this = _super.call(this, scheduler, work) || this; + + _this.scheduler = scheduler; + _this.work = work; + _this.index = index; + _this.active = true; + _this.index = scheduler.index = index; + return _this; + } + + 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_1.AsyncAction); + + exports.VirtualAction = VirtualAction; + }); + unwrapExports(VirtualTimeScheduler_1); + var VirtualTimeScheduler_2 = VirtualTimeScheduler_1.VirtualTimeScheduler; + var VirtualTimeScheduler_3 = VirtualTimeScheduler_1.VirtualAction; + + var identity_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function identity(x) { + return x; + } + + exports.identity = identity; + }); + unwrapExports(identity_1); + var identity_2 = identity_1.identity; + + var ArgumentOutOfRangeError_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 = + /** @class */ + function (_super) { + __extends(ArgumentOutOfRangeError, _super); + + function ArgumentOutOfRangeError() { + var _this = _super.call(this, 'argument out of range') || this; + + _this.name = 'ArgumentOutOfRangeError'; + Object.setPrototypeOf(_this, ArgumentOutOfRangeError.prototype); + return _this; + } + + return ArgumentOutOfRangeError; + }(Error); + + exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError; + }); + unwrapExports(ArgumentOutOfRangeError_1); + var ArgumentOutOfRangeError_2 = ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; + + var EmptyError_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * 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 = + /** @class */ + function (_super) { + __extends(EmptyError, _super); + + function EmptyError() { + var _this = _super.call(this, 'no elements in sequence') || this; + + _this.name = 'EmptyError'; + Object.setPrototypeOf(_this, EmptyError.prototype); + return _this; + } + + return EmptyError; + }(Error); + + exports.EmptyError = EmptyError; + }); + unwrapExports(EmptyError_1); + var EmptyError_2 = EmptyError_1.EmptyError; + + var TimeoutError_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * An error thrown when duetime elapses. + * + * @see {@link timeout} + * + * @class TimeoutError + */ + + var TimeoutError = + /** @class */ + function (_super) { + __extends(TimeoutError, _super); + + function TimeoutError() { + var _this = _super.call(this, 'Timeout has occurred') || this; + + Object.setPrototypeOf(_this, TimeoutError.prototype); + return _this; + } + + return TimeoutError; + }(Error); + + exports.TimeoutError = TimeoutError; + }); + unwrapExports(TimeoutError_1); + var TimeoutError_2 = TimeoutError_1.TimeoutError; + + var bindCallback_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); // tslint:enable:max-line-length + + /** + * Converts a callback API to a function that returns an Observable. + * + * 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. + * + * `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. + * + * 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 Convert jQuery's getJSON to an Observable API + * // Suppose we have jQuery.getJSON('/my/url', callback) + * var getJSONAsObservable = bindCallback(jQuery.getJSON); + * var result = getJSONAsObservable('/my/url'); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * + * @example Receive an array of arguments passed to a callback + * someFunction((a, b, c) => { + * console.log(a); // 5 + * console.log(b); // 'some string' + * console.log(c); // {someProperty: 'someValue'} + * }); + * + * const boundSomeFunction = bindCallback(someFunction); + * boundSomeFunction().subscribe(values => { + * console.log(values) // [5, 'some string', {someProperty: 'someValue'}] + * }); + * + * + * @example Compare behaviour with and without async Scheduler + * function iCallMyCallbackSynchronously(cb) { + * cb(); + * } + * + * const boundSyncFn = bindCallback(iCallMyCallbackSynchronously); + * const boundAsyncFn = 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 Use bindCallback on an object method + * const boundMethod = 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 {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. + * @name bindCallback + */ + + function bindCallback(callbackFunc, scheduler) { + return function () { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + var context = this; + var subject; + var params = { + context: context, + subject: subject, + callbackFunc: callbackFunc, + scheduler: scheduler + }; + return new Observable_1.Observable(function (subscriber) { + if (!scheduler) { + if (!subject) { + subject = new AsyncSubject_1.AsyncSubject(); + + var handler = function handler() { + var innerArgs = []; + + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i] = arguments[_i]; + } + + subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs); + subject.complete(); + }; + + try { + callbackFunc.apply(context, args.concat([handler])); + } catch (err) { + subject.error(err); + } + } + + return subject.subscribe(subscriber); + } else { + var state = { + args: args, + subscriber: subscriber, + params: params + }; + return scheduler.schedule(dispatch, 0, state); + } + }); + }; + } + + exports.bindCallback = bindCallback; + + function dispatch(state) { + var _this = this; + var args = state.args, + subscriber = state.subscriber, + params = state.params; + var callbackFunc = params.callbackFunc, + context = params.context, + scheduler = params.scheduler; + var subject = params.subject; + + if (!subject) { + subject = params.subject = new AsyncSubject_1.AsyncSubject(); + + var handler = function handler() { + var innerArgs = []; + + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i] = arguments[_i]; + } + + var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs; + + _this.add(scheduler.schedule(dispatchNext, 0, { + value: value, + subject: subject + })); + }; + + try { + callbackFunc.apply(context, args.concat([handler])); + } catch (err) { + subject.error(err); + } + } + + this.add(subject.subscribe(subscriber)); + } + + function dispatchNext(state) { + var value = state.value, + subject = state.subject; + subject.next(value); + subject.complete(); + } + + }); + unwrapExports(bindCallback_1); + var bindCallback_2 = bindCallback_1.bindCallback; + + var bindNodeCallback_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:enable:max-line-length */ + + /** + * Converts a Node.js-style callback API to a function that returns an + * Observable. + * + * It's just like {@link bindCallback}, but the + * callback is expected to be of type `callback(error, result)`. + * + * `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. + * + * 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. + * + * + * @example Read a file from the filesystem and get the data as an Observable + * import * as fs from 'fs'; + * var readFileAsObservable = bindNodeCallback(fs.readFile); + * var result = readFileAsObservable('./roadNames.txt', 'utf8'); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * + * @example Use on function calling callback with multiple arguments + * someFunction((err, a, b) => { + * console.log(err); // null + * console.log(a); // 5 + * console.log(b); // "some string" + * }); + * var boundSomeFunction = bindNodeCallback(someFunction); + * boundSomeFunction() + * .subscribe(value => { + * console.log(value); // [5, "some string"] + * }); + * + * @example Use on function calling callback in regular style + * someFunction(a => { + * console.log(a); // 5 + * }); + * var boundSomeFunction = 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 {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. + * @name bindNodeCallback + */ + + function bindNodeCallback(callbackFunc, scheduler) { + return function () { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + var params = { + subject: undefined, + args: args, + callbackFunc: callbackFunc, + scheduler: scheduler, + context: this + }; + return new Observable_1.Observable(function (subscriber) { + var context = params.context; + var subject = params.subject; + + if (!scheduler) { + if (!subject) { + subject = params.subject = new AsyncSubject_1.AsyncSubject(); + + var handler = function handlerFn() { + var innerArgs = []; + + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i] = arguments[_i]; + } + + var err = innerArgs.shift(); + + if (err) { + subject.error(err); + return; + } + + subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs); + subject.complete(); + }; + + try { + callbackFunc.apply(context, args.concat([handler])); + } catch (err) { + subject.error(err); + } + } + + return subject.subscribe(subscriber); + } else { + return scheduler.schedule(dispatch, 0, { + params: params, + subscriber: subscriber, + context: context + }); + } + }); + }; + } + + exports.bindNodeCallback = bindNodeCallback; + + function dispatch(state) { + var _this = this; + + var params = state.params, + subscriber = state.subscriber, + context = state.context; + var callbackFunc = params.callbackFunc, + args = params.args, + scheduler = params.scheduler; + var subject = params.subject; + + if (!subject) { + subject = params.subject = new AsyncSubject_1.AsyncSubject(); + + var handler = function handler() { + var innerArgs = []; + + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i] = arguments[_i]; + } + + var err = innerArgs.shift(); + + if (err) { + _this.add(scheduler.schedule(dispatchError, 0, { + err: err, + subject: subject + })); + } else { + var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs; + + _this.add(scheduler.schedule(dispatchNext, 0, { + value: value, + subject: subject + })); + } + }; + + try { + callbackFunc.apply(context, args.concat([handler])); + } catch (err) { + this.add(scheduler.schedule(dispatchError, 0, { + err: err, + subject: subject + })); + } + } + + this.add(subject.subscribe(subscriber)); + } + + 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); + } + + }); + unwrapExports(bindNodeCallback_1); + var bindNodeCallback_2 = bindNodeCallback_1.bindNodeCallback; + + var OuterSubscriber_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var OuterSubscriber = + /** @class */ + function (_super) { + __extends(OuterSubscriber, _super); + + function OuterSubscriber() { + return _super !== null && _super.apply(this, arguments) || this; + } + + 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_1.Subscriber); + + exports.OuterSubscriber = OuterSubscriber; + }); + unwrapExports(OuterSubscriber_1); + var OuterSubscriber_2 = OuterSubscriber_1.OuterSubscriber; + + var InnerSubscriber_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * We need this JSDoc comment for affecting ESDoc. + * @internal + * @ignore + * @extends {Ignored} + */ + + var InnerSubscriber = + /** @class */ + function (_super) { + __extends(InnerSubscriber, _super); + + function InnerSubscriber(parent, outerValue, outerIndex) { + var _this = _super.call(this) || this; + + _this.parent = parent; + _this.outerValue = outerValue; + _this.outerIndex = outerIndex; + _this.index = 0; + return _this; + } + + 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_1.Subscriber); + + exports.InnerSubscriber = InnerSubscriber; + }); + unwrapExports(InnerSubscriber_1); + var InnerSubscriber_2 = InnerSubscriber_1.InnerSubscriber; + + var subscribeToPromise$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + exports.subscribeToPromise = function (promise) { + return function (subscriber) { + promise.then(function (value) { + if (!subscriber.closed) { + subscriber.next(value); + subscriber.complete(); + } + }, function (err) { + return subscriber.error(err); + }).then(null, function (err) { + // Escaping the Promise trap: globally throw unhandled errors + setTimeout(function () { + throw err; + }); + }); + return subscriber; + }; + }; + + }); + unwrapExports(subscribeToPromise$1); + var subscribeToPromise_1 = subscribeToPromise$1.subscribeToPromise; + + var iterator$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function getSymbolIterator() { + if (typeof Symbol !== 'function' || !Symbol.iterator) { + return '@@iterator'; + } + + return Symbol.iterator; + } + + exports.getSymbolIterator = getSymbolIterator; + exports.iterator = getSymbolIterator(); + /** + * @deprecated use {@link iterator} instead + */ + + exports.$$iterator = exports.iterator; + }); + unwrapExports(iterator$1); + var iterator_1 = iterator$1.getSymbolIterator; + var iterator_2 = iterator$1.iterator; + var iterator_3 = iterator$1.$$iterator; + + var subscribeToIterable$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + exports.subscribeToIterable = function (iterable) { + return function (subscriber) { + var iterator = iterable[iterator$1.iterator](); + + do { + var item = iterator.next(); + + if (item.done) { + subscriber.complete(); + break; + } + + subscriber.next(item.value); + + if (subscriber.closed) { + break; + } + } while (true); // Finalize the iterator if it happens to be a Generator + + + if (typeof iterator.return === 'function') { + subscriber.add(function () { + if (iterator.return) { + iterator.return(); + } + }); + } + + return subscriber; + }; + }; + + }); + unwrapExports(subscribeToIterable$1); + var subscribeToIterable_1 = subscribeToIterable$1.subscribeToIterable; + + var subscribeToObservable$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Subscribes to an object that implements Symbol.observable with the given + * Subscriber. + * @param obj An object that implements Symbol.observable + * @param subscriber The Subscriber to use to subscribe to the observable + */ + + exports.subscribeToObservable = function (obj) { + return function (subscriber) { + var obs = obj[observable$1.observable](); + + if (typeof obs.subscribe !== 'function') { + // Should be caught by observable subscribe function error handling. + throw new TypeError('Provided object does not correctly implement Symbol.observable'); + } else { + return obs.subscribe(subscriber); + } + }; + }; + + }); + unwrapExports(subscribeToObservable$1); + var subscribeToObservable_1 = subscribeToObservable$1.subscribeToObservable; + + var isArrayLike$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + exports.isArrayLike = function (x) { + return x && typeof x.length === 'number'; + }; + + }); + unwrapExports(isArrayLike$1); + var isArrayLike_1 = isArrayLike$1.isArrayLike; + + var isPromise_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function isPromise(value) { + return value && typeof value.subscribe !== 'function' && typeof value.then === 'function'; + } + + exports.isPromise = isPromise; + }); + unwrapExports(isPromise_1); + var isPromise_2 = isPromise_1.isPromise; + + var subscribeTo$1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + exports.subscribeTo = function (result) { + if (result instanceof Observable_1.Observable) { + return function (subscriber) { + if (result._isScalar) { + subscriber.next(result.value); + subscriber.complete(); + return undefined; + } else { + return result.subscribe(subscriber); + } + }; + } else if (isArrayLike$1.isArrayLike(result)) { + return subscribeToArray$1.subscribeToArray(result); + } else if (isPromise_1.isPromise(result)) { + return subscribeToPromise$1.subscribeToPromise(result); + } else if (result && typeof result[iterator$1.iterator] === 'function') { + return subscribeToIterable$1.subscribeToIterable(result); + } else if (result && typeof result[observable$1.observable] === 'function') { + return subscribeToObservable$1.subscribeToObservable(result); + } else { + var value = isObject_1.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.'; + throw new TypeError(msg); + } + }; + + }); + unwrapExports(subscribeTo$1); + var subscribeTo_1 = subscribeTo$1.subscribeTo; + + var subscribeToResult_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) { + var destination = new InnerSubscriber_1.InnerSubscriber(outerSubscriber, outerValue, outerIndex); + return subscribeTo$1.subscribeTo(result)(destination); + } + + exports.subscribeToResult = subscribeToResult; + }); + unwrapExports(subscribeToResult_1); + var subscribeToResult_2 = subscribeToResult_1.subscribeToResult; + + var combineLatest_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + 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. + * + * 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. + * + * + * + * `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 Combine two timer Observables + * 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 Combine an array of Observables + * 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 Use project function to dynamically calculate the Body-Mass Index + * 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() { + var observables = []; + + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i] = arguments[_i]; + } + + var project = null; + var scheduler = null; + + if (isScheduler_1.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$1.isArray(observables[0])) { + observables = observables[0]; + } + + return fromArray_1.fromArray(observables, scheduler).lift(new CombineLatestOperator(project)); + } + + exports.combineLatest = combineLatest; + + var CombineLatestOperator = + /** @class */ + function () { + function CombineLatestOperator(project) { + this.project = project; + } + + CombineLatestOperator.prototype.call = function (subscriber, source) { + return source.subscribe(new CombineLatestSubscriber(subscriber, this.project)); + }; + + return CombineLatestOperator; + }(); + + exports.CombineLatestOperator = CombineLatestOperator; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var CombineLatestSubscriber = + /** @class */ + function (_super) { + __extends(CombineLatestSubscriber, _super); + + function CombineLatestSubscriber(destination, project) { + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.active = 0; + _this.values = []; + _this.observables = []; + return _this; + } + + 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_1.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_1.OuterSubscriber); + + exports.CombineLatestSubscriber = CombineLatestSubscriber; + }); + unwrapExports(combineLatest_1); + var combineLatest_2 = combineLatest_1.combineLatest; + var combineLatest_3 = combineLatest_1.CombineLatestOperator; + var combineLatest_4 = combineLatest_1.CombineLatestSubscriber; + + var isObservable_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** Identifies an input as being Observable (but not necessary an Rx Observable) */ + + function isObservable(input) { + return input && typeof input[observable$1.observable] === 'function'; + } + + exports.isObservable = isObservable; + }); + unwrapExports(isObservable_1); + var isObservable_2 = isObservable_1.isObservable; + + var isIterable_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** Identifies an input as being an Iterable */ + + function isIterable(input) { + return input && typeof input[iterator$1.iterator] === 'function'; + } + + exports.isIterable = isIterable; + }); + unwrapExports(isIterable_1); + var isIterable_2 = isIterable_1.isIterable; + + var fromPromise_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function fromPromise(input, scheduler) { + if (!scheduler) { + return new Observable_1.Observable(subscribeToPromise$1.subscribeToPromise(input)); + } else { + return new Observable_1.Observable(function (subscriber) { + var sub = new Subscription_1.Subscription(); + sub.add(scheduler.schedule(function () { + return input.then(function (value) { + sub.add(scheduler.schedule(function () { + subscriber.next(value); + sub.add(scheduler.schedule(function () { + return subscriber.complete(); + })); + })); + }, function (err) { + sub.add(scheduler.schedule(function () { + return subscriber.error(err); + })); + }); + })); + return sub; + }); + } + } + + exports.fromPromise = fromPromise; + }); + unwrapExports(fromPromise_1); + var fromPromise_2 = fromPromise_1.fromPromise; + + var fromIterable_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function fromIterable(input, scheduler) { + if (!input) { + throw new Error('Iterable cannot be null'); + } + + if (!scheduler) { + return new Observable_1.Observable(subscribeToIterable$1.subscribeToIterable(input)); + } else { + return new Observable_1.Observable(function (subscriber) { + var sub = new Subscription_1.Subscription(); + var iterator; + sub.add(function () { + // Finalize generators + if (iterator && typeof iterator.return === 'function') { + iterator.return(); + } + }); + sub.add(scheduler.schedule(function () { + iterator = input[iterator$1.iterator](); + sub.add(scheduler.schedule(function () { + if (subscriber.closed) { + return; + } + + var value; + var done; + + try { + var result = iterator.next(); + value = result.value; + done = result.done; + } catch (err) { + subscriber.error(err); + return; + } + + if (done) { + subscriber.complete(); + } else { + subscriber.next(value); + this.schedule(); + } + })); + })); + return sub; + }); + } + } + + exports.fromIterable = fromIterable; + }); + unwrapExports(fromIterable_1); + var fromIterable_2 = fromIterable_1.fromIterable; + + var fromObservable_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function fromObservable(input, scheduler) { + if (!scheduler) { + return new Observable_1.Observable(subscribeToObservable$1.subscribeToObservable(input)); + } else { + return new Observable_1.Observable(function (subscriber) { + var sub = new Subscription_1.Subscription(); + sub.add(scheduler.schedule(function () { + var observable = input[observable$1.observable](); + sub.add(observable.subscribe({ + next: function next(value) { + sub.add(scheduler.schedule(function () { + return subscriber.next(value); + })); + }, + error: function error(err) { + sub.add(scheduler.schedule(function () { + return subscriber.error(err); + })); + }, + complete: function complete() { + sub.add(scheduler.schedule(function () { + return subscriber.complete(); + })); + } + })); + })); + return sub; + }); + } + } + + exports.fromObservable = fromObservable; + }); + unwrapExports(fromObservable_1); + var fromObservable_2 = fromObservable_1.fromObservable; + + var from_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function from(input, scheduler) { + if (!scheduler) { + if (input instanceof Observable_1.Observable) { + return input; + } + + return new Observable_1.Observable(subscribeTo$1.subscribeTo(input)); + } + + if (input != null) { + if (isObservable_1.isObservable(input)) { + return fromObservable_1.fromObservable(input, scheduler); + } else if (isPromise_1.isPromise(input)) { + return fromPromise_1.fromPromise(input, scheduler); + } else if (isArrayLike$1.isArrayLike(input)) { + return fromArray_1.fromArray(input, scheduler); + } else if (isIterable_1.isIterable(input) || typeof input === 'string') { + return fromIterable_1.fromIterable(input, scheduler); + } + } + + throw new TypeError((input !== null && typeof input || input) + ' is not observable'); + } + + exports.from = from; + }); + unwrapExports(from_1); + var from_2 = from_1.from; + + var mergeMap_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:enable:max-line-length */ + + /** + * Projects each source value to an Observable which is merged in the output + * Observable. + * + * Maps each value to an Observable, then flattens all of + * these inner Observables using {@link mergeAll}. + * + * + * + * 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 Map and flatten each letter to an Observable ticking every 1 second + * 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 {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, concurrent) { + if (concurrent === void 0) { + concurrent = Number.POSITIVE_INFINITY; + } + + return function mergeMapOperatorFunction(source) { + return source.lift(new MergeMapOperator(project, concurrent)); + }; + } + + exports.mergeMap = mergeMap; + + var MergeMapOperator = + /** @class */ + function () { + function MergeMapOperator(project, concurrent) { + if (concurrent === void 0) { + concurrent = Number.POSITIVE_INFINITY; + } + + this.project = project; + this.concurrent = concurrent; + } + + MergeMapOperator.prototype.call = function (observer, source) { + return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent)); + }; + + return MergeMapOperator; + }(); + + exports.MergeMapOperator = MergeMapOperator; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var MergeMapSubscriber = + /** @class */ + function (_super) { + __extends(MergeMapSubscriber, _super); + + function MergeMapSubscriber(destination, project, concurrent) { + if (concurrent === void 0) { + concurrent = Number.POSITIVE_INFINITY; + } + + var _this = _super.call(this, destination) || this; + + _this.project = project; + _this.concurrent = concurrent; + _this.hasCompleted = false; + _this.buffer = []; + _this.active = 0; + _this.index = 0; + return _this; + } + + 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_1.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) { + this.destination.next(innerValue); + }; + + 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_1.OuterSubscriber); + + exports.MergeMapSubscriber = MergeMapSubscriber; + }); + unwrapExports(mergeMap_1); + var mergeMap_2 = mergeMap_1.mergeMap; + var mergeMap_3 = mergeMap_1.MergeMapOperator; + var mergeMap_4 = mergeMap_1.MergeMapSubscriber; + + var mergeAll_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Converts a higher-order Observable into a first-order Observable which + * concurrently delivers all values that are emitted on the inner Observables. + * + * Flattens an Observable-of-Observables. + * + * + * + * `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 Spawn a new interval Observable for each click event, and blend their outputs as one Observable + * 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 Count from 0 to 9 every second for each click, but only allow 2 concurrent timers + * 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_1.mergeMap(identity_1.identity, concurrent); + } + + exports.mergeAll = mergeAll; + }); + unwrapExports(mergeAll_1); + var mergeAll_2 = mergeAll_1.mergeAll; + + var concatAll_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Converts a higher-order Observable into a first-order Observable by + * concatenating the inner Observables in order. + * + * Flattens an Observable-of-Observables by putting one + * inner Observable after the other. + * + * + * + * 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 For each click event, tick every second from 0 to 3, with no concurrency + * 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.mergeAll(1); + } + + exports.concatAll = concatAll; + }); + unwrapExports(concatAll_1); + var concatAll_2 = concatAll_1.concatAll; + + var concat_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:enable:max-line-length */ + + /** + * Creates an output Observable which sequentially emits all values from given + * Observable and then moves on to the next. + * + * Concatenates multiple Observables together by + * sequentially emitting their values, one Observable after the other. + * + * + * + * `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 Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 + * 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 Concatenate an array of 3 Observables + * 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 Concatenate the same Observable to repeat it + * 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] = arguments[_i]; + } + + if (observables.length === 1 || observables.length === 2 && isScheduler_1.isScheduler(observables[1])) { + return from_1.from(observables[0]); + } + + return concatAll_1.concatAll()(of_1.of.apply(void 0, observables)); + } + + exports.concat = concat; + }); + unwrapExports(concat_1); + var concat_2 = concat_1.concat; + + var defer_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); // lol + + /** + * Creates an Observable that, on subscribe, calls an Observable factory to + * make an Observable for each new Observer. + * + * Creates the Observable lazily, that is, only when it + * is subscribed. + * + * + * + * + * `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 Subscribe to either an Observable of clicks or an Observable of interval, at random + * 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 + */ + + function defer(observableFactory) { + return new Observable_1.Observable(function (subscriber) { + var input; + + try { + input = observableFactory(); + } catch (err) { + subscriber.error(err); + return undefined; + } + + var source = input ? from_1.from(input) : empty_1.empty(); + return source.subscribe(subscriber); + }); + } + + exports.defer = defer; + }); + unwrapExports(defer_1); + var defer_2 = defer_1.defer; + + var forkJoin_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:enable:max-line-length */ + + /** + * Joins last values emitted by passed Observables. + * + * Wait for Observables to complete and then combine last values they emitted. + * + * + * + * `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 Use forkJoin with operator emitting immediately + * import { forkJoin, of } from 'rxjs/create'; + * + * const observable = forkJoin( + * of(1, 2, 3, 4), + * 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 Use forkJoin with operator emitting after some time + * import { forkJoin, interval } from 'rxjs/create'; + * import { take } from 'rxjs/operators'; + * + * const observable = forkJoin( + * interval(1000).pipe(take(3)), // emit 0, 1, 2 every second and complete + * interval(500).pipe(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 Use forkJoin with project function + * import { jorkJoin, interval } from 'rxjs/create'; + * import { take } from 'rxjs/operators'; + * + * const observable = forkJoin( + * interval(1000).pipe(take(3)), // emit 0, 1, 2 every second and complete + * interval(500).pipe(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 {...ObservableInput} 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 + */ + + function forkJoin() { + var sources = []; + + for (var _i = 0; _i < arguments.length; _i++) { + sources[_i] = arguments[_i]; + } // if the first and only other argument is an array + // assume it's been called with `forkJoin([obs1, obs2, obs3])` + + + if (sources.length === 1 && isArray$1.isArray(sources[0])) { + sources = sources[0]; + } + + if (sources.length === 0) { + return empty_1.EMPTY; + } + + return new Observable_1.Observable(function (subscriber) { + return new ForkJoinSubscriber(subscriber, sources); + }); + } + + exports.forkJoin = forkJoin; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var ForkJoinSubscriber = + /** @class */ + function (_super) { + __extends(ForkJoinSubscriber, _super); + + function ForkJoinSubscriber(destination, sources) { + var _this = _super.call(this, destination) || this; + + _this.sources = sources; + _this.completed = 0; + _this.haveValues = 0; + var len = sources.length; + _this.values = new Array(len); + + for (var i = 0; i < len; i++) { + var source = sources[i]; + var innerSubscription = subscribeToResult_1.subscribeToResult(_this, source, null, i); + + if (innerSubscription) { + _this.add(innerSubscription); + } + } + + return _this; + } + + 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 _a = this, + destination = _a.destination, + haveValues = _a.haveValues, + values = _a.values; + + var len = values.length; + + if (!innerSub._hasValue) { + destination.complete(); + return; + } + + this.completed++; + + if (this.completed !== len) { + return; + } + + if (haveValues === len) { + destination.next(values); + } + + destination.complete(); + }; + + return ForkJoinSubscriber; + }(OuterSubscriber_1.OuterSubscriber); + + }); + unwrapExports(forkJoin_1); + var forkJoin_2 = forkJoin_1.forkJoin; + + var fromEvent_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var toString = Object.prototype.toString; + /* tslint:enable:max-line-length */ + + /** + * Creates an Observable that emits events of a specific type coming from the + * given event target. + * + * Creates an Observable from DOM events, or Node.js + * EventEmitter events or others. + * + * + * + * `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 Emits clicks happening on the DOM document + * var clicks = 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 Use addEventListener with capture option + * var clicksInDocument = fromEvent(document, 'click', true); // note optional configuration parameter + * // which will be passed to addEventListener + * var clicksInDiv = 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 + * @return {Observable} + * @name fromEvent + */ + + function fromEvent(target, eventName, options) { + return new Observable_1.Observable(function (subscriber) { + function handler(e) { + if (arguments.length > 1) { + subscriber.next(Array.prototype.slice.call(arguments)); + } else { + subscriber.next(e); + } + } + + setupSubscription(target, eventName, handler, subscriber, options); + }); + } + + exports.fromEvent = fromEvent; + + function setupSubscription(sourceObj, eventName, handler, subscriber, options) { + var unsubscribe; + + if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { + for (var i = 0, len = sourceObj.length; i < len; i++) { + setupSubscription(sourceObj[i], eventName, handler, subscriber, options); + } + } else if (isEventTarget(sourceObj)) { + var source_1 = sourceObj; + sourceObj.addEventListener(eventName, handler, options); + + unsubscribe = function unsubscribe() { + return source_1.removeEventListener(eventName, handler, options); + }; + } else if (isJQueryStyleEventEmitter(sourceObj)) { + var source_2 = sourceObj; + sourceObj.on(eventName, handler); + + unsubscribe = function unsubscribe() { + return source_2.off(eventName, handler); + }; + } else if (isNodeStyleEventEmitter(sourceObj)) { + var source_3 = sourceObj; + sourceObj.addListener(eventName, handler); + + unsubscribe = function unsubscribe() { + return source_3.removeListener(eventName, handler); + }; + } else { + throw new TypeError('Invalid event target'); + } + + subscriber.add(unsubscribe); + } + + 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'; + } + + }); + unwrapExports(fromEvent_1); + var fromEvent_2 = fromEvent_1.fromEvent; + + var fromEventPattern_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Creates an Observable from an API based on addHandler/removeHandler + * functions. + * + * Converts any addHandler/removeHandler API to an + * Observable. + * + * + * + * Creates an Observable by using the `addHandler` and `removeHandler` + * functions to add and remove the handlers. The `addHandler` is + * called when the output Observable is subscribed, and `removeHandler` is + * called when the Subscription is unsubscribed. + * + * @example Emits clicks happening on the DOM document + * function addClickHandler(handler) { + * document.addEventListener('click', handler); + * } + * + * function removeClickHandler(handler) { + * document.removeEventListener('click', handler); + * } + * + * var clicks = 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. + * @return {Observable} + * @name fromEventPattern + */ + + function fromEventPattern(addHandler, removeHandler) { + return new Observable_1.Observable(function (subscriber) { + var handler = function handler(e) { + return subscriber.next(e); + }; + + var retValue; + + try { + retValue = addHandler(handler); + } catch (err) { + subscriber.error(err); + return undefined; + } + + if (!isFunction_1.isFunction(removeHandler)) { + return undefined; + } + + return function () { + return removeHandler(handler, retValue); + }; + }); + } + + exports.fromEventPattern = fromEventPattern; + }); + unwrapExports(fromEventPattern_1); + var fromEventPattern_2 = fromEventPattern_1.fromEventPattern; + + var generate_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function generate(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) { + var resultSelector; + var initialState; + + if (arguments.length == 1) { + var options = initialStateOrOptions; + initialState = options.initialState; + condition = options.condition; + iterate = options.iterate; + resultSelector = options.resultSelector || identity_1.identity; + scheduler = options.scheduler; + } else if (resultSelectorOrObservable === undefined || isScheduler_1.isScheduler(resultSelectorOrObservable)) { + initialState = initialStateOrOptions; + resultSelector = identity_1.identity; + scheduler = resultSelectorOrObservable; + } else { + initialState = initialStateOrOptions; + resultSelector = resultSelectorOrObservable; + } + + return new Observable_1.Observable(function (subscriber) { + var state = initialState; + + if (scheduler) { + return scheduler.schedule(dispatch, 0, { + subscriber: subscriber, + iterate: iterate, + condition: condition, + resultSelector: resultSelector, + state: state + }); + } + + do { + if (condition) { + var conditionResult = void 0; + + try { + conditionResult = condition(state); + } catch (err) { + subscriber.error(err); + return undefined; + } + + if (!conditionResult) { + subscriber.complete(); + break; + } + } + + var value = void 0; + + try { + value = resultSelector(state); + } catch (err) { + subscriber.error(err); + return undefined; + } + + subscriber.next(value); + + if (subscriber.closed) { + break; + } + + try { + state = iterate(state); + } catch (err) { + subscriber.error(err); + return undefined; + } + } while (true); + + return undefined; + }); + } + + exports.generate = generate; + + function dispatch(state) { + var subscriber = state.subscriber, + condition = state.condition; + + if (subscriber.closed) { + return undefined; + } + + if (state.needIterate) { + try { + state.state = state.iterate(state.state); + } catch (err) { + subscriber.error(err); + return undefined; + } + } else { + state.needIterate = true; + } + + if (condition) { + var conditionResult = void 0; + + try { + conditionResult = condition(state.state); + } catch (err) { + subscriber.error(err); + return undefined; + } + + if (!conditionResult) { + subscriber.complete(); + return undefined; + } + + if (subscriber.closed) { + return undefined; + } + } + + var value; + + try { + value = state.resultSelector(state.state); + } catch (err) { + subscriber.error(err); + return undefined; + } + + if (subscriber.closed) { + return undefined; + } + + subscriber.next(value); + + if (subscriber.closed) { + return undefined; + } + + return this.schedule(state); + } + + }); + unwrapExports(generate_1); + var generate_2 = generate_1.generate; + + var iif_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Decides at subscription time which Observable will actually be subscribed. + * + * `If` statement for Observables. + * + * `if` accepts a condition function and two Observables. When + * an Observable returned by the operator is subscribed, condition function will be called. + * Based on what boolean it returns at that moment, consumer will subscribe either to + * the first Observable (if condition was true) or to the second (if condition was false). Condition + * function may also not return anything - in that case condition will be evaluated as false and + * second Observable will be subscribed. + * + * Note that Observables for both cases (true and false) are optional. If condition points to an Observable that + * was left undefined, resulting stream will simply complete immediately. That allows you to, rather + * then controlling which Observable will be subscribed, decide at runtime if consumer should have access + * to given Observable or not. + * + * If you have more complex logic that requires decision between more than two Observables, {@link defer} + * will probably be a better choice. Actually `if` can be easily implemented with {@link defer} + * and exists only for convenience and readability reasons. + * + * + * @example Change at runtime which Observable will be subscribed + * let subscribeToFirst; + * const firstOrSecond = Rx.Observable.if( + * () => subscribeToFirst, + * Rx.Observable.of('first'), + * Rx.Observable.of('second') + * ); + * + * subscribeToFirst = true; + * firstOrSecond.subscribe(value => console.log(value)); + * + * // Logs: + * // "first" + * + * subscribeToFirst = false; + * firstOrSecond.subscribe(value => console.log(value)); + * + * // Logs: + * // "second" + * + * + * @example Control an access to an Observable + * let accessGranted; + * const observableIfYouHaveAccess = Rx.Observable.if( + * () => accessGranted, + * Rx.Observable.of('It seems you have an access...') // Note that only one Observable is passed to the operator. + * ); + * + * accessGranted = true; + * observableIfYouHaveAccess.subscribe( + * value => console.log(value), + * err => {}, + * () => console.log('The end') + * ); + * + * // Logs: + * // "It seems you have an access..." + * // "The end" + * + * accessGranted = false; + * observableIfYouHaveAccess.subscribe( + * value => console.log(value), + * err => {}, + * () => console.log('The end') + * ); + * + * // Logs: + * // "The end" + * + * @see {@link defer} + * + * @param {function(): boolean} condition Condition which Observable should be chosen. + * @param {Observable} [trueObservable] An Observable that will be subscribed if condition is true. + * @param {Observable} [falseObservable] An Observable that will be subscribed if condition is false. + * @return {Observable} Either first or second Observable, depending on condition. + * @static true + * @name iif + * @owner Observable + */ + + function iif(condition, trueResult, falseResult) { + if (trueResult === void 0) { + trueResult = empty_1.EMPTY; + } + + if (falseResult === void 0) { + falseResult = empty_1.EMPTY; + } + + return defer_1.defer(function () { + return condition() ? trueResult : falseResult; + }); + } + + exports.iif = iif; + }); + unwrapExports(iif_1); + var iif_2 = iif_1.iif; + + var isNumeric_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + 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$1.isArray(val) && val - parseFloat(val) + 1 >= 0; + } + + exports.isNumeric = isNumeric; + }); + unwrapExports(isNumeric_1); + var isNumeric_2 = isNumeric_1.isNumeric; + + var interval_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Creates an Observable that emits sequential numbers every specified + * interval of time, on a specified IScheduler. + * + * Emits incremental numbers periodically in time. + * + * + * + * + * `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 Emits ascending numbers, one every second (1000ms) + * 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 + */ + + function interval(period, scheduler) { + if (period === void 0) { + period = 0; + } + + if (scheduler === void 0) { + scheduler = async$1.async; + } + + if (!isNumeric_1.isNumeric(period) || period < 0) { + period = 0; + } + + if (!scheduler || typeof scheduler.schedule !== 'function') { + scheduler = async$1.async; + } + + return new Observable_1.Observable(function (subscriber) { + subscriber.add(scheduler.schedule(dispatch, period, { + subscriber: subscriber, + counter: 0, + period: period + })); + return subscriber; + }); + } + + exports.interval = interval; + + function dispatch(state) { + var subscriber = state.subscriber, + counter = state.counter, + period = state.period; + subscriber.next(counter); + this.schedule({ + subscriber: subscriber, + counter: counter + 1, + period: period + }, period); + } + + }); + unwrapExports(interval_1); + var interval_2 = interval_1.interval; + + var merge_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* tslint:enable:max-line-length */ + + /** + * Creates an output Observable which concurrently emits all values from every + * given input Observable. + * + * Flattens multiple Observables together by blending + * their values into one Observable. + * + * + * + * `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 Merge together two Observables: 1s interval and clicks + * 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 Merge together 3 Observables, but only 2 run concurrently + * 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] = arguments[_i]; + } + + var concurrent = Number.POSITIVE_INFINITY; + var scheduler = null; + var last = observables[observables.length - 1]; + + if (isScheduler_1.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_1.Observable) { + return observables[0]; + } + + return mergeAll_1.mergeAll(concurrent)(fromArray_1.fromArray(observables, scheduler)); + } + + exports.merge = merge; + }); + unwrapExports(merge_1); + var merge_2 = merge_1.merge; + + var onErrorResumeNext_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* 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. + * + * Execute series of Observables no matter what, even if it means swallowing errors. + * + * + * + * `onErrorResumeNext` Will subscribe to each observable source it is provided, in order. + * If the source it's subscribed to emits an error or completes, it will move to the next source + * without error. + * + * If `onErrorResumeNext` is provided no arguments, or a single, empty array, it will return {@link EMPTY}. + * + * `onErrorResumeNext` is basically {@link concat}, only it will continue, even if one of its + * sources emits an error. + * + * Note that there is no way to handle any errors thrown by sources via the resuult of + * `onErrorResumeNext`. If you want to handle errors thrown in any given source, you can + * always use the {@link catchError} operator on them before passing them into `onErrorResumeNext`. + * + * @example Subscribe to the next Observable after map fails + * import { onErrorResumeNext, of } from 'rxjs/create'; + * import { map } from 'rxjs/operators'; + * + * onErrorResumeNext( + * of(1, 2, 3, 0).pipe( + * map(x => { + * if (x === 0) throw Error(); + * return 10 / x; + * }) + * ), + * of(1, 2, 3), + * ) + * .subscribe( + * val => console.log(val), + * err => console.log(err), // Will never be called. + * () => console.log('done') + * ); + * + * // Logs: + * // 10 + * // 5 + * // 3.3333333333333335 + * // 1 + * // 2 + * // 3 + * // "done" + * + * @see {@link concat} + * @see {@link catch} + * + * @param {...ObservableInput} sources Observables (or anything that *is* observable) passed either directly or as an array. + * @return {Observable} An Observable that concatenates all sources, one after the other, + * ignoring all errors, such that any error causes it to move on to the next source. + */ + + function onErrorResumeNext() { + var sources = []; + + for (var _i = 0; _i < arguments.length; _i++) { + sources[_i] = arguments[_i]; + } + + if (sources.length === 0) { + return empty_1.EMPTY; + } + + var first = sources[0], + remainder = sources.slice(1); + + if (sources.length === 1 && isArray$1.isArray(first)) { + return onErrorResumeNext.apply(void 0, first); + } + + return new Observable_1.Observable(function (subscriber) { + var subNext = function subNext() { + return subscriber.add(onErrorResumeNext.apply(void 0, remainder).subscribe(subscriber)); + }; + + return from_1.from(first).subscribe({ + next: function next(value) { + subscriber.next(value); + }, + error: subNext, + complete: subNext + }); + }); + } + + exports.onErrorResumeNext = onErrorResumeNext; + }); + unwrapExports(onErrorResumeNext_1); + var onErrorResumeNext_2 = onErrorResumeNext_1.onErrorResumeNext; + + var pairs_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Convert an object into an observable sequence of [key, value] pairs + * using an optional IScheduler to enumerate the object. + * + * @example Converts a javascript object to an Observable + * 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<[string, T]>)} An observable sequence of + * [key, value] pairs from the object. + */ + + function pairs(obj, scheduler) { + if (!scheduler) { + return new Observable_1.Observable(function (subscriber) { + var keys = Object.keys(obj); + + for (var i = 0; i < keys.length && !subscriber.closed; i++) { + var key = keys[i]; + + if (obj.hasOwnProperty(key)) { + subscriber.next([key, obj[key]]); + } + } + + subscriber.complete(); + }); + } else { + return new Observable_1.Observable(function (subscriber) { + var keys = Object.keys(obj); + var subscription = new Subscription_1.Subscription(); + subscription.add(scheduler.schedule(dispatch, 0, { + keys: keys, + index: 0, + subscriber: subscriber, + subscription: subscription, + obj: obj + })); + return subscription; + }); + } + } + + exports.pairs = pairs; + /** @internal */ + + function dispatch(state) { + var keys = state.keys, + index = state.index, + subscriber = state.subscriber, + subscription = state.subscription, + obj = state.obj; + + if (!subscriber.closed) { + if (index < keys.length) { + var key = keys[index]; + subscriber.next([key, obj[key]]); + subscription.add(this.schedule({ + keys: keys, + index: index + 1, + subscriber: subscriber, + subscription: subscription, + obj: obj + })); + } else { + subscriber.complete(); + } + } + } + + exports.dispatch = dispatch; + }); + unwrapExports(pairs_1); + var pairs_2 = pairs_1.pairs; + var pairs_3 = pairs_1.dispatch; + + var race_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function race() { + var observables = []; + + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i] = arguments[_i]; + } // if the only argument is an array, it was most likely called with + // `race([obs1, obs2, ...])` + + + if (observables.length === 1) { + if (isArray$1.isArray(observables[0])) { + observables = observables[0]; + } else { + return observables[0]; + } + } + + return fromArray_1.fromArray(observables, undefined).lift(new RaceOperator()); + } + + exports.race = race; + + var RaceOperator = + /** @class */ + function () { + function RaceOperator() {} + + RaceOperator.prototype.call = function (subscriber, source) { + return source.subscribe(new RaceSubscriber(subscriber)); + }; + + return RaceOperator; + }(); + + exports.RaceOperator = RaceOperator; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var RaceSubscriber = + /** @class */ + function (_super) { + __extends(RaceSubscriber, _super); + + function RaceSubscriber(destination) { + var _this = _super.call(this, destination) || this; + + _this.hasFirst = false; + _this.observables = []; + _this.subscriptions = []; + return _this; + } + + 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_1.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_1.OuterSubscriber); + + exports.RaceSubscriber = RaceSubscriber; + }); + unwrapExports(race_1); + var race_2 = race_1.race; + var race_3 = race_1.RaceOperator; + var race_4 = race_1.RaceSubscriber; + + var range_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Creates an Observable that emits a sequence of numbers within a specified + * range. + * + * Emits a sequence of numbers in a range. + * + * + * + * `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 Emits the numbers 1 to 10 + * 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 + */ + + function range(start, count, scheduler) { + if (start === void 0) { + start = 0; + } + + if (count === void 0) { + count = 0; + } + + return new Observable_1.Observable(function (subscriber) { + var index = 0; + + if (scheduler) { + return scheduler.schedule(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 undefined; + }); + } + + exports.range = range; + /** @internal */ + + function dispatch(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); + } + + exports.dispatch = dispatch; + }); + unwrapExports(range_1); + var range_2 = range_1.range; + var range_3 = range_1.dispatch; + + var timer_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Creates an Observable that starts emitting after an `initialDelay` and + * emits ever increasing numbers after each `period` of time thereafter. + * + * Its like {@link interval}, but you can specify when + * should the emissions start. + * + * + * + * `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 Emits ascending numbers, one every second (1000ms), starting after 3 seconds + * var numbers = Rx.Observable.timer(3000, 1000); + * numbers.subscribe(x => console.log(x)); + * + * @example Emits one number after five seconds + * var numbers = Rx.Observable.timer(5000); + * numbers.subscribe(x => console.log(x)); + * + * @see {@link interval} + * @see {@link delay} + * + * @param {number|Date} [dueTime] The initial delay time to wait before + * emitting the first value of `0`. + * @param {number|SchedulerLike} [periodOrScheduler] The period of time between emissions of the + * subsequent numbers. + * @param {SchedulerLike} [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 + */ + + function timer(dueTime, periodOrScheduler, scheduler) { + if (dueTime === void 0) { + dueTime = 0; + } + + var period = -1; + + if (isNumeric_1.isNumeric(periodOrScheduler)) { + period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler); + } else if (isScheduler_1.isScheduler(periodOrScheduler)) { + scheduler = periodOrScheduler; + } + + if (!isScheduler_1.isScheduler(scheduler)) { + scheduler = async$1.async; + } + + return new Observable_1.Observable(function (subscriber) { + var due = isNumeric_1.isNumeric(dueTime) ? dueTime : +dueTime - scheduler.now(); + return scheduler.schedule(dispatch, due, { + index: 0, + period: period, + subscriber: subscriber + }); + }); + } + + exports.timer = timer; + + function dispatch(state) { + var index = state.index, + period = state.period, + subscriber = state.subscriber; + subscriber.next(index); + + if (subscriber.closed) { + return; + } else if (period === -1) { + return subscriber.complete(); + } + + state.index = index + 1; + this.schedule(state, period); + } + + }); + unwrapExports(timer_1); + var timer_2 = timer_1.timer; + + var using_1 = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); // from from from! LAWL + + /** + * Creates an Observable that uses a resource which will be disposed at the same time as the Observable. + * + * Use it when you catch yourself cleaning up after an Observable. + * + * `using` is a factory operator, which accepts two functions. First function returns a disposable resource. + * It can be an arbitrary object that implements `unsubscribe` method. Second function will be injected with + * that object and should return an Observable. That Observable can use resource object during its execution. + * Both functions passed to `using` will be called every time someone subscribes - neither an Observable nor + * resource object will be shared in any way between subscriptions. + * + * When Observable returned by `using` is subscribed, Observable returned from the second function will be subscribed + * as well. All its notifications (nexted values, completion and error events) will be emitted unchanged by the output + * Observable. If however someone unsubscribes from the Observable or source Observable completes or errors by itself, + * the `unsubscribe` method on resource object will be called. This can be used to do any necessary clean up, which + * otherwise would have to be handled by hand. Note that complete or error notifications are not emitted when someone + * cancels subscription to an Observable via `unsubscribe`, so `using` can be used as a hook, allowing you to make + * sure that all resources which need to exist during an Observable execution will be disposed at appropriate time. + * + * @see {@link defer} + * + * @param {function(): ISubscription} resourceFactory A function which creates any resource object + * that implements `unsubscribe` method. + * @param {function(resource: ISubscription): Observable} observableFactory A function which + * creates an Observable, that can use injected resource object. + * @return {Observable} An Observable that behaves the same as Observable returned by `observableFactory`, but + * which - when completed, errored or unsubscribed - will also call `unsubscribe` on created resource object. + */ + + function using(resourceFactory, observableFactory) { + return new Observable_1.Observable(function (subscriber) { + var resource; + + try { + resource = resourceFactory(); + } catch (err) { + subscriber.error(err); + return undefined; + } + + var result; + + try { + result = observableFactory(resource); + } catch (err) { + subscriber.error(err); + return undefined; + } + + var source = result ? from_1.from(result) : empty_1.EMPTY; + var subscription = source.subscribe(subscriber); + return function () { + subscription.unsubscribe(); + + if (resource) { + resource.unsubscribe(); + } + }; + }); + } + + exports.using = using; + }); + unwrapExports(using_1); + var using_2 = using_1.using; + + var zip_1 = createCommonjsModule(function (module, exports) { + + var __extends = commonjsGlobal && commonjsGlobal.__extends || function () { + 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]; + } + }; + + return function (d, b) { + extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + }(); + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* 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 Combine age and name from different sources + * + * let age$ = Observable.of(27, 25, 29); + * let name$ = Observable.of('Foo', 'Bar', 'Beer'); + * let isDev$ = Observable.of(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} + * @static true + * @name zip + * @owner Observable + */ + + function zip() { + var observables = []; + + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i] = arguments[_i]; + } + + var project = observables[observables.length - 1]; + + if (typeof project === 'function') { + observables.pop(); + } + + return fromArray_1.fromArray(observables, undefined).lift(new ZipOperator(project)); + } + + exports.zip = zip; + + var ZipOperator = + /** @class */ + function () { + function ZipOperator(project) { + this.project = project; + } + + ZipOperator.prototype.call = function (subscriber, source) { + return source.subscribe(new ZipSubscriber(subscriber, this.project)); + }; + + return ZipOperator; + }(); + + exports.ZipOperator = ZipOperator; + /** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ + + var ZipSubscriber = + /** @class */ + function (_super) { + __extends(ZipSubscriber, _super); + + function ZipSubscriber(destination, project, values) { + if (values === void 0) { + values = Object.create(null); + } + + var _this = _super.call(this, destination) || this; + + _this.iterators = []; + _this.active = 0; + _this.project = typeof project === 'function' ? project : null; + _this.values = values; + return _this; + } + + ZipSubscriber.prototype._next = function (value) { + var iterators = this.iterators; + + if (isArray$1.isArray(value)) { + iterators.push(new StaticArrayIterator(value)); + } else if (typeof value[iterator$1.iterator] === 'function') { + iterators.push(new StaticIterator(value[iterator$1.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 = iterators[i]; + + if (iterator.stillUnsubscribed) { + this.add(iterator.subscribe(iterator, 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 = iterators[i]; + + if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) { + return; + } + } + + var shouldComplete = false; + var args = []; + + for (var i = 0; i < len; i++) { + var iterator = iterators[i]; + var result = iterator.next(); // check to see if it's completed now that you've gotten + // the next value. + + if (iterator.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_1.Subscriber); + + exports.ZipSubscriber = ZipSubscriber; + + var StaticIterator = + /** @class */ + function () { + function StaticIterator(iterator) { + this.iterator = iterator; + this.nextResult = iterator.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 = + /** @class */ + function () { + function StaticArrayIterator(array) { + this.array = array; + this.index = 0; + this.length = 0; + this.length = array.length; + } + + StaticArrayIterator.prototype[iterator$1.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 = + /** @class */ + function (_super) { + __extends(ZipBufferIterator, _super); + + function ZipBufferIterator(destination, parent, observable) { + var _this = _super.call(this, destination) || this; + + _this.parent = parent; + _this.observable = observable; + _this.stillUnsubscribed = true; + _this.buffer = []; + _this.isComplete = false; + return _this; + } + + ZipBufferIterator.prototype[iterator$1.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_1.subscribeToResult(this, this.observable, this, index); + }; + + return ZipBufferIterator; + }(OuterSubscriber_1.OuterSubscriber); + + }); + unwrapExports(zip_1); + var zip_2 = zip_1.zip; + var zip_3 = zip_1.ZipOperator; + var zip_4 = zip_1.ZipSubscriber; + + var never = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * An Observable that emits no items to the Observer and never completes. + * + * + * + * 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 Emit the number 7, then never emit anything else (not even complete). + * function info() { + * console.log('Will not be called'); + * } + * var result = NEVER.startWith(7); + * result.subscribe(x => console.log(x), info, info); + * + * @see {@link create} + * @see {@link EMPTY} + * @see {@link of} + * @see {@link throwError} + */ + + exports.NEVER = new Observable_1.Observable(noop_1.noop); + }); + unwrapExports(never); + var never_1 = never.NEVER; + + var rxjs = createCommonjsModule(function (module, exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /* Observable */ + + exports.Observable = Observable_1.Observable; + exports.ConnectableObservable = ConnectableObservable_1.ConnectableObservable; + exports.observable = observable$1.observable; + /* Subjects */ + + exports.Subject = Subject_1.Subject; + exports.BehaviorSubject = BehaviorSubject_1.BehaviorSubject; + exports.ReplaySubject = ReplaySubject_1.ReplaySubject; + exports.AsyncSubject = AsyncSubject_1.AsyncSubject; + /* Schedulers */ + + exports.asapScheduler = asap.asap; + exports.asyncScheduler = async$1.async; + exports.queueScheduler = queue$2.queue; + exports.animationFrameScheduler = animationFrame.animationFrame; + exports.VirtualTimeScheduler = VirtualTimeScheduler_1.VirtualTimeScheduler; + exports.VirtualAction = VirtualTimeScheduler_1.VirtualAction; + /* Subscription */ + + exports.Subscription = Subscription_1.Subscription; + exports.Subscriber = Subscriber_1.Subscriber; + /* Notification */ + + exports.Notification = Notification_1.Notification; + /* Utils */ + + exports.pipe = pipe_1.pipe; + exports.noop = noop_1.noop; + exports.identity = identity_1.identity; + /* Error types */ + + exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; + exports.EmptyError = EmptyError_1.EmptyError; + exports.ObjectUnsubscribedError = ObjectUnsubscribedError_1.ObjectUnsubscribedError; + exports.UnsubscriptionError = UnsubscriptionError_1.UnsubscriptionError; + exports.TimeoutError = TimeoutError_1.TimeoutError; + /* Static observable creation exports */ + + exports.bindCallback = bindCallback_1.bindCallback; + exports.bindNodeCallback = bindNodeCallback_1.bindNodeCallback; + exports.combineLatest = combineLatest_1.combineLatest; + exports.concat = concat_1.concat; + exports.defer = defer_1.defer; + exports.empty = empty_1.empty; + exports.forkJoin = forkJoin_1.forkJoin; + exports.from = from_1.from; + exports.fromEvent = fromEvent_1.fromEvent; + exports.fromEventPattern = fromEventPattern_1.fromEventPattern; + exports.generate = generate_1.generate; + exports.iif = iif_1.iif; + exports.interval = interval_1.interval; + exports.merge = merge_1.merge; + exports.of = of_1.of; + exports.onErrorResumeNext = onErrorResumeNext_1.onErrorResumeNext; + exports.pairs = pairs_1.pairs; + exports.race = race_1.race; + exports.range = range_1.range; + exports.throwError = throwError_1.throwError; + exports.timer = timer_1.timer; + exports.using = using_1.using; + exports.zip = zip_1.zip; + /* Constants */ + + var empty_2 = empty_1; + exports.EMPTY = empty_2.EMPTY; + exports.NEVER = never.NEVER; + }); + unwrapExports(rxjs); + var rxjs_1 = rxjs.Observable; + var rxjs_2 = rxjs.ConnectableObservable; + var rxjs_3 = rxjs.observable; + var rxjs_4 = rxjs.Subject; + var rxjs_5 = rxjs.BehaviorSubject; + var rxjs_6 = rxjs.ReplaySubject; + var rxjs_7 = rxjs.AsyncSubject; + var rxjs_8 = rxjs.asapScheduler; + var rxjs_9 = rxjs.asyncScheduler; + var rxjs_10 = rxjs.queueScheduler; + var rxjs_11 = rxjs.animationFrameScheduler; + var rxjs_12 = rxjs.VirtualTimeScheduler; + var rxjs_13 = rxjs.VirtualAction; + var rxjs_14 = rxjs.Subscription; + var rxjs_15 = rxjs.Subscriber; + var rxjs_16 = rxjs.Notification; + var rxjs_17 = rxjs.pipe; + var rxjs_18 = rxjs.noop; + var rxjs_19 = rxjs.identity; + var rxjs_20 = rxjs.ArgumentOutOfRangeError; + var rxjs_21 = rxjs.EmptyError; + var rxjs_22 = rxjs.ObjectUnsubscribedError; + var rxjs_23 = rxjs.UnsubscriptionError; + var rxjs_24 = rxjs.TimeoutError; + var rxjs_25 = rxjs.bindCallback; + var rxjs_26 = rxjs.bindNodeCallback; + var rxjs_27 = rxjs.combineLatest; + var rxjs_28 = rxjs.concat; + var rxjs_29 = rxjs.defer; + var rxjs_30 = rxjs.empty; + var rxjs_31 = rxjs.forkJoin; + var rxjs_32 = rxjs.from; + var rxjs_33 = rxjs.fromEvent; + var rxjs_34 = rxjs.fromEventPattern; + var rxjs_35 = rxjs.generate; + var rxjs_36 = rxjs.iif; + var rxjs_37 = rxjs.interval; + var rxjs_38 = rxjs.merge; + var rxjs_39 = rxjs.of; + var rxjs_40 = rxjs.onErrorResumeNext; + var rxjs_41 = rxjs.pairs; + var rxjs_42 = rxjs.race; + var rxjs_43 = rxjs.range; + var rxjs_44 = rxjs.throwError; + var rxjs_45 = rxjs.timer; + var rxjs_46 = rxjs.using; + var rxjs_47 = rxjs.zip; + var rxjs_48 = rxjs.EMPTY; + var rxjs_49 = rxjs.NEVER; + + var arraySlice = [].slice; + var factories = {}; + + var construct = function (F, len, args) { + if (!(len in factories)) { + for (var n = [], i = 0; i < len; i++) n[i] = 'a[' + i + ']'; + // eslint-disable-next-line no-new-func + factories[len] = Function('F,a', 'return new F(' + n.join(',') + ')'); + } return factories[len](F, args); + }; + + var _bind = Function.bind || function bind(that /* , ...args */) { + var fn = _aFunction(this); + var partArgs = arraySlice.call(arguments, 1); + var bound = function (/* args... */) { + var args = partArgs.concat(arraySlice.call(arguments)); + return this instanceof bound ? construct(fn, args.length, args) : _invoke(fn, args, that); + }; + if (_isObject(fn.prototype)) bound.prototype = fn.prototype; + return bound; + }; + + // 26.1.2 Reflect.construct(target, argumentsList [, newTarget]) + + + + + + + + var rConstruct = (_global.Reflect || {}).construct; + + // MS Edge supports only 2 arguments and argumentsList argument is optional + // FF Nightly sets third argument as `new.target`, but does not create `this` from it + var NEW_TARGET_BUG = _fails(function () { + function F() { /* empty */ } + return !(rConstruct(function () { /* empty */ }, [], F) instanceof F); + }); + var ARGS_BUG = !_fails(function () { + rConstruct(function () { /* empty */ }); + }); + + _export(_export.S + _export.F * (NEW_TARGET_BUG || ARGS_BUG), 'Reflect', { + construct: function construct(Target, args /* , newTarget */) { + _aFunction(Target); + _anObject(args); + var newTarget = arguments.length < 3 ? Target : _aFunction(arguments[2]); + if (ARGS_BUG && !NEW_TARGET_BUG) return rConstruct(Target, args, newTarget); + if (Target == newTarget) { + // w/o altered newTarget, optimization for 0-4 arguments + switch (args.length) { + case 0: return new Target(); + case 1: return new Target(args[0]); + case 2: return new Target(args[0], args[1]); + case 3: return new Target(args[0], args[1], args[2]); + case 4: return new Target(args[0], args[1], args[2], args[3]); + } + // w/o altered newTarget, lot of arguments case + var $args = [null]; + $args.push.apply($args, args); + return new (_bind.apply(Target, $args))(); + } + // with altered newTarget, not support built-in constructors + var proto = newTarget.prototype; + var instance = _objectCreate(_isObject(proto) ? proto : Object.prototype); + var result = Function.apply.call(Target, instance, args); + return _isObject(result) ? result : instance; + } + }); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + _setPrototypeOf(subClass.prototype, superClass && superClass.prototype); + + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { + return o.__proto__; + }; + + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); + } + + function _superPropBase(object, property) { + while (!Object.prototype.hasOwnProperty.call(object, property)) { + object = _getPrototypeOf(object); + if (object === null) break; + } + + return object; + } + + function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + + if (desc.get) { + return desc.get.call(receiver); + } + + return desc.value; + }; + } + + return _get(target, property, receiver || target); + } + + var dP$3 = _objectDp.f; + var FProto = Function.prototype; + var nameRE = /^\s*function ([^ (]*)/; + var NAME$1 = 'name'; + + // 19.2.4.2 name + NAME$1 in FProto || _descriptors && dP$3(FProto, NAME$1, { + configurable: true, + get: function () { + try { + return ('' + this).match(nameRE)[1]; + } catch (e) { + return ''; + } + } + }); + + var _fixReWks = function (KEY, length, exec) { + var SYMBOL = _wks(KEY); + var fns = exec(_defined, SYMBOL, ''[KEY]); + var strfn = fns[0]; + var rxfn = fns[1]; + if (_fails(function () { + var O = {}; + O[SYMBOL] = function () { return 7; }; + return ''[KEY](O) != 7; + })) { + _redefine(String.prototype, KEY, strfn); + _hide(RegExp.prototype, SYMBOL, length == 2 + // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) + // 21.2.5.11 RegExp.prototype[@@split](string, limit) + ? function (string, arg) { return rxfn.call(string, this, arg); } + // 21.2.5.6 RegExp.prototype[@@match](string) + // 21.2.5.9 RegExp.prototype[@@search](string) + : function (string) { return rxfn.call(string, this); } + ); + } + }; + + // 7.2.8 IsRegExp(argument) + + + var MATCH = _wks('match'); + var _isRegexp = function (it) { + var isRegExp; + return _isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : _cof(it) == 'RegExp'); + }; + + // @@split logic + _fixReWks('split', 2, function (defined, SPLIT, $split) { + var isRegExp = _isRegexp; + var _split = $split; + var $push = [].push; + var $SPLIT = 'split'; + var LENGTH = 'length'; + var LAST_INDEX = 'lastIndex'; + if ( + 'abbc'[$SPLIT](/(b)*/)[1] == 'c' || + 'test'[$SPLIT](/(?:)/, -1)[LENGTH] != 4 || + 'ab'[$SPLIT](/(?:ab)*/)[LENGTH] != 2 || + '.'[$SPLIT](/(.?)(.?)/)[LENGTH] != 4 || + '.'[$SPLIT](/()()/)[LENGTH] > 1 || + ''[$SPLIT](/.?/)[LENGTH] + ) { + var NPCG = /()??/.exec('')[1] === undefined; // nonparticipating capturing group + // based on es5-shim implementation, need to rework it + $split = function (separator, limit) { + var string = String(this); + if (separator === undefined && limit === 0) return []; + // If `separator` is not a regex, use native split + if (!isRegExp(separator)) return _split.call(string, separator, limit); + var output = []; + var flags = (separator.ignoreCase ? 'i' : '') + + (separator.multiline ? 'm' : '') + + (separator.unicode ? 'u' : '') + + (separator.sticky ? 'y' : ''); + var lastLastIndex = 0; + var splitLimit = limit === undefined ? 4294967295 : limit >>> 0; + // Make `global` and avoid `lastIndex` issues by working with a copy + var separatorCopy = new RegExp(separator.source, flags + 'g'); + var separator2, match, lastIndex, lastLength, i; + // Doesn't need flags gy, but they don't hurt + if (!NPCG) separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags); + while (match = separatorCopy.exec(string)) { + // `separatorCopy.lastIndex` is not reliable cross-browser + lastIndex = match.index + match[0][LENGTH]; + if (lastIndex > lastLastIndex) { + output.push(string.slice(lastLastIndex, match.index)); + // Fix browsers whose `exec` methods don't consistently return `undefined` for NPCG + // eslint-disable-next-line no-loop-func + if (!NPCG && match[LENGTH] > 1) match[0].replace(separator2, function () { + for (i = 1; i < arguments[LENGTH] - 2; i++) if (arguments[i] === undefined) match[i] = undefined; + }); + if (match[LENGTH] > 1 && match.index < string[LENGTH]) $push.apply(output, match.slice(1)); + lastLength = match[0][LENGTH]; + lastLastIndex = lastIndex; + if (output[LENGTH] >= splitLimit) break; + } + if (separatorCopy[LAST_INDEX] === match.index) separatorCopy[LAST_INDEX]++; // Avoid an infinite loop + } + if (lastLastIndex === string[LENGTH]) { + if (lastLength || !separatorCopy.test('')) output.push(''); + } else output.push(string.slice(lastLastIndex)); + return output[LENGTH] > splitLimit ? output.slice(0, splitLimit) : output; + }; + // Chakra, V8 + } else if ('0'[$SPLIT](undefined, 0)[LENGTH]) { + $split = function (separator, limit) { + return separator === undefined && limit === 0 ? [] : _split.call(this, separator, limit); + }; + } + // 21.1.3.17 String.prototype.split(separator, limit) + return [function split(separator, limit) { + var O = defined(this); + var fn = separator == undefined ? undefined : separator[SPLIT]; + return fn !== undefined ? fn.call(separator, O, limit) : $split.call(String(O), separator, limit); + }, $split]; + }); + + /** + * @license + * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at + * http://polymer.github.io/LICENSE.txt + * The complete set of authors may be found at + * http://polymer.github.io/AUTHORS.txt + * The complete set of contributors may be found at + * http://polymer.github.io/CONTRIBUTORS.txt + * Code distributed by Google as part of the polymer project is also + * subject to an additional IP rights grant found at + * http://polymer.github.io/PATENTS.txt + */ + // The first argument to JS template tags retain identity across multiple + // calls to a tag for the same literal, so we can cache work done per literal + // in a Map. + var templateCaches = new Map(); + /** + * Interprets a template literal as an HTML template that can efficiently + * render to and update a container. + */ + + var html = function html(strings) { + for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + values[_key - 1] = arguments[_key]; + } + + return new TemplateResult(strings, values, 'html'); + }; + /** + * The return type of `html`, which holds a Template and the values from + * interpolated expressions. + */ + + var TemplateResult = + /*#__PURE__*/ + function () { + function TemplateResult(strings, values, type) { + var partCallback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : defaultPartCallback; + + _classCallCheck(this, TemplateResult); + + this.strings = strings; + this.values = values; + this.type = type; + this.partCallback = partCallback; + } + /** + * Returns a string of HTML used to create a