commit
This commit is contained in:
parent
70e2f7a8aa
commit
008d2f30d7
675 changed files with 189892 additions and 0 deletions
22
node_modules/loads/LICENSE
generated
vendored
Normal file
22
node_modules/loads/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
47
node_modules/loads/README.md
generated
vendored
Normal file
47
node_modules/loads/README.md
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
# loads
|
||||
|
||||
[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/loads)[![Build Status][build]](https://travis-ci.org/unshiftio/loads)[![Dependencies][david]](https://david-dm.org/unshiftio/loads)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/loads?branch=master)[![IRC channel][irc]](https://webchat.freenode.net/?channels=unshift)
|
||||
|
||||
[made-by]: https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square
|
||||
[version]: https://img.shields.io/npm/v/loads.svg?style=flat-square
|
||||
[build]: https://img.shields.io/travis/unshiftio/loads/master.svg?style=flat-square
|
||||
[david]: https://img.shields.io/david/unshiftio/loads.svg?style=flat-square
|
||||
[cover]: https://img.shields.io/coveralls/unshiftio/loads/master.svg?style=flat-square
|
||||
[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square
|
||||
|
||||
Loads is a small helper library which automatically assigns and listens to the
|
||||
various of XHR event hooks and emits the corrected and normalized responses over
|
||||
a supplied EventEmitter instance.
|
||||
|
||||
## Installation
|
||||
|
||||
This module was primary developed with browsers in mind and is released in the
|
||||
public npm registry. It can be installed by running:
|
||||
|
||||
```
|
||||
npm install --save loads
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var loads = require('loads')
|
||||
, xhr = new XMLHTTPRequest()
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var ee = new EventEmitter();
|
||||
loads(xhr, ee);
|
||||
|
||||
ee.on('stream', function (data) {
|
||||
// data chunk received.
|
||||
});
|
||||
|
||||
ee.on('end', function () {});
|
||||
|
||||
xhr.open(url);
|
||||
xhr.send();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
163
node_modules/loads/index.js
generated
vendored
Normal file
163
node_modules/loads/index.js
generated
vendored
Normal file
|
@ -0,0 +1,163 @@
|
|||
'use strict';
|
||||
|
||||
var response = require('xhr-response')
|
||||
, statuscode = require('xhr-status')
|
||||
, one = require('one-time')
|
||||
, fail = require('failure');
|
||||
|
||||
/**
|
||||
* Simple nope function that assigned to XHR requests as part of a clean-up
|
||||
* operation.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
function nope() {}
|
||||
|
||||
/**
|
||||
* Attach various of event listeners to a given XHR request.
|
||||
*
|
||||
* @param {XHR} xhr A XHR request that requires listening.
|
||||
* @param {EventEmitter} ee EventEmitter that receives events.
|
||||
* @api public
|
||||
*/
|
||||
function loads(xhr, ee) {
|
||||
var onreadystatechange
|
||||
, onprogress
|
||||
, ontimeout
|
||||
, onabort
|
||||
, onerror
|
||||
, onload
|
||||
, timer;
|
||||
|
||||
/**
|
||||
* Error listener.
|
||||
*
|
||||
* @param {Event} evt Triggered error event.
|
||||
* @api private
|
||||
*/
|
||||
onerror = xhr.onerror = one(function onerror(evt) {
|
||||
var status = statuscode(xhr)
|
||||
, err = fail(new Error('Network request failed'), status);
|
||||
|
||||
ee.emit('error', err);
|
||||
ee.emit('end', err, status);
|
||||
});
|
||||
|
||||
/**
|
||||
* Fix for FireFox's odd abort handling behaviour. When you press ESC on an
|
||||
* active request it triggers `error` instead of abort. The same is called
|
||||
* when an HTTP request is canceled onunload.
|
||||
*
|
||||
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
||||
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
||||
* @see https://code.google.com/p/chromium/issues/detail?id=153570
|
||||
* @param {Event} evt Triggerd abort event
|
||||
* @api private
|
||||
*/
|
||||
onabort = xhr.onabort = function onabort(evt) {
|
||||
onerror(evt);
|
||||
};
|
||||
|
||||
/**
|
||||
* ReadyStateChange listener.
|
||||
*
|
||||
* @param {Event} evt Triggered readyState change event.
|
||||
* @api private
|
||||
*/
|
||||
onreadystatechange = xhr.onreadystatechange = function change(evt) {
|
||||
var target = evt.target;
|
||||
|
||||
if (4 === target.readyState) return onload(evt);
|
||||
};
|
||||
|
||||
/**
|
||||
* The connection has timed out.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
ontimeout = xhr.ontimeout = one(function timeout(evt) {
|
||||
ee.emit('timeout', evt);
|
||||
|
||||
//
|
||||
// Make sure that the request is aborted when there is a timeout. If this
|
||||
// doesn't trigger an error, the next call will.
|
||||
//
|
||||
if (xhr.abort) xhr.abort();
|
||||
onerror(evt);
|
||||
});
|
||||
|
||||
//
|
||||
// Fallback for implementations that did not ship with timer support yet.
|
||||
// Microsoft's XDomainRequest was one of the first to ship with `.timeout`
|
||||
// support so we all XHR implementations before that require a polyfill.
|
||||
//
|
||||
// @see https://bugzilla.mozilla.org/show_bug.cgi?id=525816
|
||||
//
|
||||
if (xhr.timeout) timer = setTimeout(ontimeout, +xhr.timeout);
|
||||
|
||||
/**
|
||||
* IE needs have it's `onprogress` function assigned to a unique function. So,
|
||||
* no touchy touchy here!
|
||||
*
|
||||
* @param {Event} evt Triggered progress event.
|
||||
* @api private
|
||||
*/
|
||||
onprogress = xhr.onprogress = function progress(evt) {
|
||||
var status = statuscode(xhr)
|
||||
, data;
|
||||
|
||||
ee.emit('progress', evt, status);
|
||||
|
||||
if (xhr.readyState >= 3 && status.code === 200 && (data = response(xhr))) {
|
||||
ee.emit('stream', data, status);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle load events an potential data events for when there was no streaming
|
||||
* data.
|
||||
*
|
||||
* @param {Event} evt Triggered load event.
|
||||
* @api private
|
||||
*/
|
||||
onload = xhr.onload = one(function load(evt) {
|
||||
var status = statuscode(xhr)
|
||||
, data = response(xhr);
|
||||
|
||||
if (status.code < 100 || status.code > 599) return onerror(evt);
|
||||
|
||||
//
|
||||
// There is a bug in FireFox's XHR2 implementation where status code 204
|
||||
// triggers a "no element found" error and bad data. So to be save here,
|
||||
// we're just **never** going to emit a `stream` event as for 204's there
|
||||
// shouldn't be any content.
|
||||
//
|
||||
if (data && status.code !== 204) {
|
||||
ee.emit('stream', data, status);
|
||||
}
|
||||
|
||||
ee.emit('end', undefined, status);
|
||||
});
|
||||
|
||||
//
|
||||
// Properly clean up the previously assigned event listeners and timers to
|
||||
// prevent potential data leaks and unwanted `stream` events.
|
||||
//
|
||||
ee.once('end', function cleanup() {
|
||||
xhr.onreadystatechange = onreadystatechange =
|
||||
xhr.onprogress = onprogress =
|
||||
xhr.ontimeout = ontimeout =
|
||||
xhr.onerror = onerror =
|
||||
xhr.onabort = onabort =
|
||||
xhr.onload = onload = nope;
|
||||
|
||||
if (timer) clearTimeout(timer);
|
||||
});
|
||||
|
||||
return xhr;
|
||||
}
|
||||
|
||||
//
|
||||
// Expose all the things.
|
||||
//
|
||||
module.exports = loads;
|
43
node_modules/loads/package.json
generated
vendored
Normal file
43
node_modules/loads/package.json
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "loads",
|
||||
"version": "0.0.4",
|
||||
"description": "Dedicated listening for xhr requests.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"test": "mocha test.js",
|
||||
"watch": "mocha --watch test.js",
|
||||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js",
|
||||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/unshiftio/loads"
|
||||
},
|
||||
"keywords": [
|
||||
"loads",
|
||||
"xhr",
|
||||
"load",
|
||||
"request",
|
||||
"ajax"
|
||||
],
|
||||
"author": "Arnout Kazemier",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/unshiftio/loads/issues"
|
||||
},
|
||||
"homepage": "https://github.com/unshiftio/loads",
|
||||
"dependencies": {
|
||||
"failure": "1.1.x",
|
||||
"one-time": "0.0.x",
|
||||
"xhr-response": "1.0.x",
|
||||
"xhr-status": "1.0.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"assume": "1.2.x",
|
||||
"eventstub": "1.0.x",
|
||||
"istanbul": "0.3.x",
|
||||
"mocha": "2.2.x",
|
||||
"pre-commit": "1.1.x"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue