mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Adding support for all and spread
This commit is contained in:
@@ -6,6 +6,7 @@ var parseHeaders = require('./parseHeaders');
|
||||
var transformData = require('./transformData');
|
||||
var urlIsSameOrigin = require('./urlIsSameOrigin');
|
||||
var utils = require('./utils');
|
||||
var spread = require('./spread');
|
||||
|
||||
var axios = module.exports = function axios(config) {
|
||||
config = utils.merge({
|
||||
@@ -128,6 +129,10 @@ var axios = module.exports = function axios(config) {
|
||||
// Expose defaults
|
||||
axios.defaults = defaults;
|
||||
|
||||
// Expose all/spread
|
||||
axios.all = Promise.all;
|
||||
axios.spread = spread;
|
||||
|
||||
// Provide aliases for supported request methods
|
||||
createShortMethods('delete', 'get', 'head');
|
||||
createShortMethodsWithData('post', 'put', 'patch');
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
||||
*
|
||||
* Common use case would be to use `Function.prototype.apply`.
|
||||
*
|
||||
* ```js
|
||||
* function f(x, y, z) {}
|
||||
* var args = [1, 2, 3];
|
||||
* f.apply(null, args);
|
||||
* ```
|
||||
*
|
||||
* With `spread` this example can be re-written.
|
||||
*
|
||||
* ```js
|
||||
* spread(function(x, y, z) {})([1, 2, 3]);
|
||||
* ```
|
||||
*
|
||||
* @param {Function} callback
|
||||
* @returns {Function}
|
||||
*/
|
||||
module.exports = function spread(callback) {
|
||||
return function (arr) {
|
||||
callback.apply(null, arr);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user