Skip to content

Commit

Permalink
[added] PropertyObservable
Browse files Browse the repository at this point in the history
Summary:
`ReactiveProperty` is a class, but since JavaScript is duck-typed, we ought to only care that the object conforms to the right shape.  Thus, `PropertyObservable` - the shape that `ReactiveProperty` implements.

I did some experimenting.  You can treat a class as an interface, but the implementor must have an identical shape, [even private members
](http://www.typescriptlang.org/play/index.html#src=class%20Hi%20%7B%0A%20%20private%20_other%20%3D%20true%3B%0A%0A%20%20thing%28%29%3A%20boolean%20%7B%0A%20%20%20%20return%20false%0A%20%20%7D%0A%7D%0A%0A%2F%2F%20%2F%2F%20This%20doesn't%20seem%20to%20matter%0A%2F%2F%20interface%20Hi%20%7B%0A%2F%2F%20%20%20thing%28%29%3A%20boolean%3B%0A%2F%2F%20%7D%0A%0Aclass%20Bye%20implements%20Hi%20%7B%0A%20%20thing%20%3D%20%28%29%20%3D%3E%20true%0A%7D%0A%0Afunction%20doThing%28to%3A%20Hi%29%20%7B%0A%20%20return%20to.thing%28%29%0A%7D%0A%0AdoThing%28new%20Bye%28%29%29%3B).

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

Reviewed By: featherless, O2 Material Motion, #material_motion

Subscribers: featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D2500
  • Loading branch information
appsforartists committed Jan 13, 2017
1 parent ef34ced commit a0963c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 2 additions & 3 deletions packages/experimental-addons/src/TogglableProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import {
} from 'indefinite-observable';

import {
PropertyObservable,
ReactiveProperty,
ScopedReadable,
ScopedWritable,
} from 'material-motion-streams';

export class TogglableProperty<T> implements Observable<T>, ScopedReadable<T>, ScopedWritable<T> {
export class TogglableProperty<T> implements PropertyObservable<T> {
_property = new ReactiveProperty<T>();
_isOn = false;
_onValue: T;
Expand Down
3 changes: 2 additions & 1 deletion packages/streams/src/properties/ReactiveProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import {
} from '../observables/IndefiniteSubject';

import {
PropertyObservable,
ScopedReadable,
ScopedWritable,
} from '../types';

export class ReactiveProperty<T> implements Observable<T>, ScopedReadable<T>, ScopedWritable<T> {
export class ReactiveProperty<T> implements PropertyObservable<T> {
// ReactiveProperty delegates all of its reactive functionality to an internal
// instance of IndefiniteSubject.
//
Expand Down
7 changes: 4 additions & 3 deletions packages/streams/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ export interface ScopedWritable<T> {
write: Write<T>;
}

export interface PropertyObservable<T> extends Observable<T>, ScopedReadable<T>, ScopedWritable<T> {}

export interface MotionElement {
readonly scrollPosition: ScopedReadable<Point2D> & ScopedWritable<Point2D>;
getEvent$(type: string): MotionObservable<Event>;
}

export type SpringArgs<T> = {
destination: ScopedReadable<T>,
initialValue: ScopedReadable<T>,
initialVelocity: ScopedReadable<T>,
destination: PropertyObservable<T>,
initialValue: PropertyObservable<T>,
initialVelocity: PropertyObservable<T>,
threshold: ScopedReadable<number>,
friction: ScopedReadable<number>,
tension: ScopedReadable<number>,
Expand Down

0 comments on commit a0963c0

Please sign in to comment.