Skip to content

Commit

Permalink
[upgraded] to TypeScript 2.4
Browse files Browse the repository at this point in the history
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/D3256
  • Loading branch information
appsforartists committed Jul 28, 2017
1 parent b1049fc commit 3ebb839
Show file tree
Hide file tree
Showing 16 changed files with 423 additions and 300 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"sinon-chai": "2.9.0",
"ts-loader": "2.0.3",
"tslint": "4.5.1",
"typescript": "2.3",
"typescript": "2.4",
"webpack": "2.3.1"
}
}
8 changes: 4 additions & 4 deletions packages/core/src/Axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* under the License.
*/

export const Axis = {
X: 'x',
Y: 'y',
ALL: 'all',
export enum Axis {
X = 'x',
Y = 'y',
ALL = 'all',
};
export default Axis;
16 changes: 8 additions & 8 deletions packages/core/src/GestureRecognitionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* under the License.
*/

export const GestureRecognitionState = {
POSSIBLE: 'possible',
BEGAN: 'began',
CHANGED: 'changed',
ENDED: 'ended',
RECOGNIZED: 'ended',
CANCELLED: 'cancelled',
FAILED: 'failed',
export enum GestureRecognitionState {
POSSIBLE = 'possible',
BEGAN = 'began',
CHANGED = 'changed',
ENDED = 'ended',
RECOGNIZED = 'ended',
CANCELLED = 'cancelled',
FAILED = 'failed',
};

export default GestureRecognitionState;
6 changes: 3 additions & 3 deletions packages/core/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* under the License.
*/

export const State = {
AT_REST: 'at_rest',
ACTIVE: 'active',
export enum State {
AT_REST = 'at_rest',
ACTIVE = 'active',
};
export default State;
8 changes: 4 additions & 4 deletions packages/core/src/ThresholdSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* under the License.
*/

export const ThresholdSide = {
ABOVE: 'above',
WITHIN: 'within',
BELOW: 'below',
export enum ThresholdSide {
ABOVE = 'above',
WITHIN = 'within',
BELOW = 'below',
};
export default ThresholdSide;
17 changes: 7 additions & 10 deletions packages/core/src/interactions/Draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@ import {
} from '../GestureRecognitionState';

export class Draggable {
// TODO: type this to be the values in the State enum
readonly state$: MotionProperty<string> = createProperty<string>({
readonly state$: MotionProperty<State> = createProperty<State>({
initialValue: State.AT_REST,
});

get state(): string {
get state(): State {
return this.state$.read();
}

// TODO: type this to be the values in the GestureRecognitionState enum
readonly recognitionState$: MotionProperty<string> = createProperty<string>({
readonly recognitionState$: MotionProperty<GestureRecognitionState> = createProperty<GestureRecognitionState>({
initialValue: GestureRecognitionState.POSSIBLE,
});

get recognitionState(): string {
get recognitionState(): GestureRecognitionState {
return this.recognitionState$.read();
}

Expand All @@ -76,16 +74,15 @@ export class Draggable {
this.recognitionThreshold$.write(value);
}

// TODO: type this to be the values in the Axis enum
readonly axis$: MotionProperty<string> = createProperty<string>({
readonly axis$: MotionProperty<Axis> = createProperty<Axis>({
initialValue: Axis.ALL,
});

get axis(): string {
get axis(): Axis {
return this.axis$.read();
}

set axis(value: string) {
set axis(value: Axis) {
this.axis$.write(value);
}

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/interactions/NumericSpring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
MotionProperty,
} from '../observables/MotionProperty';

import {
State,
} from '../State';

import {
ObservableWithMotionOperators,
} from '../types';
Expand Down Expand Up @@ -57,8 +61,8 @@ export interface NumericSpring {
readonly enabled$: MotionProperty<boolean>;
enabled: boolean;

readonly state$: MotionProperty<string>;
readonly state: string;
readonly state$: MotionProperty<State>;
readonly state: State;

value$: ObservableWithMotionOperators<number>;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/interactions/Tossable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ export type TossableArgs = {
};

export class Tossable {
// TODO: type this to be the values in the State enum
readonly state$: MotionProperty<string> = createProperty<string>({
readonly state$: MotionProperty<State> = createProperty<State>({
initialValue: State.AT_REST,
});

get state(): string {
get state(): State {
return this.state$.read();
}

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/observables/IndefiniteSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
Subscription,
} from 'indefinite-observable';

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

import {
MemorylessIndefiniteSubject,
} from './MemorylessIndefiniteSubject';
Expand Down Expand Up @@ -59,7 +63,7 @@ export class IndefiniteSubject<T> extends MemorylessIndefiniteSubject<T> {
const subscription = super.subscribe(observerOrNext);

if (this._hasStarted) {
observerOrNext.next
isObserver(observerOrNext)
? observerOrNext.next(this._lastValue)
: observerOrNext(this._lastValue);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/operators/offsetBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface MotionOffsetable<T> {
offsetBy(offset$: T | Observable<T>): ObservableWithMotionOperators<T>;
}

export function withOffsetBy<T, S extends Constructor<MotionReactiveMappable<T>>>(superclass: S): S & Constructor<MotionOffsetable> {
export function withOffsetBy<T, S extends Constructor<MotionReactiveMappable<T>>>(superclass: S): S & Constructor<MotionOffsetable<T>> {
return class extends superclass implements MotionOffsetable<T> {
/**
* Adds the offset to the incoming value and dispatches the result.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/operators/slidingWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {
Constructor,
MotionNextOperable,
NextChannel,
Observable,
ObservableWithMotionOperators,
Observer,
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/operators/threshold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ export function withThreshold<T, S extends Constructor<MotionMappable<T>>>(super
threshold(limit: number): ObservableWithMotionOperators<ThresholdSide> {
return (this as any as ObservableWithMotionOperators<number>)._map(
(value: number) => {
if (value === limit) {
return ThresholdSide.WITHIN;

} else if (value < limit) {
if (value < limit) {
return ThresholdSide.BELOW;

} else if (value > limit) {
return ThresholdSide.ABOVE;
} else {
return ThresholdSide.WITHIN;
}
}
);
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import $$observable from 'symbol-observable';

import {
Observable,
Observer,
Point2D,
} from './types';

Expand Down Expand Up @@ -57,6 +58,14 @@ export function isPoint2D(value: any): value is Point2D {
return typeof value.x === 'number' && typeof value.y === 'number';
}

/**
* Checks if a value is an `Observer` by checking if the value has a `next`
* method.
*/
export function isObserver<T = any>(value: any): value is Observer<T> {
return typeof value.next === 'function';
}

/**
* Checks if a value is a `PointerEvent` by checking if the value is an `Event`
* whose `type` starts with `pointer`.
Expand Down
3 changes: 2 additions & 1 deletion packages/testing-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build": "yarn run clean; ../../node_modules/.bin/tsc"
},
"dependencies": {
"mock-raf": "^1.0.0"
"mock-raf": "^1.0.0",
"tslib": "^1.2.0"
},
"peerDependencies": {
"mocha-sugar-free": "1.3.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/testing-utils/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# yarn lockfile v1


"@types/sinon@^1.16.34":
version "1.16.36"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-1.16.36.tgz#74bb6ed7928597c1b3fb1b009005e94dc6eae357"

mock-raf@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/mock-raf/-/mock-raf-1.0.0.tgz#a288145178893e2040b230f2182fee2049f16f25"
Expand All @@ -11,3 +15,7 @@ mock-raf@^1.0.0:
object-assign@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2"

tslib@^1.2.0:
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"
Loading

0 comments on commit 3ebb839

Please sign in to comment.