1 line
8.4 KiB
Plaintext
Executable File
1 line
8.4 KiB
Plaintext
Executable File
{"version":3,"file":"sequenceEqual.js","sourceRoot":"","sources":["../../src/operators/sequenceEqual.ts"],"names":[],"mappings":";;;;;;AAGA,2BAA2B,eAAe,CAAC,CAAA;AAC3C,yBAAyB,kBAAkB,CAAC,CAAA;AAC5C,4BAA4B,qBAAqB,CAAC,CAAA;AAIlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,uBAAiC,SAAwB,EACxB,QAAkC;IACjE,MAAM,CAAC,UAAC,MAAqB,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,qBAAqB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,EAA3D,CAA2D,CAAC;AAChG,CAAC;AAHe,qBAAa,gBAG5B,CAAA;AAED;IACE,+BAAoB,SAAwB,EACxB,QAAiC;QADjC,cAAS,GAAT,SAAS,CAAe;QACxB,aAAQ,GAAR,QAAQ,CAAyB;IACrD,CAAC;IAED,oCAAI,GAAJ,UAAK,UAA+B,EAAE,MAAW;QAC/C,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,uBAAuB,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClG,CAAC;IACH,4BAAC;AAAD,CAAC,AARD,IAQC;AARY,6BAAqB,wBAQjC,CAAA;AAED;;;;GAIG;AACH;IAAmD,2CAAa;IAK9D,iCAAY,WAAwB,EAChB,SAAwB,EACxB,QAAiC;QACnD,kBAAM,WAAW,CAAC,CAAC;QAFD,cAAS,GAAT,SAAS,CAAe;QACxB,aAAQ,GAAR,QAAQ,CAAyB;QAN7C,OAAE,GAAQ,EAAE,CAAC;QACb,OAAE,GAAQ,EAAE,CAAC;QACb,iBAAY,GAAG,KAAK,CAAC;QAM3B,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,g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,CAAC;IAES,oDAAS,GAAnB;QACE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;IACH,uCAAC;AAAD,CAAC,AAhBD,CAAqD,uBAAU,GAgB9D","sourcesContent":["import { Operator } from '../Operator';\nimport { Observer } from '../Observer';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { tryCatch } from '../util/tryCatch';\nimport { errorObject } from '../util/errorObject';\n\nimport { OperatorFunction } from '../interfaces';\n\n/**\n * Compares all values of two observables in sequence using an optional comparor function\n * and returns an observable of a single boolean value representing whether or not the two sequences\n * are equal.\n *\n * <span class=\"informal\">Checks to see of all values emitted by both observables are equal, in order.</span>\n *\n * <img src=\"./img/sequenceEqual.png\" width=\"100%\">\n *\n * `sequenceEqual` subscribes to two observables and buffers incoming values from each observable. Whenever either\n * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom\n * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the\n * observables completes, the operator will wait for the other observable to complete; If the other\n * observable emits before completing, the returned observable will emit `false` and complete. If one observable never\n * completes or emits after the other complets, the returned observable will never complete.\n *\n * @example <caption>figure out if the Konami code matches</caption>\n * var code = Rx.Observable.from([\n * \"ArrowUp\",\n * \"ArrowUp\",\n * \"ArrowDown\",\n * \"ArrowDown\",\n * \"ArrowLeft\",\n * \"ArrowRight\",\n * \"ArrowLeft\",\n * \"ArrowRight\",\n * \"KeyB\",\n * \"KeyA\",\n * \"Enter\" // no start key, clearly.\n * ]);\n *\n * var keys = Rx.Observable.fromEvent(document, 'keyup')\n * .map(e => e.code);\n * var matches = keys.bufferCount(11, 1)\n * .mergeMap(\n * last11 =>\n * Rx.Observable.from(last11)\n * .sequenceEqual(code)\n * );\n * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));\n *\n * @see {@link combineLatest}\n * @see {@link zip}\n * @see {@link withLatestFrom}\n *\n * @param {Observable} compareTo The observable sequence to compare the source sequence to.\n * @param {function} [comparor] An optional function to compare each value pair\n * @return {Observable} An Observable of a single boolean value representing whether or not\n * the values emitted by both observables were equal in sequence.\n * @method sequenceEqual\n * @owner Observable\n */\nexport function sequenceEqual<T>(compareTo: Observable<T>,\n comparor?: (a: T, b: T) => boolean): OperatorFunction<T, boolean> {\n return (source: Observable<T>) => source.lift(new SequenceEqualOperator(compareTo, comparor));\n}\n\nexport class SequenceEqualOperator<T> implements Operator<T, boolean> {\n constructor(private compareTo: Observable<T>,\n private comparor: (a: T, b: T) => boolean) {\n }\n\n call(subscriber: Subscriber<boolean>, source: any): any {\n return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparor));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class SequenceEqualSubscriber<T, R> extends Subscriber<T> {\n private _a: T[] = [];\n private _b: T[] = [];\n private _oneComplete = false;\n\n constructor(destination: Observer<R>,\n private compareTo: Observable<T>,\n private comparor: (a: T, b: T) => boolean) {\n super(destination);\n this.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, this)));\n }\n\n protected _next(value: T): void {\n if (this._oneComplete && this._b.length === 0) {\n this.emit(false);\n } else {\n this._a.push(value);\n this.checkValues();\n }\n }\n\n public _complete(): void {\n if (this._oneComplete) {\n this.emit(this._a.length === 0 && this._b.length === 0);\n } else {\n this._oneComplete = true;\n }\n }\n\n checkValues() {\n const { _a, _b, comparor } = this;\n while (_a.length > 0 && _b.length > 0) {\n let a = _a.shift();\n let b = _b.shift();\n let areEqual = false;\n if (comparor) {\n areEqual = tryCatch(comparor)(a, b);\n if (areEqual === errorObject) {\n this.destination.error(errorObject.e);\n }\n } else {\n areEqual = a === b;\n }\n if (!areEqual) {\n this.emit(false);\n }\n }\n }\n\n emit(value: boolean) {\n const { destination } = this;\n destination.next(value);\n destination.complete();\n }\n\n nextB(value: T) {\n if (this._oneComplete && this._a.length === 0) {\n this.emit(false);\n } else {\n this._b.push(value);\n this.checkValues();\n }\n }\n}\n\nclass SequenceEqualCompareToSubscriber<T, R> extends Subscriber<T> {\n constructor(destination: Observer<R>, private parent: SequenceEqualSubscriber<T, R>) {\n super(destination);\n }\n\n protected _next(value: T): void {\n this.parent.nextB(value);\n }\n\n protected _error(err: any): void {\n this.parent.error(err);\n }\n\n protected _complete(): void {\n this.parent._complete();\n }\n}\n"]} |