Skip to content

Commit

Permalink
refactor(groupBy): Remove Map polyfill
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
benlesh committed Nov 3, 2017
1 parent 0f3cf71 commit 74b5b1a
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 239 deletions.
81 changes: 0 additions & 81 deletions spec/util/FastMap-spec.ts

This file was deleted.

78 changes: 0 additions & 78 deletions spec/util/MapPolyfill-spec.ts

This file was deleted.

9 changes: 6 additions & 3 deletions src/operators/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { Subscription } from '../Subscription';
import { Observable } from '../Observable';
import { Operator } from '../Operator';
import { Subject } from '../Subject';
import { Map } from '../util/Map';
import { FastMap } from '../util/FastMap';
import { OperatorFunction } from '../interfaces';

/** Assert that map is present for this operator */
if (!Map) {
throw new Error('Map not found, please polyfill');
}

/* tslint:disable:max-line-length */
export function groupBy<T, K>(keySelector: (value: T) => K): OperatorFunction<T, GroupedObservable<K, T>>;
export function groupBy<T, K>(keySelector: (value: T) => K, elementSelector: void, durationSelector: (grouped: GroupedObservable<K, T>) => Observable<any>): OperatorFunction<T, GroupedObservable<K, T>>;
Expand Down Expand Up @@ -144,7 +147,7 @@ class GroupBySubscriber<T, K, R> extends Subscriber<T> implements RefCountSubscr
let groups = this.groups;

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

let group = groups.get(key);
Expand Down
30 changes: 0 additions & 30 deletions src/util/FastMap.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/util/Map.ts

This file was deleted.

43 changes: 0 additions & 43 deletions src/util/MapPolyfill.ts

This file was deleted.

0 comments on commit 74b5b1a

Please sign in to comment.