{"version":3,"file":"urx.esm.js","sources":["../src/constants.ts","../src/utils.ts","../src/actions.ts","../src/streams.ts","../src/pipe.ts","../src/transformers.ts","../src/system.ts"],"sourcesContent":["export const PUBLISH = 0 as const\nexport type PUBLISH = typeof PUBLISH\n\nexport const SUBSCRIBE = 1 as const\nexport type SUBSCRIBE = typeof SUBSCRIBE\n\nexport const RESET = 2 as const\nexport type RESET = typeof RESET\n\nexport const VALUE = 4 as const\nexport type VALUE = typeof VALUE\n","/**\n * Utils includes\n * - a handful of functional utilities inspired by or taken from the [Ramda library](https://ramdajs.com/);\n * - TypeScript crutches - the [[tup]] function.\n *\n * Use these for your convenience - they are here so that urx is zero-dependency package.\n *\n * @packageDocumentation\n */\n\n/** @internal */\nexport interface Proc {\n (): any\n}\n\n/**\n * Performs left to right composition of two functions.\n */\nexport function compose(a: (arg: A) => R, b: (arg: I) => A): (arg: I) => R {\n return (arg: I) => a(b(arg))\n}\n\n/**\n * Takes a value and applies a function to it.\n */\nexport function thrush(arg: I, proc: (arg: I) => K) {\n return proc(arg)\n}\n\n/**\n * Takes a 2 argument function and partially applies the first argument.\n */\nexport function curry2to1(proc: (arg1: T, arg2: K) => R, arg1: T): (arg2: K) => R {\n return arg2 => proc(arg1, arg2)\n}\n\n/**\n * Takes a 1 argument function and returns a function which when called, executes it with the provided argument.\n */\nexport function curry1to0(proc: (arg: T) => R, arg: T): () => R {\n return () => proc(arg)\n}\n\n/**\n * Returns a function which extracts the property from from the passed object.\n */\nexport function prop(property: string) {\n return (object: any) => object[property]\n}\n\n/**\n * Calls callback with the first argument, and returns it.\n */\nexport function tap(arg: T, proc: (arg: T) => any): T {\n proc(arg)\n return arg\n}\n\n/**\n * Utility function to help typescript figure out that what we pass is a tuple and not a generic array.\n * Taken from (this StackOverflow tread)[https://stackoverflow.com/questions/49729550/implicitly-create-a-tuple-in-typescript/52445008#52445008]\n */\nexport function tup>(...args: T): T {\n return args\n}\n\n/**\n * Calls the passed function.\n */\nexport function call(proc: Proc) {\n proc()\n}\n\n/**\n * returns a function which when called always returns the passed value\n */\nexport function always(value: T) {\n return () => value\n}\n\n/**\n * returns a function which calls all passed functions in the passed order.\n * joinProc does not pass arguments or collect return values.\n */\nexport function joinProc(...procs: Proc[]) {\n return () => {\n procs.map(call)\n }\n}\n\nexport function noop() {}\n","/**\n * urx Actions operate on streams - `publish` publishes data in a stream, and `subscribe` attaches a subscription to a stream.\n * @packageDocumentation\n */\nimport { PUBLISH, RESET, SUBSCRIBE, VALUE } from './constants'\nimport { curry2to1 } from './utils'\n\n/**\n * A Publisher is the **input end** of a Stream. The [[publish]] action publishes values in publishers.\n * @typeParam T the type of values to be published.\n */\nexport interface Publisher {\n /** @internal */\n (action: PUBLISH, value: T): void\n}\n\n/**\n * An Emitter is the **output end** of a Stream. The [[subscribe]] action binds {@link Subscription | subscriptions} to emitters.\n * @typeParam T the type of values that will be emitted.\n */\nexport interface Emitter {\n /** @internal */\n (action: SUBSCRIBE, subscription: Subscription): Unsubscribe\n /** @internal */\n (action: RESET): void\n}\n\n/**\n * Subscriptions are bound to Emitters with the [[subscribe]] action, and get called with the new values.\n * @typeParam T the Emitter value type.\n */\nexport interface Subscription {\n (value: T): any\n}\n\n/**\n * Subscribe-like actions return unsubscribe handles of the Unsubscribe type, which, when called, unbind the subscription.\n */\nexport interface Unsubscribe {\n (): void\n}\n\n/**\n * Streams present both the input and the output ends of a stream.\n * A single stream instance can be both subscribed to and published in.\n */\nexport interface Stream extends Publisher, Emitter {\n /** @internal */\n (action: SUBSCRIBE | PUBLISH | RESET): any // fix for bug with pipe + connect\n}\n\n/**\n * Just like {@link Stream | streams}, stateful streams present both input and output ends of a stream.\n * A single stream instance can be both subscribed to and published in.\n * Stateful Streams can also act like depots, preserving the last passed value and immediately publishing it to new subscriptions.\n * [[getValue]] can be used to extract value from stateful streams.\n */\nexport interface StatefulStream extends Publisher, Emitter {\n /** @internal */\n (action: SUBSCRIBE | PUBLISH | RESET | VALUE): any // fix for bug with pipe + connect\n // StatefulStream should extend rather then duplicate the signature, but this somehow causes a bug in TS\n}\n\n/**\n * Subscribes the specified [[Subscription]] to the updates from the Emitter.\n * The emitter calls the subscription with the new data each time new data is published into it.\n *\n * ```ts\n * const foo = stream();\n * subscribe(foo, (value) => console.log(value));\n * ```\n *\n * @returns an [[Unsubscribe]] handle - calling it will unbind the subscription from the emitter.\n *```ts\n * const foo = stream();\n * const unsub = subscribe(foo, (value) => console.log(value));\n * unsub();\n *```\n */\nexport function subscribe(emitter: Emitter, subscription: Subscription): Unsubscribe {\n return emitter(SUBSCRIBE, subscription)\n}\n\n/**\n * Publishes the value into the passed [[Publisher]].\n *\n * ```ts\n * const foo = stream();\n * publish(foo, 42);\n * ```\n */\nexport function publish(publisher: Publisher, value: T) {\n publisher(PUBLISH, value)\n}\n\n/**\n * Clears all subscriptions from the [[Emitter]].\n * ```ts\n * const foo = stream();\n * subscribe(foo, (value) => console.log(value));\n * reset(foo);\n * publish(foo, 42);\n * ```\n */\nexport function reset(emitter: Emitter) {\n emitter(RESET)\n}\n\n/**\n * Extracts the current value from a stateful stream. Use it only as an escape hatch, as it violates the concept of reactive programming.\n * ```ts\n * const foo = statefulStream(42);\n * console.log(getValue(foo));\n * ```\n */\nexport function getValue(depot: StatefulStream): T {\n return depot(VALUE)\n}\n\n/**\n * Connects two streams - any value emitted from the emitter will be published in the publisher.\n * ```ts\n * const foo = stream();\n * const bar = stream();\n * subscribe(bar, (value) => console.log(`Bar emitted ${value}`));\n *\n * connect(foo, bar);\n * publish(foo);\n * ```\n * @returns an [[Unsubscribe]] handle which will disconnect the two streams.\n */\nexport function connect(emitter: Emitter, publisher: Publisher) {\n return subscribe(emitter, curry2to1(publisher, PUBLISH))\n}\n\n/**\n * Executes the passed subscription at most once, for the next emit from the emitter.\n * ```ts\n * const foo = stream()\n * handleNext(foo, value => console.log(value)) // called once, with 42\n * publish(foo, 42)\n * publish(foo, 43)\n * ```\n * @returns an [[Unsubscribe]] handle to unbind the subscription if necessary.\n */\nexport function handleNext(emitter: Emitter, subscription: Subscription) {\n const unsub = emitter(SUBSCRIBE, value => {\n unsub()\n subscription(value)\n })\n return unsub\n}\n","/**\n * Streams are the basic building blocks of a reactive system. Think of them as the system permanent \"data tubes\".\n *\n * A stream acts as both an [[Emitter]] and [[Publisher]]. Each stream can have multiple {@link Subscription | Subscriptions}.\n *\n * urx streams are either **stateless** or **stateful**.\n * Stateless streams emit data to existing subscriptions when published, without keeping track of it.\n * Stateful streams remember the last published value and immediately publish it to new subscriptions.\n *\n * ```ts\n * import { stream, statefulStream, publish, subscribe } from \"@virtuoso.dev/urx\";\n *\n * // foo is a stateless stream\n * const foo = stream();\n *\n * publish(foo, 42);\n * // this subsription will not be called...\n * subscribe(foo, (value) => console.log(value));\n * // it will only catch published values after it\n * publish(foo, 43);\n *\n * // stateful streams always start with an initial value\n * const bar = statefulStream(42);\n *\n * // subscribing to a stateful stream\n * // immediately calls the subscription with the current value\n * subscribe(bar, (value) => console.log(value));\n *\n * // subsequent publishing works just like stateless streams\n * publish(bar, 43);\n * ```\n * @packageDocumentation\n */\n\nimport { Emitter, StatefulStream, Stream, Subscription, Unsubscribe, subscribe, connect } from './actions'\nimport { RESET, PUBLISH, SUBSCRIBE, VALUE } from './constants'\nimport { tap, noop } from './utils'\n\n/**\n * Constructs a new stateless stream.\n * ```ts\n * const foo = stream();\n * ```\n * @typeParam T the type of values to publish in the stream.\n * @returns a [[Stream]]\n */\nexport function stream(): Stream {\n const subscriptions = [] as Subscription[]\n\n return ((action: PUBLISH | SUBSCRIBE | RESET, arg: any) => {\n switch (action) {\n case RESET:\n subscriptions.splice(0, subscriptions.length)\n return\n case SUBSCRIBE:\n subscriptions.push(arg)\n return () => {\n const indexOf = subscriptions.indexOf(arg)\n if (indexOf > -1) {\n subscriptions.splice(indexOf, 1)\n }\n }\n case PUBLISH:\n subscriptions.slice().forEach(subscription => {\n subscription(arg as T)\n })\n return\n default:\n throw new Error(`unrecognized action ${action}`)\n }\n }) as Stream\n}\n\n/**\n * Constructs a new stateful stream.\n * ```ts\n * const foo = statefulStream(42);\n * ```\n * @param initial the initial value in the stream.\n * @typeParam T the type of values to publish in the stream. If omitted, the function infers it from the initial value.\n * @returns a [[StatefulStream]]\n */\nexport function statefulStream(initial: T): StatefulStream {\n let value: T = initial\n const innerSubject = stream()\n\n return ((action: PUBLISH | SUBSCRIBE | RESET | VALUE, arg: any) => {\n switch (action) {\n case SUBSCRIBE:\n const subscription = arg as Subscription\n subscription(value)\n break\n case PUBLISH:\n value = arg as T\n break\n case VALUE:\n return value\n }\n return innerSubject(action as any, arg)\n }) as StatefulStream\n}\n\n/**\n * Event handlers are special emitters which can have **at most one active subscription**.\n * Subscribing to an event handler unsubscribes the previous subscription, if present.\n * ```ts\n * const foo = stream();\n * const fooEvent = eventHandler(foo);\n *\n * // will be called once with 42\n * subscribe(fooEvent, (value) => console.log(`Sub 1 ${value}`));\n * publish(foo, 42);\n *\n * // unsubscribes sub 1\n * subscribe(fooEvent, (value) => console.log(`Sub 2 ${value}`));\n * publish(foo, 43);\n * ```\n * @param emitter the source emitter.\n * @returns the single-subscription emitter.\n */\nexport function eventHandler(emitter: Emitter) {\n let unsub: Unsubscribe | undefined\n let currentSubscription: any\n let cleanup = () => unsub && unsub()\n\n return function(action: SUBSCRIBE | RESET, subscription?: Subscription) {\n switch (action) {\n case SUBSCRIBE:\n if (subscription) {\n if (currentSubscription === subscription) {\n return\n }\n cleanup()\n currentSubscription = subscription\n unsub = subscribe(emitter, subscription!)\n return unsub\n } else {\n cleanup()\n return noop\n }\n case RESET:\n cleanup()\n currentSubscription = null\n return\n default:\n throw new Error(`unrecognized action ${action}`)\n }\n } as Emitter\n}\n\n/**\n * Creates and connects a \"junction\" stream to the specified emitter. Often used with [[pipe]], to avoid the multiple evaluation of operator sets.\n *\n * ```ts\n * const foo = stream();\n *\n * const fooX2 = pipe(\n * foo,\n * map((value) => {\n * console.log(`multiplying ${value}`);\n * return value * 2;\n * })\n * );\n *\n * subscribe(fooX2, (value) => console.log(value));\n * subscribe(fooX2, (value) => console.log(value));\n *\n * publish(foo, 42); // executes the map operator twice for each subscription.\n *\n * const sharedFooX2 = streamFromEmitter(pipe(\n * foo,\n * map((value) => {\n * console.log(`shared multiplying ${value}`);\n * return value * 2;\n * })\n * ));\n *\n * subscribe(sharedFooX2, (value) => console.log(value));\n * subscribe(sharedFooX2, (value) => console.log(value));\n *\n * publish(foo, 42);\n *```\n * @returns the resulting stream.\n */\nexport function streamFromEmitter(emitter: Emitter): Stream {\n return tap(stream(), stream => connect(emitter, stream))\n}\n\n/**\n * Creates and connects a \"junction\" stateful stream to the specified emitter. Often used with [[pipe]], to avoid the multiple evaluation of operator sets.\n *\n * ```ts\n * const foo = stream();\n *\n * const fooX2 = pipe(\n * foo,\n * map((value) => {\n * console.log(`multiplying ${value}`);\n * return value * 2;\n * })\n * );\n *\n * subscribe(fooX2, (value) => console.log(value));\n * subscribe(fooX2, (value) => console.log(value));\n *\n * publish(foo, 42); // executes the map operator twice for each subscription.\n *\n * const sharedFooX2 = statefulStreamFromEmitter(pipe(\n * foo,\n * map((value) => {\n * console.log(`shared multiplying ${value}`);\n * return value * 2;\n * })\n * ), 42);\n *\n * subscribe(sharedFooX2, (value) => console.log(value));\n * subscribe(sharedFooX2, (value) => console.log(value));\n *\n * publish(foo, 42);\n *```\n * @param initial the initial value in the stream.\n * @returns the resulting stateful stream.\n */\nexport function statefulStreamFromEmitter(emitter: Emitter, initial: T): StatefulStream {\n return tap(statefulStream(initial), stream => connect(emitter, stream))\n}\n","/**\n *\n * Stream values can be transformed and controlled by {@link pipe | **piping**} through **operators**.\n * urx includes several operators like [[map]], [[filter]], [[scan]], and [[throttleTime]].\n * The [[withLatestFrom]] operator allows the combination of values from other streams.\n *\n * ```ts\n * const foo = stream()\n *\n * // create an emitter that first adds 2 to the passed value, then multiplies it by * 2\n * const bar = pipe(foo, map(value => value + 2), map(value => value * 2))\n * subscribe(bar, value => console.log(value))\n * publish(foo, 2) // outputs 8\n * ```\n *\n * ### Implementing Custom Operators\n * To implement your own operators, implement the [[Operator]] interface.\n * @packageDocumentation\n */\nimport { compose, thrush } from './utils'\nimport { Emitter, subscribe, Subscription, reset } from './actions'\nimport { SUBSCRIBE, RESET } from './constants'\n\n/**\n * Operators can transform and control the flow of values.\n * [[pipe]] is used to transform one Emitter into another by stacking operators to its values.\n * To build your own operator that looks like the built-in ones,\n * create a function which returns an operator.\n * The following custom operator multiplies the passed value:\n *\n * ```ts\n * function multiplyBy(multiplier: number): Operator {\n * return done => value => done(value * multiplier)\n * }\n *\n * const foo = stream()\n * const multipliedFoo = pipe(foo, multiplyBy(3))\n * subscribe(multipliedFoo, value => console.log(value))\n * publish(foo, 42)\n * ```\n */\nexport interface Operator {\n (done: (value: Output) => void): (value: Input) => void\n}\n\n/** @internal */\ntype CombineOperatorsReturnType = (subscriber: (value: O) => void) => (value: I) => void\n\n/** @internal */\nfunction combineOperators(...operators: Operator[]): CombineOperatorsReturnType {\n return (subscriber: (value: any) => void) => {\n return operators.reduceRight(thrush, subscriber)\n }\n}\n\n/** @internal */\ntype O = Operator\n\n/**\n * Creates a new emitter from the passed one by piping its values through one or more operators.\n * Operators can perform various actions like filter values, pull values from other emitters, or compute new values.\n *\n * ```ts\n * const foo = stream()\n *\n * // create an emitter that first adds 2 to the passed value, then multiplies it by * 2\n * const bar = pipe(foo, map(value => value + 2), map(value => value * 2))\n * subscribe(bar, value => console.log(value))\n * publish(foo, 2) // outputs 8\n * ```\n * #### Sharing Subscription Calculations\n *\n * `pipe` acts as a proxy for the source emitter, and re-runs the operators for each subscription to the derived emitter.\n * Use [[streamFromEmitter]] or [[statefulStreamFromEmitter]] to avoid that.\n */\nexport function pipe(s: Emitter): Emitter // prettier-ignore\nexport function pipe(s: Emitter, o1: O): Emitter // prettier-ignore\nexport function pipe(s: Emitter, ...o: [O, O]): Emitter // prettier-ignore\nexport function pipe(s: Emitter, ...o: [O, O, O]): Emitter // prettier-ignore\nexport function pipe(s: Emitter, ...o: [O, O, O, O]): Emitter // prettier-ignore\nexport function pipe(s: Emitter, ...o: [O, O, O, O, O]): Emitter // prettier-ignore\nexport function pipe(s: Emitter, ...o: [O, O, O, O, O, O]): Emitter // prettier-ignore\nexport function pipe(s: Emitter, ...o: [O, O, O, O, O, O, O]): Emitter // prettier-ignore\nexport function pipe(source: Emitter, ...operators: O[]): Emitter {\n // prettier-ignore\n const project = combineOperators(...operators)\n return ((action: SUBSCRIBE | RESET, subscription: Subscription) => {\n switch (action) {\n case SUBSCRIBE:\n return subscribe(source, project(subscription))\n case RESET:\n reset(source)\n return\n default:\n throw new Error(`unrecognized action ${action}`)\n }\n }) as Emitter\n}\n\n/**\n * A function which determines if two values are equal.\n * Implement custom comparators when [[distinctUntilChanged]] needs to work on non-primitive objects.\n * @returns true if values should be considered equal.\n */\nexport interface Comparator {\n (previous: T, next: T): boolean\n}\n\n/**\n * The default [[Comparator]] for [[distinctUntilChanged]] and [[duc]].\n */\nexport function defaultComparator(previous: T, next: T) {\n return previous === next\n}\n\n/**\n * Filters out identical values. Pass an optional [[Comparator]] if you need to filter non-primitive values.\n * ```ts\n * const foo = stream()\n *\n * subscribe(\n * pipe(foo, distinctUntilChanged()),\n * console.log\n * ) // will be called only once\n *\n * publish(foo, 42)\n * publish(foo, 42)\n * ```\n */\nexport function distinctUntilChanged(comparator: Comparator = defaultComparator): Operator {\n let current: T\n return done => next => {\n if (!comparator(current, next)) {\n current = next\n done(next)\n }\n }\n}\n\n/**\n * Filters out values for which the predicator does not return `true`-ish.\n * ```ts\n * const foo = stream()\n *\n * subscribe(\n * pipe(foo, filter(value => value % 2 === 0)),\n * console.log\n * ) // will be called only with even values\n *\n * publish(foo, 2)\n * publish(foo, 3)\n * publish(foo, 4)\n * publish(foo, 5)\n * ```\n */\nexport function filter(predicate: (value: T) => boolean): Operator {\n return done => value => {\n predicate(value) && done(value)\n }\n}\n\n/**\n * Maps values using the provided project function.\n * ```ts\n * const foo = stream()\n *\n * subscribe(\n * pipe(foo, map(value => value * 2)),\n * console.log\n * ) // 4, 6\n *\n * publish(foo, 2)\n * publish(foo, 3)\n * ```\n */\nexport function map(project: (value: T) => K): Operator {\n return done => compose(done, project)\n}\n\n/**\n * Maps values to the hard-coded value.\n * ```ts\n * const foo = stream()\n *\n * subscribe(\n * pipe(foo, mapTo(3)),\n * console.log\n * ) // 3, 3\n *\n * publish(foo, 1)\n * publish(foo, 2)\n * ```\n */\nexport function mapTo(value: T): Operator {\n return done => () => done(value)\n}\n\n/**\n * Works like Array#reduce.\n * Applies an accumulator function on the emitter, and outputs intermediate result. Starts with the initial value.\n * ```ts\n * const foo = stream()\n *\n * subscribe(\n * pipe(foo, scan((acc, value) => acc + value, 2),\n * console.log\n * ) // 3, 5\n *\n * publish(foo, 1)\n * publish(foo, 2)\n * ```\n */\nexport function scan(scanner: (current: T, value: K) => T, initial: T): Operator {\n return done => value => done((initial = scanner(initial, value)))\n}\n\n/**\n * Skips the specified amount of values from the emitter.\n * ```ts\n * const foo = stream()\n *\n * subscribe(\n * pipe(foo, skip(2)),\n * console.log\n * ) // 3, 4\n *\n * publish(foo, 1) // skipped\n * publish(foo, 2) // skipped\n * publish(foo, 3)\n * publish(foo, 4)\n * ```\n */\nexport function skip(times: number): Operator {\n return done => value => {\n times > 0 ? times-- : done(value)\n }\n}\n\n/**\n * Throttles flowing values at the provided interval in milliseconds.\n * [Throttle VS Debounce in SO](https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function).\n *\n * ```ts\n * const foo = stream()\n * publish(foo, 1)\n *\n * setTimeout(() => publish(foo, 2), 20)\n * setTimeout(() => publish(foo, 3), 20)\n *\n * subscribe(pipe(foo, throttleTime(50)), val => {\n * console.log(value); // 3\n * })\n * ```\n */\nexport function throttleTime(interval: number): Operator {\n let currentValue: T | undefined\n let timeout: any\n\n return done => value => {\n currentValue = value\n\n if (timeout) {\n return\n }\n\n timeout = setTimeout(() => {\n timeout = undefined\n done(currentValue!)\n }, interval)\n }\n}\n\n/**\n * Debounces flowing values at the provided interval in milliseconds.\n * [Throttle VS Debounce in SO](https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function).\n *\n * ```ts\n * const foo = stream()\n * publish(foo, 1)\n *\n * setTimeout(() => publish(foo, 2), 20)\n * setTimeout(() => publish(foo, 3), 20)\n *\n * subscribe(pipe(foo, debounceTime(50)), val => {\n * console.log(value); // 3\n * })\n * ```\n */\nexport function debounceTime(interval: number): Operator {\n let currentValue: T | undefined\n let timeout: any\n\n return done => value => {\n currentValue = value\n if (timeout) {\n clearTimeout(timeout)\n }\n\n timeout = setTimeout(() => {\n done(currentValue!)\n }, interval)\n }\n}\n\n/**\n * Combines the source Emitter with the latest values from the specified Emitters into an array. Outputs only when the source Emitter emits.\n * See [[combineLatest]] for a transformer that outputs when any of the emitters emit.\n *\n * ```ts\n * const foo = stream()\n * const bar = stream()\n * subscribe(\n * pipe(\n * foo,\n * withLatestFrom(bar)\n * ),\n * (([foo, bar]) => console.log({ foo, bar }))\n * )\n *\n * publish(foo, 1) // nothing happens, bar has not emitted yet\n * publish(bar, 1) // still nothing\n * publish(foo, 2) // logs { foo: 2, bar: 1 }\n * publish(bar, 2)\n * publish(foo, 3) // logs { foo: 3, bar: 2 }\n * ```\n */\nexport function withLatestFrom(...s: [Emitter]): Operator // prettier-ignore\nexport function withLatestFrom(...s: [Emitter, Emitter]): Operator // prettier-ignore\nexport function withLatestFrom( ...s: [Emitter, Emitter, Emitter]): Operator // prettier-ignore\nexport function withLatestFrom( ...s: [Emitter, Emitter, Emitter, Emitter]): Operator // prettier-ignore\nexport function withLatestFrom( ...s: [Emitter, Emitter, Emitter, Emitter, Emitter]): Operator // prettier-ignore\nexport function withLatestFrom( ...s: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Operator // prettier-ignore\nexport function withLatestFrom( ...s: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Operator // prettier-ignore\nexport function withLatestFrom(...sources: Emitter[]): Operator {\n const values = new Array(sources.length)\n let called = 0\n let pendingCall: null | (() => void) = null\n const allCalled = Math.pow(2, sources.length) - 1\n\n sources.forEach((source, index) => {\n const bit = Math.pow(2, index)\n subscribe(source, value => {\n let prevCalled = called\n called = called | bit\n values[index] = value\n if (prevCalled !== allCalled && called === allCalled && pendingCall) {\n pendingCall()\n pendingCall = null\n }\n })\n })\n\n return done => value => {\n let call = () => done([value].concat(values))\n if (called === allCalled) {\n call()\n } else {\n pendingCall = call\n }\n }\n}\n","/**\n * Transformers change and combine streams, similar to operators.\n * urx comes with two combinators - [[combineLatest]] and [[merge]], and one convenience filter - [[duc]].\n *\n * @packageDocumentation\n */\nimport { Emitter, publish, reset, subscribe, Subscription } from './actions'\nimport { RESET, SUBSCRIBE } from './constants'\nimport { Comparator, defaultComparator, distinctUntilChanged, pipe } from './pipe'\nimport { stream } from './streams'\nimport { joinProc } from './utils'\n\n/**\n * Merges one or more emitters from the same type into a new Emitter which emits values from any of the source emitters.\n * ```ts\n * const foo = stream()\n * const bar = stream()\n *\n * subscribe(merge(foo, bar), (value) => console.log(value)) // 42, 43\n *\n * publish(foo, 42)\n * publish(bar, 43)\n * ```\n */\nexport function merge(...sources: Emitter[]): Emitter {\n return function(action: SUBSCRIBE | RESET, subscription?: Subscription) {\n switch (action) {\n case SUBSCRIBE:\n return joinProc(...sources.map(source => subscribe(source, subscription!)))\n case RESET:\n // do nothing, we are stateless\n return\n default:\n throw new Error(`unrecognized action ${action}`)\n }\n } as Emitter\n}\n\n/**\n * A convenience wrapper that emits only the distinct values from the passed Emitter. Wraps [[pipe]] and [[distinctUntilChanged]].\n *\n * ```ts\n * const foo = stream()\n *\n * // this line...\n * const a = duc(foo)\n *\n * // is equivalent to this\n * const b = pipe(distinctUntilChanged(foo))\n * ```\n *\n * @param source The source emitter.\n * @param comparator optional custom comparison function for the two values.\n *\n * @typeParam T the type of the value emitted by the source.\n *\n * @returns the resulting emitter.\n */\nexport function duc(source: Emitter, comparator: Comparator = defaultComparator): Emitter {\n return pipe(source, distinctUntilChanged(comparator))\n}\n\n/**\n * Creates an emitter with the latest values from all passed emitters as an array.\n *\n * `combineLatest` acts as a Depot. Using it on stateless streams persists the last emitted value of each [[Emitter]].\n * Provided that all emitters have emitted at least once, subscribing to the resulting emitter will immediately receive their combined latest values.\n *\n * ```ts\n * const foo = stream()\n * const bar = stream()\n *\n * subscribe(combineLatest(foo, bar), ([foo, bar]) => console.log({ foo, bar }))\n *\n * publish(foo, 42)\n * publish(bar, 43) // { foo: 42, bar: 43 }\n * publish(foo, 44) // { foo: 44, bar: 43 }\n * publish(bar, 45) // { foo: 44, bar: 45 }\n * ```\n */\nexport function combineLatest(...emitters: [Emitter, Emitter]): Emitter<[O1, O2]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5, O6]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5, O6, O7]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5, O6, O7, O8]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5, O6, O7, O8, O9]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10]> // prettier-ignore\nexport function combineLatest( ...emitters: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Emitter<[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11]> // prettier-ignore\nexport function combineLatest(...emitters: Emitter[]): Emitter {\n let innerSubject = stream()\n const values = new Array(emitters.length)\n let called = 0\n const allCalled = Math.pow(2, emitters.length) - 1\n\n emitters.forEach((source, index) => {\n const bit = Math.pow(2, index)\n subscribe(source, value => {\n values[index] = value\n called = called | bit\n if (called === allCalled) {\n publish(innerSubject, values)\n }\n })\n })\n\n return function(action: SUBSCRIBE | RESET, subscription?: Subscription) {\n switch (action) {\n case SUBSCRIBE:\n if (called === allCalled) {\n subscription!(values)\n }\n return subscribe(innerSubject, subscription!)\n case RESET:\n return reset(innerSubject)\n default:\n throw new Error(`unrecognized action ${action}`)\n }\n } as Emitter\n}\n","/**\n * ## Thinking in Systems\n * systems are a stateful **data-processing machines** which accept input through **input streams**,\n * init and maintain state in **depots** and, in certain conditions, emit values to subscriptions through **output streams**.\n * Systems can specify other systems as dependencies, and can act as singletons in the resulting dependency tree.\n *\n * ### Depots\n *\n * The first, and probably the most critical part to understand are **the depots**\n * mostly because they are somewhat implicit.\n * Unlike other state management paradigms, the depots are not kept in a single data structure.\n * Insted, depots are defined and maintained as stateful streams, stateful transfomers\n * like [[combineLatest]] or stateful operators like[ []withLatestFrom] or [[scan]].\n *\n * **Depots persist values over time**.\n * If it was not for them, the system had to re-receive its entire input state simultaneously in order to calculate the values for its output stream.\n *\n * Of course, strictly speaking, it is possible to implement a pure, stateless system as a form of a complex map/reduce. urx would not mind that ;).\n *\n * ### Input Streams\n *\n * The system receives updates from the rest of the world through values published in its input streams.\n * The streams used can be either stateless (acting as means to send **signals**) or stateful, where the initial stream state acts as the default value for that system parameter.\n *\n * The effects of the input streams are up to the system data-processing logic. It can change its depots' state, and/or emit values through its output streams.\n *\n * ### Data Processing\n *\n * The actual system behavior is exclusively implemented by **applying transformers and operators** to the input streams, producing the respective output streams.\n * In the final state the system streams are organized in a directed graph, where incoming data is routed through certain edges and nodes.\n * Simple systems like the one in [urx by example](https://urx.virtuoso.dev/docs/urx-by-example) can use a straightforward single-step transformation (in this case, `combineLatest` and `map`),\n * while complex ones can introduce multiple intermediate streams to model their logic.\n *\n * ### Output Streams\n *\n * The system publishes updates to its clients (other systems or an UI bound to it) by publishing data in its output streams.\n * State-reflecting output streams, like `sum` in the [urx by example](https://urx.virtuoso.dev/docs/urx-by-example) should use stateful streams as output streams.\n * Signal-like output should use regular, stateless streams. In general, stateless input streams tend to have a symmetrical stateless streams, and the opposite.\n *\n * @packageDocumentation\n */\nimport { Emitter } from './actions'\n\n/**\n * Systems are a dictionaries of streams. a [[SystemConstructor]] should return a System.\n */\nexport interface System {\n [key: string]: Emitter\n}\n\n/**\n * a SystemSpec is the result from a [[system]] call. To obtain the [[System]], pass the spec to [[init]].\n */\nexport interface SystemSpec> {\n id: string\n constructor: C\n dependencies: SS\n singleton: boolean\n}\n\n/** @internal **/\nexport type AnySystemSpec = SystemSpec\n\n/** @internal **/\nexport type SystemSpecs = AnySystemSpec[]\n\n/** @internal **/\nexport type SR> = R\n\n/** @internal **/\nexport type SpecResults = L extends 0\n ? []\n : L extends 1\n ? [SR]\n : L extends 2\n ? [SR, SR]\n : L extends 3\n ? [SR, SR, SR]\n : L extends 4\n ? [SR, SR, SR, SR]\n : L extends 5\n ? [SR, SR, SR, SR, SR]\n : L extends 6\n ? [SR, SR, SR, SR, SR, SR]\n : L extends 7\n ? [SR, SR, SR, SR, SR, SR, SR]\n : L extends 8\n ? [SR, SR, SR, SR, SR, SR, SR, SR]\n : L extends 9\n ? [SR, SR, SR, SR, SR, SR, SR, SR, SR]\n : L extends 10\n ? [SR, SR, SR, SR, SR, SR, SR, SR, SR, SR]\n : L extends 11\n ? [SR, SR, SR, SR, SR, SR, SR, SR, SR, SR, SR]\n : never\n\n/**\n * The system constructor is a function which initializes and connects streams and returns them as a [[System]].\n * If the [[system]] call specifies system dependencies, the constructor receives the dependencies as an array argument.\n */\nexport type SystemConstructor = (dependencies: SpecResults) => System\n\n/**\n * `system` defines a specification of a system - its constructor, dependencies and if it should act as a singleton in a system dependency tree.\n * When called, system returns a [[SystemSpec]], which is then initialized along with its dependencies by passing it to [[init]].\n *\n * ```ts\n * @import { subscribe, publish, system, init, tup, connect, map, pipe } from 'urx'\n *\n * // a simple system with two streams\n * const sys1 = system(() => {\n * const a = stream()\n * const b = stream()\n *\n * connect(pipe(a, map(value => value * 2)), b)\n * return { a, b }\n * })\n *\n * // a second system which depends on the streams from the first one\n * const sys2 = system(([ {a, b} ]) => {\n * const c = stream()\n * connect(pipe(b, map(value => value * 2)), c)\n * // re-export the `a` stream, keep `b` internal\n * return { a, c }\n * }, tup(sys1))\n *\n * // init will recursively initialize sys2 dependencies, in this case sys1\n * const { a, c } = init(sys2)\n * subscribe(c, c => console.log(`Value multiplied by 4`, c))\n * publish(a, 2)\n * ```\n *\n * #### Singletons in Dependency Tree\n *\n * By default, systems will be initialized only once if encountered multiple times in the dependency tree.\n * In the below dependency system tree, systems `b` and `c` will receive the same stream instances from system `a` when system `d` is initialized.\n * ```txt\n * a\n * / \\\n * b c\n * \\ /\n * d\n * ```\n * If `a` gets `{singleton: false}` as a last argument, `init` creates two separate instances - one for `b` and one for `c`.\n *\n * @param constructor the system constructor function. Initialize and connect the streams in its body.\n *\n * @param dependencies the system dependencies, which the constructor will receive as arguments.\n * Use the [[tup]] utility **For TypeScript type inference to work correctly**.\n * ```ts\n * const sys3 = system(() => { ... }, tup(sys2, sys1))\n * ```\n * @param __namedParameters Options\n * @param singleton determines if the system will act as a singleton in a system dependency tree. `true` by default.\n */\nexport function system, D extends SystemSpecs>(\n constructor: F,\n dependencies: D = ([] as unknown) as D,\n { singleton }: { singleton: boolean } = { singleton: true }\n): SystemSpec {\n return {\n id: id(),\n constructor,\n dependencies,\n singleton,\n }\n}\n\n/** @internal */\nconst id = () => (Symbol() as unknown) as string\n\n/**\n * Initializes a [[SystemSpec]] by recursively initializing its dependencies.\n *\n * ```ts\n * // a simple system with two streams\n * const sys1 = system(() => {\n * const a = stream()\n * const b = stream()\n *\n * connect(pipe(a, map(value => value * 2)), b)\n * return { a, b }\n * })\n *\n * const { a, b } = init(sys1)\n * subscribe(b, b => console.log(b))\n * publish(a, 2)\n * ```\n *\n * @returns the [[System]] constructed by the spec constructor.\n * @param systemSpec the system spec to initialize.\n */\nexport function init(systemSpec: SS): SR {\n const singletons = new Map()\n const _init = ({ id, constructor, dependencies, singleton }: SS) => {\n if (singleton && singletons.has(id)) {\n return singletons.get(id)! as SR\n }\n const system = constructor(dependencies.map((e: AnySystemSpec) => _init(e)))\n if (singleton) {\n singletons.set(id, system)\n }\n return system as any\n }\n return _init(systemSpec)\n}\n"],"names":["PUBLISH","SUBSCRIBE","RESET","VALUE","compose","a","b","arg","thrush","proc","curry2to1","arg1","arg2","curry1to0","prop","property","object","tap","tup","args","call","always","value","joinProc","procs","map","noop","subscribe","emitter","subscription","publish","publisher","reset","getValue","depot","connect","handleNext","unsub","stream","subscriptions","action","splice","length","push","indexOf","slice","forEach","Error","statefulStream","initial","innerSubject","eventHandler","currentSubscription","cleanup","streamFromEmitter","statefulStreamFromEmitter","combineOperators","operators","subscriber","reduceRight","pipe","source","project","defaultComparator","previous","next","distinctUntilChanged","comparator","current","done","filter","predicate","mapTo","scan","scanner","skip","times","throttleTime","interval","currentValue","timeout","setTimeout","undefined","debounceTime","clearTimeout","withLatestFrom","sources","values","Array","called","pendingCall","allCalled","Math","pow","index","bit","prevCalled","concat","merge","duc","combineLatest","emitters","system","constructor","dependencies","singleton","id","Symbol","init","systemSpec","singletons","Map","_init","has","get","e","set"],"mappings":"AAAO,IAAMA,OAAO,GAAG,CAAhB;AAGA,IAAM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