-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gareth Whittaker
committed
Feb 5, 2017
0 parents
commit 6222c87
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Observable } from 'rxjs/Observable' | ||
import { Subject } from 'rxjs/Subject' | ||
import { animationFrame } from 'rxjs/scheduler/animationFrame' | ||
import 'rxjs/add/observable/of' | ||
import 'rxjs/add/observable/never' | ||
import 'rxjs/add/operator/repeat' | ||
import 'rxjs/add/operator/switchMap' | ||
|
||
const animationLoop = () => { | ||
const frame = Observable | ||
.of(null, animationFrame) | ||
.repeat() | ||
|
||
const noop = Observable.never() | ||
|
||
const loop = new Subject() | ||
.switchMap((active) => active ? frame : noop) | ||
|
||
return { | ||
start() { | ||
loop.next(true) | ||
}, | ||
|
||
stop() { | ||
loop.next(false) | ||
}, | ||
|
||
subscribe(observer) { | ||
return loop.subscribe(observer) | ||
} | ||
} | ||
} | ||
|
||
export { animationLoop } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "rxjs-animation-loop", | ||
"version": "0.1.0", | ||
"description": "This module provides a game / animation loop based upon requestAnimationFrame.", | ||
"author": "Gareth Whittaker <[email protected]>", | ||
"main": "animation-loop.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/garethwhittaker/rxjs-animation-loop" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/garethwhittaker/rxjs-animation-loop/issues" | ||
}, | ||
"keywords": [ | ||
"animation loop", | ||
"game loop", | ||
"animationframe", | ||
"requestanimationframe" | ||
], | ||
"dependencies": { | ||
"rxjs": "5.1.0" | ||
}, | ||
"license": "MIT" | ||
} |