Skip to content

Commit

Permalink
[changed] ObservableWithOperators types to interfaces
Browse files Browse the repository at this point in the history
Summary:
The tooltips were not helpful for types because there were so many of them:

someVariable incompatible with MotionOperator1 & MotionOperator2 &…

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

Reviewed By: O2 Material Motion, #material_motion, featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D3132
  • Loading branch information
appsforartists committed May 2, 2017
1 parent d480b70 commit 76f3b77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
17 changes: 7 additions & 10 deletions packages/core/src/operators/foundation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {
Constructor,
Observable,
Operable,
} from '../../types';

import {
Expand Down Expand Up @@ -54,18 +55,14 @@ import {
withRead,
} from './_read';

export type ObservableWithFoundationalMotionOperators<T> = MotionNextOperable<T> & MotionMappable<T>
& MotionFilterable<T> & MotionMemorable<T> & MotionDebounceable<T> & MotionReadable<T>
& MotionFlattenable<T>;
export interface ObservableWithFoundationalMotionOperators<T> extends
MotionNextOperable<T>, MotionMappable<T>, MotionFilterable<T>,
MotionMemorable<T>, MotionDebounceable<T>, MotionReadable<T>,
MotionFlattenable<T> {}

export function withFoundationalMotionOperators<T, S extends Constructor<Observable<T>>>(superclass: S): S
export function withFoundationalMotionOperators<T, S extends Constructor<Observable<T> & Operable<T>>>(superclass: S): S
& Constructor<ObservableWithFoundationalMotionOperators<T>> {
// Not sure if withMap needs to be specialized. Trying results in this error:
// Type 'Constructor<MotionNextOperable<T>> &
// Constructor<MotionMappable<T>>' is not assignable to type 'S &
// Constructor<MotionNextOperable<T>>'.
// Type 'Constructor<MotionNextOperable<T>> &
// Constructor<MotionMappable<T>>' is not assignable to type 'S'.

return withRead(withDebounce(withRemember(withFilter(withMap(
withFlattenIterables(withNextOperator<T, S>(superclass))
)))));
Expand Down
30 changes: 18 additions & 12 deletions packages/core/src/operators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {
Constructor,
Observable,
Operable,
} from '../types';

import {
Expand Down Expand Up @@ -129,23 +130,28 @@ import {
withVelocity,
} from './velocity';

export type ObservableWithMotionOperators<T> = ObservableWithFoundationalMotionOperators<T>
& MotionPluckable<T> & MotionLoggable<T> & MotionDeduplicable<T> & MotionInvertible<T>
& MotionMergeable<T> & MotionRewritable<T> & MotionRewriteToable & MotionRewriteRangeable
& MotionThresholdable & MotionThresholdRangeable & MotionUpperBoundable & MotionLowerBoundable
& MotionOffsetable & MotionScalable & MotionDelayable<T> & MotionMeasurable<T>
& MotionSeedable<T> & MotionIgnorable<T> & MotionWindowable<T> & MotionTimestampable<T>
& MotionVelocityMeasurable<T>;

export function withMotionOperators<T, S extends Constructor<Observable<T>>>(superclass: S): S
export interface ObservableWithMotionOperators<T> extends
ObservableWithFoundationalMotionOperators<T>, MotionPluckable<T>,
MotionLoggable<T>, MotionDeduplicable<T>, MotionInvertible<T>,
MotionMergeable<T>, MotionRewritable<T>, MotionRewriteToable,
MotionRewriteRangeable, MotionThresholdable, MotionThresholdRangeable,
MotionUpperBoundable, MotionLowerBoundable, MotionOffsetable, MotionScalable,
MotionDelayable<T>, MotionMeasurable<T>, MotionSeedable<T>,
MotionIgnorable<T>, MotionWindowable<T>, MotionTimestampable<T>,
MotionVelocityMeasurable<T> {}

export function withMotionOperators<T, S extends Constructor<Observable<T> & Operable<T>>>(superclass: S): S
& Constructor<ObservableWithMotionOperators<T>> {

// TypeScript seems to dislike returning this function. Calling the functions
// themselves in a constant works fine (except it gets mad about the Ts being
// incompatible for some combinations);
return withThresholdRange(withThreshold(withRewriteRange(withRewriteTo(withRewrite(
withMerge(withInverted(withDedupe(withLog(withUpperBound(withLowerBound(
withOffsetBy(withScaledBy(withDelayBy(withDistanceFrom(withStartWith(
withIgnoreUntil(withSlidingWindow(withTimestamp(withVelocity(
withPluck<T, Constructor<ObservableWithFoundationalMotionOperators<T>>>(
withFoundationalMotionOperators<T, Constructor<Observable<T>>>(superclass)
withIgnoreUntil(withVelocity(withSlidingWindow(withTimestamp(
withPluck(
withFoundationalMotionOperators<T, S>(superclass)
)
))))
)))))
Expand Down

0 comments on commit 76f3b77

Please sign in to comment.