Skip to content

Commit

Permalink
[added] createProperty
Browse files Browse the repository at this point in the history
Summary:
As specified in https://material-motion.github.io/material-motion/starmap/specifications/streams/connections/ReactiveProperty-createProperty

I was a little torn on whether or not I should implement `constantProperty` in terms of `createProperty` or just remove it.  The difference is only in the signature (does it take named args or not), unless you wanted to throw in `constantProperty().write()`.

Removing `constantProperty` seemed like the simplest and most consistent solution.

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

Reviewed By: #material_motion, O2 Material Motion, featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D2499
  • Loading branch information
appsforartists committed Jan 13, 2017
1 parent e495203 commit ef34ced
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {

import {
State,
constantProperty,
createProperty,
} from 'material-motion-streams';

import {
Expand Down Expand Up @@ -62,8 +62,8 @@ describe('springSource',
it('transitions from initialValue to destination',
() => {
springSource({
initialValue: constantProperty(2),
destination: constantProperty(3),
initialValue: createProperty({ initialValue: 2 }),
destination: createProperty({ initialValue: 3 }),
}).subscribe(listener);

expect(listener.firstCall).to.have.been.calledWith(2);
Expand All @@ -77,8 +77,8 @@ describe('springSource',
let firstNextTime;

springSource({
initialValue: constantProperty(0),
destination: constantProperty(0),
initialValue: createProperty({ initialValue: 0 }),
destination: createProperty({ initialValue: 0 }),
}).subscribe({
next(value) {},
state: listener
Expand All @@ -95,8 +95,8 @@ describe('springSource',
let tested;

const spring = springSource({
initialValue: constantProperty(0),
destination: constantProperty(1),
initialValue: createProperty({ initialValue: 0 }),
destination: createProperty({ initialValue: 1 }),
});

const subscription = spring.subscribe({
Expand All @@ -122,8 +122,8 @@ describe('springSource',
let tested;

const spring = springSource({
initialValue: constantProperty(0),
destination: constantProperty(1),
initialValue: createProperty({ initialValue: 0 }),
destination: createProperty({ initialValue: 1 }),
});

const subscription = spring.subscribe({
Expand Down
10 changes: 5 additions & 5 deletions packages/springs-adaptor-rebound/src/springSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
MotionObserver,
SpringArgs,
State,
constantProperty,
createProperty,
} from 'material-motion-streams';

import {
Expand Down Expand Up @@ -66,9 +66,9 @@ export function springSource<T extends number | NumericDict>({
//
// tension: property.startWith(defaultTension).read()
initialVelocity,
threshold = constantProperty(Number.EPSILON),
tension = constantProperty(342),
friction = constantProperty(30),
threshold = createProperty({ initialValue: Number.EPSILON }),
tension = createProperty({ initialValue: 342 }),
friction = createProperty({ initialValue: 30 }),
}: SpringArgs<T>) {
const firstInitialValue = initialValue.read();

Expand All @@ -92,7 +92,7 @@ export default springSource;
function numericSpringSource({
destination,
initialValue,
initialVelocity = constantProperty(0),
initialVelocity = createProperty({ initialValue: 0 }),
threshold,
tension,
friction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
* under the License.
*/

import {
ScopedReadable,
} from '../types';
import ReactiveProperty from './ReactiveProperty';

export function constantProperty<T>(value: T): ScopedReadable<T> {
return {
read: () => value,
};
};
export default constantProperty;
export function createProperty<T>({ initialValue }: { initialValue?: T} = {}): ReactiveProperty<T> {
const result = new ReactiveProperty<T>();

if (initialValue !== undefined) {
result.write(initialValue);
}

return result;
}
export default createProperty;
4 changes: 2 additions & 2 deletions packages/streams/src/properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
export * from './ReactiveProperty';
export { default as ReactiveProperty } from './ReactiveProperty';

export * from './constantProperty';
export { default as constantProperty } from './constantProperty';
export * from './createProperty';
export { default as createProperty } from './createProperty';

export default undefined;

0 comments on commit ef34ced

Please sign in to comment.