From ce137028e07c1f066cdc642809ca339d80bee640 Mon Sep 17 00:00:00 2001 From: Pat Sissons Date: Tue, 1 Aug 2017 20:54:22 -0700 Subject: [PATCH] adding IxJS augmentation to fix bug see: https://github.com/Reactive-Extensions/IxJS/issues/22 --- src/types/augmentations.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/types/augmentations.ts b/src/types/augmentations.ts index 17ee0c90..692aadd1 100644 --- a/src/types/augmentations.ts +++ b/src/types/augmentations.ts @@ -1,3 +1,34 @@ // tslint:disable:no-unused-variable -// currently there are no augmenatations +import { Enumerable, OrderedEnumerable, Comparer } from 'ix'; + +// we want to reuse the createOrderedEnumerable that comes with OrderedEnumerable +interface OrderedEnumerablePrototype extends OrderedEnumerable { + createOrderedEnumerable(keySelector: (item: T) => TKey, comparer: Comparer | undefined, descending: boolean): OrderedEnumerable; +} + +// reach in and grab the OrderedEnumerable prototype by creating an ordered enumerable +const orderedEnumerablePrototype: OrderedEnumerablePrototype = (Enumerable) + .empty() + .orderBy(undefined) + .__proto__ + .constructor + .prototype; + +function thenBy( + this: OrderedEnumerablePrototype, + keySelector: (item: T) => TKey, + comparer?: Comparer, +) { + return this.createOrderedEnumerable(keySelector, comparer, false); +} +orderedEnumerablePrototype.thenBy = thenBy; + +function thenByDescending( + this: OrderedEnumerablePrototype, + keySelector: (item: T) => TKey, + comparer?: Comparer, +) { + return this.createOrderedEnumerable(keySelector, comparer, true); +} +orderedEnumerablePrototype.thenByDescending = thenByDescending;