Skip to content

Commit

Permalink
[refactored] appendUnit 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/D3409
  • Loading branch information
appsforartists committed Oct 11, 2017
1 parent 2d8892f commit 888f3df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/operators/__tests__/appendUnit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('motionObservable.appendUnit',

it('should append the given unit to the upstream values',
() => {
stream.appendUnit('px').subscribe(listener);
stream.appendUnit({ unit: 'px' }).subscribe(listener);

mockObserver.next(50);

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/operators/appendUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import {
ObservableWithMotionOperators,
} from '../types';

export type AppendUnitArgs = {
unit: string,
}

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

export function withAppendUnit<T, S extends Constructor<MotionMappable<T>>>(superclass: S): S & Constructor<MotionAppendUnitable> {
Expand All @@ -30,7 +34,7 @@ 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: string): ObservableWithMotionOperators<string> {
appendUnit({ unit }: AppendUnitArgs): ObservableWithMotionOperators<string> {
return this._map({
transform: (value: T) => value + unit
});
Expand Down

0 comments on commit 888f3df

Please sign in to comment.