Skip to content

Commit 74b5b1a

Browse files
committed
refactor(groupBy): Remove Map polyfill
- Removes Map polyfill - Removes FastMap impl - Tests in latest Chrome and Node show no discernable difference in performance between Map<string, T> and Object has a hashtable for our use case. - Adds an error that is thrown immediately at runtime if Map does not exist. BREAKING CHANGE: Older runtimes will require Map to be polyfilled to use `groupBy`
1 parent 0f3cf71 commit 74b5b1a

File tree

6 files changed

+6
-239
lines changed

6 files changed

+6
-239
lines changed

spec/util/FastMap-spec.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

spec/util/MapPolyfill-spec.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/operators/groupBy.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { Subscription } from '../Subscription';
33
import { Observable } from '../Observable';
44
import { Operator } from '../Operator';
55
import { Subject } from '../Subject';
6-
import { Map } from '../util/Map';
7-
import { FastMap } from '../util/FastMap';
86
import { OperatorFunction } from '../interfaces';
97

8+
/** Assert that map is present for this operator */
9+
if (!Map) {
10+
throw new Error('Map not found, please polyfill');
11+
}
12+
1013
/* tslint:disable:max-line-length */
1114
export function groupBy<T, K>(keySelector: (value: T) => K): OperatorFunction<T, GroupedObservable<K, T>>;
1215
export function groupBy<T, K>(keySelector: (value: T) => K, elementSelector: void, durationSelector: (grouped: GroupedObservable<K, T>) => Observable<any>): OperatorFunction<T, GroupedObservable<K, T>>;
@@ -144,7 +147,7 @@ class GroupBySubscriber<T, K, R> extends Subscriber<T> implements RefCountSubscr
144147
let groups = this.groups;
145148

146149
if (!groups) {
147-
groups = this.groups = typeof key === 'string' ? new FastMap() : new Map();
150+
groups = this.groups = new Map<K, Subject<T|R>>();
148151
}
149152

150153
let group = groups.get(key);

src/util/FastMap.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/util/Map.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/util/MapPolyfill.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)