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,CAAC;gBAClB,CAAC,CACF,CAAC;YACJ,CAAC;YAAC,IAAI,CAAC,CAAC;gBACN,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAE3B,SAAqB,CAAC,GAAG,CAAC,GAAG,WAAgB,CAAC;gBAC/C,aAAa,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;QAED;YACE,EAAE,CAAC,CAAC,gBAAgB,GAAG,eAAe,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;gBAClE,QAAQ,CAAC,IAAI,CACX,CACE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;sBACpB,CAAE,GAAG,SAAS,CAAc;wCACtB,SAAqB,CAAE,CAC7B,CACP,CAAC;YACJ,CAAC;QACH,CAAC;QAED,aAAa,EAAE,CAAC;QAEhB,MAAM,CAAC;YACL,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAClC,YAAY,IAAI,YAAY,CAAC,WAAW,EAAE,CAC3C,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC\"}","code":"/** @license\r\n *  Copyright 2016 - present The Material Motion Authors. All Rights Reserved.\r\n *\r\n *  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n *  use this file except in compliance with the License. You may obtain a copy\r\n *  of the License at\r\n *\r\n *      http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n *  Unless required by applicable law or agreed to in writing, software\r\n *  distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n *  License for the specific language governing permissions and limitations\r\n *  under the License.\r\n */\r\nimport { MotionObservable, } from './observables/proxies';\r\nimport { isIterable, isObservable, } from './typeGuards';\r\nexport function combineLatest(streams, { waitForAllValues = true } = {}) {\r\n    return new MotionObservable((observer) => {\r\n        const outstandingKeys = new Set(Object.keys(streams));\r\n        let nextValue;\r\n        if (isIterable(streams)) {\r\n            nextValue = [];\r\n        }\r\n        else {\r\n            nextValue = {};\r\n        }\r\n        const subscriptions = {};\r\n        let initializing = true;\r\n        outstandingKeys.forEach(checkKey);\r\n        initializing = false;\r\n        // TypeScript doesn't know whether the index signature for `streams` (and\r\n        // hence, `nextValue` and `outstandingKeys`) is a string or a number.\r\n        // Thus, it throws an error at a simple `streams[key]`.  Since we know\r\n        // that whichever it is, `key` can index into all three collections, we\r\n        // cast each to `Dict<V>` and `key` to `string`.  Then, TypeScript will\r\n        // happily index into the collections using `key`.\r\n        function checkKey(key) {\r\n            const maybeStream = streams[key];\r\n            if (isObservable(maybeStream)) {\r\n                subscriptions[key] = maybeStream.subscribe((value) => {\r\n                    outstandingKeys.delete(key);\r\n                    nextValue[key] = value;\r\n                    emitNextValue();\r\n                });\r\n            }\r\n            else {\r\n                outstandingKeys.delete(key);\r\n                nextValue[key] = maybeStream;\r\n                emitNextValue();\r\n            }\r\n        }\r\n        function emitNextValue() {\r\n            if (waitForAllValues ? outstandingKeys.size === 0 : !initializing) {\r\n                observer.next((Array.isArray(nextValue)\r\n                    ? [...nextValue]\r\n                    : Object.assign({}, nextValue)));\r\n            }\r\n        }\r\n        emitNextValue();\r\n        return function disconnect() {\r\n            Object.values(subscriptions).forEach(subscription => subscription.unsubscribe());\r\n        };\r\n    });\r\n}\r\n//# sourceMappingURL=combineLatest.js.map","dts":{"name":"/Users/brentons/Projects/material-motion-js/packages/core/combineLatest.d.ts","text":"import { MaybeReactive, NumericallyKeyed, ObservableWithMotionOperators } from './types';\r\nexport declare type CombineLatestOptions = {\r\n    waitForAllValues?: boolean;\r\n};\r\nexport declare function combineLatest<V, T extends MaybeReactive<NumericallyKeyed<V>>, U extends Array<V>>(streams: T, options?: CombineLatestOptions): ObservableWithMotionOperators<U>;\r\nexport declare function combineLatest<U, T extends MaybeReactive<U>>(streams: T, options?: CombineLatestOptions): ObservableWithMotionOperators<U>;\r\n"}}
