Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Whittaker committed Feb 5, 2017
0 parents commit 6222c87
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
34 changes: 34 additions & 0 deletions animation-loop.js
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 }
24 changes: 24 additions & 0 deletions package.json
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"
}

0 comments on commit 6222c87

Please sign in to comment.