Skip to content

Commit

Permalink
[refactored] dedupe to use named args
Browse files Browse the repository at this point in the history
Summary: Continuation of #193

Reviewers: O2 Material Motion, O3 Material JavaScript platform reviewers, #material_motion, vietanh

Reviewed By: #material_motion, vietanh

Subscribers: vietanh

Tags: #material_motion

Differential Revision: http://codereview.cc/D3408
  • Loading branch information
appsforartists committed Oct 11, 2017
1 parent 33bde2e commit 2d8892f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/operators/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ import {
ObservableWithMotionOperators,
} from '../types';

export type DedupeArgs = {
areEqual?: EqualityCheck,
};

export interface MotionDeduplicable<T> {
dedupe(areEqual?: EqualityCheck): ObservableWithMotionOperators<T>;
dedupe(kwargs?: DedupeArgs): ObservableWithMotionOperators<T>;
}

export function withDedupe<T, S extends Constructor<ObservableWithFoundationalMotionOperators<T>>>(superclass: S): S & Constructor<MotionDeduplicable<T>> {
return class extends superclass implements MotionDeduplicable<T> {
/**
* Ensures that every value dispatched is different than the previous one.
*/
dedupe(areEqual: EqualityCheck = deepEqual): ObservableWithMotionOperators<T> {
dedupe({ areEqual = deepEqual } = {}): ObservableWithMotionOperators<T> {
return this._nextOperator({
operation({ emit }) {
let emitted = false;
Expand Down

0 comments on commit 2d8892f

Please sign in to comment.