Skip to content

Commit

Permalink
[refactored] appendUnit to have shorthand signature
Browse files Browse the repository at this point in the history
Summary: Part of #230

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

Reviewed By: #material_motion, vietanh

Tags: #material_motion

Differential Revision: http://codereview.cc/D3426
  • Loading branch information
appsforartists committed Oct 11, 2017
1 parent 80b1264 commit a6898e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/core/src/operators/__tests__/appendUnit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,15 @@ describe('motionObservable.appendUnit',
expect(listener).to.have.been.calledOnce.and.to.have.been.calledWith('50px');
}
);

it('should have a shorthand signature',
() => {
stream.appendUnit('px').subscribe(listener);

mockObserver.next(50);

expect(listener).to.have.been.calledOnce.and.to.have.been.calledWith('50px');
}
);
}
);
13 changes: 12 additions & 1 deletion packages/core/src/operators/appendUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ import {
ObservableWithMotionOperators,
} from '../types';

import {
isDefined,
} from '../typeGuards';

export type AppendUnitArgs = {
unit: string,
}

export interface MotionAppendUnitable {
appendUnit(unit: string): ObservableWithMotionOperators<string>;
appendUnit(kwargs: AppendUnitArgs): ObservableWithMotionOperators<string>;
}

Expand All @@ -34,7 +39,13 @@ export function withAppendUnit<T, S extends Constructor<MotionMappable<T>>>(supe
* Converts a stream to a CSS string representation by appending the given
* unit to the upstream values.
*/
appendUnit({ unit }: AppendUnitArgs): ObservableWithMotionOperators<string> {
appendUnit(unit: string): ObservableWithMotionOperators<string>;
appendUnit(kwargs: AppendUnitArgs): ObservableWithMotionOperators<string>;
appendUnit({ unit }: AppendUnitArgs & string): ObservableWithMotionOperators<string> {
if (!isDefined(unit)) {
unit = arguments[0];
}

return this._map({
transform: (value: T) => value + unit
});
Expand Down

0 comments on commit a6898e3

Please sign in to comment.