-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(distinct): remove
distinctKey
, distinct
signature change and…
… perf improvements (#2049) * feat(distinct): remove `distinctKey`, `distinct` signature change and perf improvements - Adds a limited Set ponyfill for runtimes that do not support `Set` - `distinct` now supports an optional keySelector argument that the user can use to select the value to check distinct on - `distinctKey` is removed as it is redundant - `distinct` no longer supports a comparer function argument, as there is little to no use case for such an argument that could not be covered by the keySelector - updates tests to remove tests that do not make sense and test new functionality BREAKING CHANGE: `distinctKey` has been removed. Use `distinct` BREAKING CHANGE: `distinct` operator has changed, first argument is an optional `keySelector`. The custom `compare` function is no longer supported. resolves #2009 * perf(distinct): increase `distinct()` perf by improving deopts - moves keySelector call to a different function with a try catch to improve V8 optimization - distinct calls with no keySelector passed now take a fully optimized path, doubling speed again related #2009 * docs(distinct): update distinct docs to fit new API
- Loading branch information
Showing
7 changed files
with
156 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {expect} from 'chai'; | ||
import { Set as TestSet, minimalSetImpl } from '../../dist/cjs/util/Set'; | ||
|
||
describe('Set', () => { | ||
if (typeof Set === 'function') { | ||
it('should use Set if Set exists', () => { | ||
expect(TestSet).to.equal(Set); | ||
}); | ||
} | ||
}); | ||
|
||
describe('minimalSetImpl()', () => { | ||
it('should provide the minimal Set we require', () => { | ||
const MinSet = minimalSetImpl(); | ||
const test = new MinSet(); | ||
|
||
expect(MinSet.prototype.add).to.be.a('function'); | ||
expect(MinSet.prototype.has).to.be.a('function'); | ||
expect(MinSet.prototype.clear).to.be.a('function'); | ||
expect(test.size).to.be.a('number'); | ||
}); | ||
|
||
describe('returned MinimalSet', () => { | ||
it('should implement add, has, size and clear', () => { | ||
const MinSet = minimalSetImpl(); | ||
const test = new MinSet(); | ||
|
||
expect(test.size).to.equal(0); | ||
|
||
test.add('Laverne'); | ||
expect(test.size).to.equal(1); | ||
expect(test.has('Laverne')).to.be.true; | ||
expect(test.has('Shirley')).to.be.false; | ||
|
||
test.add('Shirley'); | ||
expect(test.size).to.equal(2); | ||
expect(test.has('Laverne')).to.be.true; | ||
expect(test.has('Shirley')).to.be.true; | ||
|
||
const squiggy = { name: 'Andrew Squiggman' }; | ||
const identicalSquiggy = { name: 'Andrew Squiggman' }; // lol, imposter! | ||
|
||
test.add(squiggy); | ||
expect(test.size).to.equal(3); | ||
expect(test.has(identicalSquiggy)).to.be.false; | ||
expect(test.has(squiggy)).to.be.true; | ||
|
||
test.clear(); | ||
expect(test.size).to.equal(0); | ||
expect(test.has('Laverne')).to.be.false; | ||
expect(test.has('Shirley')).to.be.false; | ||
expect(test.has(squiggy)).to.be.false; | ||
expect(test.has(identicalSquiggy)).to.be.false; | ||
|
||
test.add('Fonzi'); | ||
expect(test.size).to.equal(1); | ||
expect(test.has('Fonzi')).to.be.true; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
89612b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed
src/add/operator/distinctKey.ts
#2161 (comment)
89612b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to fix #2162