1 line
5.2 KiB
Plaintext
Executable File
1 line
5.2 KiB
Plaintext
Executable File
{"version":3,"file":"single.js","sourceRoot":"","sources":["../../src/operators/single.ts"],"names":[],"mappings":";;;;;;AAEA,2BAA2B,eAAe,CAAC,CAAA;AAE3C,2BAA2B,oBAAoB,CAAC,CAAA;AAKhD;;;;;;;;;;;;;;;GAeG;AACH,gBAA0B,SAAuE;IAC/F,MAAM,CAAC,UAAC,MAAqB,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,EAAlD,CAAkD,CAAC;AACvF,CAAC;AAFe,cAAM,SAErB,CAAA;AAED;IACE,wBAAoB,SAAuE,EACvE,MAAsB;QADtB,cAAS,GAAT,SAAS,CAA8D;QACvE,WAAM,GAAN,MAAM,CAAgB;IAC1C,CAAC;IAED,6BAAI,GAAJ,UAAK,UAAyB,EAAE,MAAW;QACzC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACzF,CAAC;IACH,qBAAC;AAAD,CAAC,AARD,IAQC;AAED;;;;GAIG;AACH;IAAkC,oCAAa;IAK7C,0BAAY,WAAwB,EAChB,SAAuE,EACvE,MAAsB;QACxC,kBAAM,WAAW,CAAC,CAAC;QAFD,cAAS,GAAT,SAAS,CAA8D;QACvE,WAAM,GAAN,MAAM,CAAgB;QANlC,cAAS,GAAY,KAAK,CAAC;QAE3B,UAAK,GAAW,CAAC,CAAC;IAM1B,CAAC;IAEO,2CAAgB,GAAxB,UAAyB,KAAQ;QAC/B,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACpE,CAAC;QAAC,IAAI,CAAC,CAAC;YACN,IAAI,CAAC,SAAS,GAAG,I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Observable } from '../Observable';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observer } from '../Observer';\nimport { EmptyError } from '../util/EmptyError';\nimport { TeardownLogic } from '../Subscription';\n\nimport { MonoTypeOperatorFunction } from '../interfaces';\n\n/**\n * Returns an Observable that emits the single item emitted by the source Observable that matches a specified\n * predicate, if that Observable emits one such item. If the source Observable emits more than one such item or no\n * such items, notify of an IllegalArgumentException or NoSuchElementException respectively.\n *\n * <img src=\"./img/single.png\" width=\"100%\">\n *\n * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`\n * callback if the Observable completes before any `next` notification was sent.\n * @param {Function} predicate - A predicate function to evaluate items emitted by the source Observable.\n * @return {Observable<T>} An Observable that emits the single item emitted by the source Observable that matches\n * the predicate.\n .\n * @method single\n * @owner Observable\n */\nexport function single<T>(predicate?: (value: T, index: number, source: Observable<T>) => boolean): MonoTypeOperatorFunction<T> {\n return (source: Observable<T>) => source.lift(new SingleOperator(predicate, source));\n}\n\nclass SingleOperator<T> implements Operator<T, T> {\n constructor(private predicate?: (value: T, index: number, source: Observable<T>) => boolean,\n private source?: Observable<T>) {\n }\n\n call(subscriber: Subscriber<T>, source: any): TeardownLogic {\n return source.subscribe(new SingleSubscriber(subscriber, this.predicate, this.source));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass SingleSubscriber<T> extends Subscriber<T> {\n private seenValue: boolean = false;\n private singleValue: T;\n private index: number = 0;\n\n constructor(destination: Observer<T>,\n private predicate?: (value: T, index: number, source: Observable<T>) => boolean,\n private source?: Observable<T>) {\n super(destination);\n }\n\n private applySingleValue(value: T): void {\n if (this.seenValue) {\n this.destination.error('Sequence contains more than one element');\n } else {\n this.seenValue = true;\n this.singleValue = value;\n }\n }\n\n protected _next(value: T): void {\n const index = this.index++;\n\n if (this.predicate) {\n this.tryNext(value, index);\n } else {\n this.applySingleValue(value);\n }\n }\n\n private tryNext(value: T, index: number): void {\n try {\n if (this.predicate(value, index, this.source)) {\n this.applySingleValue(value);\n }\n } catch (err) {\n this.destination.error(err);\n }\n }\n\n protected _complete(): void {\n const destination = this.destination;\n\n if (this.index > 0) {\n destination.next(this.seenValue ? this.singleValue : undefined);\n destination.complete();\n } else {\n destination.error(new EmptyError);\n }\n }\n}\n"]} |