Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1 @@
node_modules/

View File

@@ -0,0 +1,83 @@
# raf
[![Browser Support](http://ci.testling.com/chrisdickinson/raf.png)](http://ci.testling.com/chrisdickinson/raf)
requestAnimationFrame polyfill for node and the browser.
```js
var raf = require('raf')
raf(function tick() {
// Animation logic
raf(tick)
})
```
**Note:** The stream/event emitter logic found in versions prior to 1.0.0 can be found in [raf-stream](https://www.npmjs.org/package/raf-stream).
## Getting started
### CommonJS (Node, Browserify, Webpack, etc.)
Install `raf` from npm:
```bash
npm install --save raf
```
Require it like you would any other module:
```js
const raf = require('raf')
```
### AMD (require.js, etc)
Download the UMD-bundle from [wzrd.in](https://wzrd.in/standalone/raf@latest) (remember to include the current version number in the filename).
Add it to your AMD module loader config and require it like you would any other module:
```html
define(['raf'], raf => {...})
```
### `<script>`
Download the UMD-bundle from [wzrd.in](https://wzrd.in/standalone/raf@latest) (remember to include the current version number in the filename).
Then include it via a script tag:
```html
<script src="raf-x.x.x.js"></script>
```
The API will be available on `window.raf`.
## API
[Documentation at Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame), [W3 Specification](http://www.w3.org/TR/animation-timing/#requestAnimationFrame)
### var handle = raf(callback)
`callback` is the function to invoke in the next frame. `handle` is a long integer value that uniquely identifies the entry in the callback list. This is a non-zero value, but you may not make any other assumptions about its value.
### raf.cancel(handle)
`handle` is the entry identifier returned by `raf()`. Removes the queued animation frame callback (other queued callbacks will still be invoked unless cancelled).
### raf.polyfill([object])
Shorthand to polyfill `window.requestAnimationFrame` and `window.cancelAnimationFrame` if necessary (Polyfills `global` in node).
Alternatively you can require `raf/polyfill` which will act the same as `require('raf').polyfill()`.
If you provide `object` the polyfills are attached to that given object, instead of the inferred global.
Useful if you have an instance of a fake `window` object, and want to add `raf` and `caf` to it.
## Acknowledgments
Based on work by Erik Möller, Paul Irish, and Tino Zijdel (https://gist.github.com/paulirish/1579671)
## License
MIT

View File

@@ -0,0 +1,75 @@
var now = require('performance-now')
, root = typeof window === 'undefined' ? global : window
, vendors = ['moz', 'webkit']
, suffix = 'AnimationFrame'
, raf = root['request' + suffix]
, caf = root['cancel' + suffix] || root['cancelRequest' + suffix]
for(var i = 0; !raf && i < vendors.length; i++) {
raf = root[vendors[i] + 'Request' + suffix]
caf = root[vendors[i] + 'Cancel' + suffix]
|| root[vendors[i] + 'CancelRequest' + suffix]
}
// Some versions of FF have rAF but not cAF
if(!raf || !caf) {
var last = 0
, id = 0
, queue = []
, frameDuration = 1000 / 60
raf = function(callback) {
if(queue.length === 0) {
var _now = now()
, next = Math.max(0, frameDuration - (_now - last))
last = next + _now
setTimeout(function() {
var cp = queue.slice(0)
// Clear queue here to prevent
// callbacks from appending listeners
// to the current frame's queue
queue.length = 0
for(var i = 0; i < cp.length; i++) {
if(!cp[i].cancelled) {
try{
cp[i].callback(last)
} catch(e) {
setTimeout(function() { throw e }, 0)
}
}
}
}, Math.round(next))
}
queue.push({
handle: ++id,
callback: callback,
cancelled: false
})
return id
}
caf = function(handle) {
for(var i = 0; i < queue.length; i++) {
if(queue[i].handle === handle) {
queue[i].cancelled = true
}
}
}
}
module.exports = function(fn) {
// Wrap in a new function to prevent
// `cancel` potentially being assigned
// to the native rAF function
return raf.call(root, fn)
}
module.exports.cancel = function() {
caf.apply(root, arguments)
}
module.exports.polyfill = function(object) {
if (!object) {
object = root;
}
object.requestAnimationFrame = raf
object.cancelAnimationFrame = caf
}

View File

@@ -0,0 +1,86 @@
{
"_args": [
[
"raf@3.4.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "raf@3.4.0",
"_id": "raf@3.4.0",
"_inBundle": false,
"_integrity": "sha512-pDP/NMRAXoTfrhCfyfSEwJAKLaxBU9eApMeBPB1TkDouZmvPerIClV8lTAd+uF8ZiTaVl69e1FCxQrAd/VTjGw==",
"_location": "/react-scripts/raf",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "raf@3.4.0",
"name": "raf",
"escapedName": "raf",
"rawSpec": "3.4.0",
"saveSpec": null,
"fetchSpec": "3.4.0"
},
"_requiredBy": [
"/react-scripts"
],
"_resolved": "https://registry.npmjs.org/raf/-/raf-3.4.0.tgz",
"_spec": "3.4.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Chris Dickinson",
"email": "chris@neversaw.us"
},
"bugs": {
"url": "https://github.com/chrisdickinson/raf/issues"
},
"contributors": [
{
"name": "Christian Maughan Tegnér",
"email": "christian.tegner@gmail.com"
}
],
"dependencies": {
"performance-now": "^2.1.0"
},
"description": "requestAnimationFrame polyfill for node and the browser",
"devDependencies": {
"browserify": "~4.1.2",
"tape": "^4.0.0",
"testling": "~1.6.1"
},
"homepage": "https://github.com/chrisdickinson/raf#readme",
"keywords": [
"requestAnimationFrame",
"polyfill"
],
"license": "MIT",
"main": "index.js",
"name": "raf",
"repository": {
"type": "git",
"url": "git://github.com/chrisdickinson/raf.git"
},
"scripts": {
"test": "node test.js",
"testling": "browserify test.js | testling"
},
"testling": {
"files": "test.js",
"browsers": [
"iexplore/6.0..latest",
"firefox/3.0..6.0",
"firefox/15.0..latest",
"firefox/nightly",
"chrome/4.0..10.0",
"chrome/20.0..latest",
"chrome/canary",
"opera/10.0..latest",
"opera/next",
"safari/4.0..latest",
"ipad/6.0..latest",
"iphone/6.0..latest"
]
},
"version": "3.4.0"
}

View File

@@ -0,0 +1 @@
require('./').polyfill()

View File

@@ -0,0 +1,62 @@
var test = require('tape')
, raf = require('./index.js')
test('continues to emit events', function(t) {
t.plan(11)
var start = new Date().getTime()
, times = 0
raf(function tick(dt) {
t.ok(dt >= 0, 'time has passed: ' + dt)
if(++times == 10) {
var elapsed = (new Date().getTime() - start)
t.ok(elapsed >= 150, 'should take at least 9 frames worth of wall time: ' + elapsed)
t.end()
} else {
raf(tick)
}
})
})
test('cancel removes callbacks from queue', function(t) {
t.plan(6)
function cb1() { cb1.called = true }
function cb2() { cb2.called = true }
function cb3() { cb3.called = true }
var handle1 = raf(cb1)
t.ok(handle1, 'returns a handle')
var handle2 = raf(cb2)
t.ok(handle2, 'returns a handle')
var handle3 = raf(cb3)
t.ok(handle3, 'returns a handle')
raf.cancel(handle2)
raf(function() {
t.ok(cb1.called, 'callback was invoked')
t.notOk(cb2.called, 'callback was cancelled')
t.ok(cb3.called, 'callback was invoked')
t.end()
})
})
test('raf should throw on errors', function(t) {
t.plan(1)
var onError = function() {
t.pass('error bubbled up to event loop')
}
if(typeof window !== 'undefined') {
window.onerror = onError
} else if(typeof process !== 'undefined') {
process.on('uncaughtException', onError)
}
raf(function() {
throw new Error('foo')
})
})

View File

@@ -0,0 +1,5 @@
try {
module.exports = window
} catch(e) {
module.exports = {}
}