Skip to content

Commit

Permalink
feat(rstream): add tweenNumber()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 11, 2019
1 parent b5da3b2 commit 17d0fdb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/rstream/src/tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,28 @@ export const tween = <T>(
scan(reducer(() => initial, (acc, { src }) => mix(acc, src))),
dedupe(stop || (() => false))
);

/**
* Convenience version of `tween` for its most common use case, tweening
* of numeric streams.
*
* @param src
* @param init
* @param speed
* @param eps
* @param clock
*/
export const tweenNumber = (
src: ISubscribable<number>,
init = 0,
speed = 0.05,
eps = 1e-3,
clock?: ISubscribable<any> | number
) =>
tween<number>(
src,
init,
(a, b) => a + (b - a) * speed,
(a, b) => Math.abs(a - b) < eps,
clock
);

0 comments on commit 17d0fdb

Please sign in to comment.