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operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable, SubscribableOrPromise } from '../Observable';\nimport { Subscription, TeardownLogic } from '../Subscription';\n\nimport { tryCatch } from '../util/tryCatch';\nimport { errorObject } from '../util/errorObject';\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { MonoTypeOperatorFunction } from '../interfaces';\n\n/**\n * Ignores source values for a duration determined by another Observable, then\n * emits the most recent value from the source Observable, then repeats this\n * process.\n *\n * <span class=\"informal\">It's like {@link auditTime}, but the silencing\n * duration is determined by a second Observable.</span>\n *\n * <img src=\"./img/audit.png\" width=\"100%\">\n *\n * `audit` is similar to `throttle`, but emits the last value from the silenced\n * time window, instead of the first value. `audit` emits the most recent value\n * from the source Observable on the output Observable as soon as its internal\n * timer becomes disabled, and ignores source values while the timer is enabled.\n * Initially, the timer is disabled. As soon as the first source value arrives,\n * the timer is enabled by calling the `durationSelector` function with the\n * source value, which returns the \"duration\" Observable. When the duration\n * Observable emits a value or completes, the timer is disabled, then the most\n * recent source value is emitted on the output Observable, and this process\n * repeats for the next source value.\n *\n * @example <caption>Emit clicks at a rate of at most one click per second</caption>\n * var clicks = Rx.Observable.fromEvent(document, 'click');\n * var result = clicks.audit(ev => Rx.Observable.interval(1000));\n * result.subscribe(x => console.log(x));\n *\n * @see {@link auditTime}\n * @see {@link debounce}\n * @see {@link delayWhen}\n * @see {@link sample}\n * @see {@link throttle}\n *\n * @param {function(value: T): SubscribableOrPromise} durationSelector A function\n * that receives a value from the source Observable, for computing the silencing\n * duration, returned as an Observable or a Promise.\n * @return {Observable<T>} An Observable that performs rate-limiting of\n * emissions from the source Observable.\n * @method audit\n * @owner Observable\n */\nexport function audit<T>(durationSelector: (value: T) => SubscribableOrPromise<any>): MonoTypeOperatorFunction<T> {\n return function auditOperatorFunction(source: Observable<T>) {\n return source.lift(new AuditOperator(durationSelector));\n };\n}\n\nclass AuditOperator<T> implements Operator<T, T> {\n constructor(private durationSelector: (value: T) => SubscribableOrPromise<any>) {\n }\n\n call(subscriber: Subscriber<T>, source: any): TeardownLogic {\n return source.subscribe(new AuditSubscriber<T, T>(subscriber, this.durationSelector));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass AuditSubscriber<T, R> extends OuterSubscriber<T, R> {\n\n private value: T;\n private hasValue: boolean = false;\n private throttled: Subscription;\n\n constructor(destination: Subscriber<T>,\n private durationSelector: (value: T) => SubscribableOrPromise<any>) {\n super(destination);\n }\n\n protected _next(value: T): void {\n this.value = value;\n this.hasValue = true;\n if (!this.throttled) {\n const duration = tryCatch(this.durationSelector)(value);\n if (duration === errorObject) {\n this.destination.error(errorObject.e);\n } else {\n const innerSubscription = subscribeToResult(this, duration);\n if (innerSubscription.closed) {\n this.clearThrottle();\n } else {\n this.add(this.throttled = innerSubscription);\n }\n }\n }\n }\n\n clearThrottle() {\n const { value, hasValue, throttled } = this;\n if (throttled) {\n this.remove(throttled);\n this.throttled = null;\n throttled.unsubscribe();\n }\n if (hasValue) {\n this.value = null;\n this.hasValue = false;\n this.destination.next(value);\n }\n }\n\n notifyNext(outerValue: T, innerValue: R, outerIndex: number, innerIndex: number): void {\n this.clearThrottle();\n }\n\n notifyComplete(): void {\n this.clearThrottle();\n }\n}\n"]}
|