Skip to content

Instantly share code, notes, and snippets.

@eplawless
Last active August 24, 2016 06:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eplawless/d5a79021999413c187ea to your computer and use it in GitHub Desktop.
Save eplawless/d5a79021999413c187ea to your computer and use it in GitHub Desktop.
function NOOP() {}
var button = getSomeButtonSomehow();
// all of these Animation objects are immutable, and just describe the motion
var moveRight = Animate.positionX({ from: 0, to: 100, ease: Easing.easeOut, duration: 200 });
var moveDown = Animate.positionY({ from: 0, to: 100, ease: Easing.easeOut, duration: 200 });
var fadeOut = Animate.opacity({ to: 0, ease: Easing.cubicBezier(0,1,1,0), duration: 50 });
var move = moveRight.with(moveDown, 100); // start moveDown 100ms after moveRight starts
var reusableAnimation = move.then(fadeOut, -fadeOut.duration); // start fadeOut 50ms before move ends
var targetedAnimation = reusableAnimation.target(button);
targetedAnimation
.toObservable()
.takeUntil(somethingTerribleHappens)
.subscribe(NOOP, NOOP, button.destroy.bind(button));
@eplawless
Copy link
Author

Much of this API is hand-waved but we've explored the pattern pretty deeply and it's very effective. Observables are trickier to use for this because you can't really encode the duration, which means a.then(b, -100) is much harder to pull off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment