Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Add distinctValues #11

Merged
merged 2 commits into from Sep 7, 2018
Merged

Add distinctValues #11

merged 2 commits into from Sep 7, 2018

Conversation

amaury1093
Copy link
Collaborator

So that RpcObservables don't fire again when the value didn't change.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 99

  • 13 of 13 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.5%) to 46.301%

Totals Coverage Status
Change from base Build 97: 0.5%
Covered Lines: 810
Relevant Lines: 1749

💛 - Coveralls

@amaury1093 amaury1093 merged commit d2d7cd7 into master Sep 7, 2018
@amaury1093 amaury1093 deleted the am-fix-lightjs branch September 7, 2018 13:04
*/
export const distinctValues = <T>() =>
distinctUntilChanged<T>((x, y) => {
if (x instanceof BigNumber && y instanceof BigNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see MikeMcl/bignumber.js#111
related: parity-js/ui#8 (comment)

It would be safer to use BigNumber.isBigNumber(x) && BigNumber.isBigNumber(y) (https://mikemcl.github.io/bignumber.js/#isBigNumber)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right! Thanks, I'll change it asap

import { distinctValues } from './distinctValues';

// Observable that fires 2 times
const fireTwice$ = () => concat(of(0), of(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be the same as () => of(0, 1); ?

.subscribe(() => {
++numberOfTimesCalled;
});
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use

.finalize(() => {
      expect(numberOfTimesCalled).toEqual(1);
      done();
}

* @param value - A value to test
*/
const testValue = (value: any, type: string) =>
it('should only fire once for `type`', done => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

`should only fire once for ${type}`

testValue({ foo: 'bar' }, 'object');
testValue(new BigNumber(2), 'BigNumber');

it('should only fire twice for difference values', done => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo different

fireTwice$().subscribe(() => {
++numberOfTimesCalled;
});
setTimeout(() => {
Copy link
Contributor

@axelchalon axelchalon Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can also use finalize here I think

axelchalon added a commit that referenced this pull request Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants