Skip to content

Instantly share code, notes, and snippets.

@paldepind
Created March 16, 2017 13:38
Show Gist options
  • Save paldepind/81aa21be706737528d04226040ac4c00 to your computer and use it in GitHub Desktop.
Save paldepind/81aa21be706737528d04226040ac4c00 to your computer and use it in GitHub Desktop.
Player timeline implemented in Funnel
const model = (animation: Animation) => fgo(function* model({ playPauseS, replayS }: ToModel) {
const playingB: Behavior<boolean> = yield sample(scan((_, b) => !b, false, playPauseS));
const playingSpeedB = map((b) => b ? 1 : 0, playingB);
const initialTimeB = yield sample(integrate(playingSpeedB));
const positionB = yield sample(switcher(initialTimeB, snapshot(integrate(playingSpeedB), replayS)));
return [{ positionB, playingB }, {}];
});
const view = ({ playingB, positionB }: ToView): any => [
button({output: {click: "playPauseS"}}, icon(playingB.map((b) => b ? "pause" : "play_arrow"))),
button({output: {click: "replayS"}}, icon("replay")),
slider({ position: positionB })
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment