Subtheme of barrio
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
5.9 KiB

{"version":3,"file":"distinctUntilChanged.js","sourceRoot":"","sources":["../../src/operators/distinctUntilChanged.ts"],"names":[],"mappings":";;;;;;AACA,2BAA2B,eAAe,CAAC,CAAA;AAC3C,yBAAyB,kBAAkB,CAAC,CAAA;AAC5C,4BAA4B,qBAAqB,CAAC,CAAA;AAQlD,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,8BAA2C,OAAiC,EAAE,WAAyB;IACrG,MAAM,CAAC,UAAC,MAAqB,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,4BAA4B,CAAO,OAAO,EAAE,WAAW,CAAC,CAAC,EAAzE,CAAyE,CAAC;AAC9G,CAAC;AAFe,4BAAoB,uBAEnC,CAAA;AAED;IACE,sCAAoB,OAAgC,EAChC,WAAwB;QADxB,YAAO,GAAP,OAAO,CAAyB;QAChC,gBAAW,GAAX,WAAW,CAAa;IAC5C,CAAC;IAED,2CAAI,GAAJ,UAAK,UAAyB,EAAE,MAAW;QACzC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,8BAA8B,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1G,CAAC;IACH,mCAAC;AAAD,CAAC,AARD,IAQC;AAED;;;;GAIG;AACH;IAAmD,kDAAa;IAI9D,wCAAY,WAA0B,EAC1B,OAAgC,EACxB,WAAwB;QAC1C,kBAAM,WAAW,CAAC,CAAC;QADD,gBAAW,GAAX,WAAW,CAAa;QAJpC,WAAM,GAAY,KAAK,CAAC;QAM9B,EAAE,CAAC,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,CAAC;IACH,CAAC;IAEO,gDAA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operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { tryCatch } from '../util/tryCatch';\nimport { errorObject } from '../util/errorObject';\nimport { Observable } from '../Observable';\nimport { TeardownLogic } from '../Subscription';\nimport { MonoTypeOperatorFunction } from '../interfaces';\n\n/* tslint:disable:max-line-length */\nexport function distinctUntilChanged<T>(compare?: (x: T, y: T) => boolean): MonoTypeOperatorFunction<T>;\nexport function distinctUntilChanged<T, K>(compare: (x: K, y: K) => boolean, keySelector: (x: T) => K): MonoTypeOperatorFunction<T>;\n/* tslint:enable:max-line-length */\n\n/**\n * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.\n *\n * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.\n *\n * If a comparator function is not provided, an equality check is used by default.\n *\n * @example <caption>A simple example with numbers</caption>\n * Observable.of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4)\n * .distinctUntilChanged()\n * .subscribe(x => console.log(x)); // 1, 2, 1, 2, 3, 4\n *\n * @example <caption>An example using a compare function</caption>\n * interface Person {\n * age: number,\n * name: string\n * }\n *\n * Observable.of<Person>(\n * { age: 4, name: 'Foo'},\n * { age: 7, name: 'Bar'},\n * { age: 5, name: 'Foo'})\n * { age: 6, name: 'Foo'})\n * .distinctUntilChanged((p: Person, q: Person) => p.name === q.name)\n * .subscribe(x => console.log(x));\n *\n * // displays:\n * // { age: 4, name: 'Foo' }\n * // { age: 7, name: 'Bar' }\n * // { age: 5, name: 'Foo' }\n *\n * @see {@link distinct}\n * @see {@link distinctUntilKeyChanged}\n *\n * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.\n * @return {Observable} An Observable that emits items from the source Observable with distinct values.\n * @method distinctUntilChanged\n * @owner Observable\n */\nexport function distinctUntilChanged<T, K>(compare?: (x: K, y: K) => boolean, keySelector?: (x: T) => K): MonoTypeOperatorFunction<T> {\n return (source: Observable<T>) => source.lift(new DistinctUntilChangedOperator<T, K>(compare, keySelector));\n}\n\nclass DistinctUntilChangedOperator<T, K> implements Operator<T, T> {\n constructor(private compare: (x: K, y: K) => boolean,\n private keySelector: (x: T) => K) {\n }\n\n call(subscriber: Subscriber<T>, source: any): TeardownLogic {\n return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass DistinctUntilChangedSubscriber<T, K> extends Subscriber<T> {\n private key: K;\n private hasKey: boolean = false;\n\n constructor(destination: Subscriber<T>,\n compare: (x: K, y: K) => boolean,\n private keySelector: (x: T) => K) {\n super(destination);\n if (typeof compare === 'function') {\n this.compare = compare;\n }\n }\n\n private compare(x: any, y: any): boolean {\n return x === y;\n }\n\n protected _next(value: T): void {\n\n const keySelector = this.keySelector;\n let key: any = value;\n\n if (keySelector) {\n key = tryCatch(this.keySelector)(value);\n if (key === errorObject) {\n return this.destination.error(errorObject.e);\n }\n }\n\n let result: any = false;\n\n if (this.hasKey) {\n result = tryCatch(this.compare)(this.key, key);\n if (result === errorObject) {\n return this.destination.error(errorObject.e);\n }\n } else {\n this.hasKey = true;\n }\n\n if (Boolean(result) === false) {\n this.key = key;\n this.destination.next(value);\n }\n }\n}\n"]}