vue-resource
Advanced tools
Comparing version 0.7.4 to 0.8.0
/*! | ||
* vue-resource v0.7.4 | ||
* vue-resource v0.8.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -16,12 +16,285 @@ * Released under the MIT License. | ||
/** | ||
* Utility functions. | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
var PromiseObj = window.Promise || Promise$2; | ||
function Promise$1(executor, context) { | ||
if (executor instanceof PromiseObj) { | ||
this.promise = executor; | ||
} else { | ||
this.promise = new PromiseObj(executor.bind(context)); | ||
} | ||
this.context = context; | ||
} | ||
Promise$1.all = function (iterable, context) { | ||
return new Promise$1(PromiseObj.all(iterable), context); | ||
}; | ||
Promise$1.resolve = function (value, context) { | ||
return new Promise$1(PromiseObj.resolve(value), context); | ||
}; | ||
Promise$1.reject = function (reason, context) { | ||
return new Promise$1(PromiseObj.reject(reason), context); | ||
}; | ||
Promise$1.race = function (iterable, context) { | ||
return new Promise$1(PromiseObj.race(iterable), context); | ||
}; | ||
var p = Promise$1.prototype; | ||
p.bind = function (context) { | ||
this.context = context; | ||
return this; | ||
}; | ||
p.then = function (fulfilled, rejected) { | ||
if (fulfilled && fulfilled.bind && this.context) { | ||
fulfilled = fulfilled.bind(this.context); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.then(fulfilled, rejected); | ||
return this; | ||
}; | ||
p.catch = function (rejected) { | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.catch(rejected); | ||
return this; | ||
}; | ||
p.finally = function (callback) { | ||
return this.then(function (value) { | ||
callback.call(this); | ||
return value; | ||
}, function (reason) { | ||
callback.call(this); | ||
return PromiseObj.reject(reason); | ||
}); | ||
}; | ||
p.success = function (callback) { | ||
warn('The `success` method has been deprecated. Use the `then` method instead.'); | ||
return this.then(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.error = function (callback) { | ||
warn('The `error` method has been deprecated. Use the `catch` method instead.'); | ||
return this.catch(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.always = function (callback) { | ||
warn('The `always` method has been deprecated. Use the `finally` method instead.'); | ||
var cb = function cb(response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}; | ||
return this.then(cb, cb); | ||
}; | ||
var debug = false; | ||
var util = {}; | ||
var config = {}; | ||
var array = []; | ||
var console = window.console; | ||
function Util (Vue) { | ||
util = Vue.util; | ||
config = Vue.config; | ||
debug = Vue.config.debug || !Vue.config.silent; | ||
} | ||
@@ -32,3 +305,3 @@ | ||
function warn(msg) { | ||
if (console && util.warn && (!config.silent || config.debug)) { | ||
if (typeof console !== 'undefined' && debug) { | ||
console.warn('[VueResource warn]: ' + msg); | ||
@@ -39,3 +312,3 @@ } | ||
function error(msg) { | ||
if (console) { | ||
if (typeof console !== 'undefined') { | ||
console.error(msg); | ||
@@ -73,2 +346,13 @@ } | ||
function when(value, fulfilled, rejected) { | ||
var promise = Promise$1.resolve(value); | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
function options(fn, obj, opts) { | ||
@@ -502,280 +786,2 @@ | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
var PromiseObj = window.Promise || Promise$2; | ||
function Promise$1(executor, context) { | ||
if (executor instanceof PromiseObj) { | ||
this.promise = executor; | ||
} else { | ||
this.promise = new PromiseObj(executor.bind(context)); | ||
} | ||
this.context = context; | ||
} | ||
Promise$1.all = function (iterable, context) { | ||
return new Promise$1(PromiseObj.all(iterable), context); | ||
}; | ||
Promise$1.resolve = function (value, context) { | ||
return new Promise$1(PromiseObj.resolve(value), context); | ||
}; | ||
Promise$1.reject = function (reason, context) { | ||
return new Promise$1(PromiseObj.reject(reason), context); | ||
}; | ||
Promise$1.race = function (iterable, context) { | ||
return new Promise$1(PromiseObj.race(iterable), context); | ||
}; | ||
var p = Promise$1.prototype; | ||
p.bind = function (context) { | ||
this.context = context; | ||
return this; | ||
}; | ||
p.then = function (fulfilled, rejected) { | ||
if (fulfilled && fulfilled.bind && this.context) { | ||
fulfilled = fulfilled.bind(this.context); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.then(fulfilled, rejected); | ||
return this; | ||
}; | ||
p.catch = function (rejected) { | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.catch(rejected); | ||
return this; | ||
}; | ||
p.finally = function (callback) { | ||
return this.then(function (value) { | ||
callback.call(this); | ||
return value; | ||
}, function (reason) { | ||
callback.call(this); | ||
return PromiseObj.reject(reason); | ||
}); | ||
}; | ||
p.success = function (callback) { | ||
warn('The `success` method has been deprecated. Use the `then` method instead.'); | ||
return this.then(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.error = function (callback) { | ||
warn('The `error` method has been deprecated. Use the `catch` method instead.'); | ||
return this.catch(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.always = function (callback) { | ||
warn('The `always` method has been deprecated. Use the `finally` method instead.'); | ||
var cb = function cb(response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}; | ||
return this.then(cb, cb); | ||
}; | ||
function xdrClient (request) { | ||
@@ -817,22 +823,20 @@ return new Promise$1(function (resolve) { | ||
var exports$1 = { | ||
request: function request(_request) { | ||
function cors (request, next) { | ||
if (_request.crossOrigin === null) { | ||
_request.crossOrigin = crossOrigin(_request); | ||
} | ||
if (request.crossOrigin === null) { | ||
request.crossOrigin = crossOrigin(request); | ||
} | ||
if (_request.crossOrigin) { | ||
if (request.crossOrigin) { | ||
if (!supportCors) { | ||
_request.client = xdrClient; | ||
} | ||
_request.emulateHTTP = false; | ||
if (!supportCors) { | ||
request.client = xdrClient; | ||
} | ||
return _request; | ||
request.emulateHTTP = false; | ||
} | ||
}; | ||
next(); | ||
} | ||
function crossOrigin(request) { | ||
@@ -845,30 +849,25 @@ | ||
var exports$2 = { | ||
request: function request(_request) { | ||
function mime (request, next) { | ||
if (_request.emulateJSON && isPlainObject(_request.data)) { | ||
_request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
_request.data = Url.params(_request.data); | ||
} | ||
if (request.emulateJSON && isPlainObject(request.data)) { | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.data = Url.params(request.data); | ||
} | ||
if (isObject(_request.data) && /FormData/i.test(_request.data.toString())) { | ||
delete _request.headers['Content-Type']; | ||
} | ||
if (isObject(request.data) && /FormData/i.test(request.data.toString())) { | ||
delete request.headers['Content-Type']; | ||
} | ||
if (isPlainObject(_request.data)) { | ||
_request.data = JSON.stringify(_request.data); | ||
} | ||
if (isPlainObject(request.data)) { | ||
request.data = JSON.stringify(request.data); | ||
} | ||
return _request; | ||
}, | ||
response: function response(_response) { | ||
next(function (response) { | ||
try { | ||
_response.data = JSON.parse(_response.data); | ||
response.data = JSON.parse(response.data); | ||
} catch (e) {} | ||
}); | ||
} | ||
return _response; | ||
} | ||
}; | ||
function jsonpClient (request) { | ||
@@ -919,24 +918,20 @@ return new Promise$1(function (resolve) { | ||
var exports$3 = { | ||
request: function request(_request) { | ||
function jsonp (request, next) { | ||
if (_request.method == 'JSONP') { | ||
_request.client = jsonpClient; | ||
} | ||
return _request; | ||
if (request.method == 'JSONP') { | ||
request.client = jsonpClient; | ||
} | ||
}; | ||
var exports$4 = { | ||
request: function request(_request) { | ||
next(); | ||
} | ||
if (isFunction(_request.beforeSend)) { | ||
_request.beforeSend.call(this, _request); | ||
} | ||
function before (request, next) { | ||
return _request; | ||
if (isFunction(request.beforeSend)) { | ||
request.beforeSend.call(this, request); | ||
} | ||
}; | ||
next(); | ||
} | ||
/** | ||
@@ -946,29 +941,25 @@ * HTTP method override Interceptor. | ||
var exports$5 = { | ||
request: function request(_request) { | ||
function method (request, next) { | ||
if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { | ||
_request.headers['X-HTTP-Method-Override'] = _request.method; | ||
_request.method = 'POST'; | ||
} | ||
return _request; | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.method = 'POST'; | ||
} | ||
}; | ||
var exports$6 = { | ||
request: function request(_request) { | ||
next(); | ||
} | ||
_request.method = _request.method.toUpperCase(); | ||
_request.headers = extend({}, Http.headers.common, !_request.crossOrigin ? Http.headers.custom : {}, Http.headers[_request.method.toLowerCase()], _request.headers); | ||
function header (request, next) { | ||
if (isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { | ||
extend(_request.params, _request.data); | ||
delete _request.data; | ||
} | ||
request.method = request.method.toUpperCase(); | ||
request.headers = extend({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[request.method.toLowerCase()], request.headers); | ||
return _request; | ||
if (isPlainObject(request.data) && /^(GET|JSONP)$/i.test(request.method)) { | ||
extend(request.params, request.data); | ||
delete request.data; | ||
} | ||
}; | ||
next(); | ||
} | ||
/** | ||
@@ -978,65 +969,18 @@ * Timeout Interceptor. | ||
var exports$7 = function exports() { | ||
function timeout (request, next) { | ||
var timeout; | ||
return { | ||
request: function request(_request) { | ||
if (request.timeout) { | ||
timeout = setTimeout(function () { | ||
request.cancel(); | ||
}, request.timeout); | ||
} | ||
if (_request.timeout) { | ||
timeout = setTimeout(function () { | ||
_request.cancel(); | ||
}, _request.timeout); | ||
} | ||
next(function (response) { | ||
return _request; | ||
}, | ||
response: function response(_response) { | ||
clearTimeout(timeout); | ||
return _response; | ||
} | ||
}; | ||
}; | ||
function interceptor (handler, vm) { | ||
return function (client) { | ||
if (isFunction(handler)) { | ||
handler = handler.call(vm, Promise$1); | ||
} | ||
return function (request) { | ||
if (isFunction(handler.request)) { | ||
request = handler.request.call(vm, request); | ||
} | ||
return when(request, function (request) { | ||
return when(client(request), function (response) { | ||
if (isFunction(handler.response)) { | ||
response = handler.response.call(vm, response); | ||
} | ||
return response; | ||
}); | ||
}); | ||
}; | ||
}; | ||
clearTimeout(timeout); | ||
}); | ||
} | ||
function when(value, fulfilled, rejected) { | ||
var promise = Promise$1.resolve(value); | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
function xhrClient (request) { | ||
@@ -1060,3 +1004,3 @@ return new Promise$1(function (resolve) { | ||
response.statusText = trim(xhr.statusText || ''); | ||
response.headers = xhr.getAllResponseHeaders(); | ||
response.allHeaders = xhr.getAllResponseHeaders(); | ||
@@ -1089,28 +1033,78 @@ resolve(response); | ||
function Client (request) { | ||
function Client (context) { | ||
var response = (request.client || xhrClient)(request); | ||
var reqHandlers = [sendRequest], | ||
resHandlers = []; | ||
return Promise$1.resolve(response).then(function (response) { | ||
if (!isObject(context)) { | ||
context = null; | ||
} | ||
if (response.headers) { | ||
function Client(request) { | ||
return new Promise$1(function (resolve) { | ||
var headers = parseHeaders(response.headers); | ||
function exec() { | ||
reqHandlers.pop().call(context, request, next); | ||
} | ||
response.headers = function (name) { | ||
function next(response) { | ||
when(response, function (response) { | ||
if (name) { | ||
return headers[toLower(name)]; | ||
} | ||
if (isFunction(response)) { | ||
return headers; | ||
}; | ||
} | ||
resHandlers.unshift(response); | ||
} else if (isObject(response)) { | ||
response.ok = response.status >= 200 && response.status < 300; | ||
processResponse(response); | ||
return response; | ||
}); | ||
resHandlers.forEach(function (handler) { | ||
handler.call(context, response); | ||
}); | ||
resolve(response); | ||
return; | ||
} | ||
exec(); | ||
}); | ||
} | ||
exec(); | ||
}, context); | ||
} | ||
Client.use = function (handler) { | ||
reqHandlers.push(handler); | ||
}; | ||
return Client; | ||
} | ||
function sendRequest(request, resolve) { | ||
var client = request.client || xhrClient; | ||
resolve(client(request)); | ||
} | ||
function processResponse(response) { | ||
var headers = response.headers || response.allHeaders; | ||
if (isString(headers)) { | ||
headers = parseHeaders(headers); | ||
} | ||
if (isObject(headers)) { | ||
response.headers = function (name) { | ||
return name ? headers[toLower(name)] : headers; | ||
}; | ||
} | ||
response.ok = response.status >= 200 && response.status < 300; | ||
return response; | ||
} | ||
function parseHeaders(str) { | ||
@@ -1123,23 +1117,21 @@ | ||
if (isString(str)) { | ||
each(str.split('\n'), function (row) { | ||
each(str.split('\n'), function (row) { | ||
i = row.indexOf(':'); | ||
name = trim(toLower(row.slice(0, i))); | ||
value = trim(row.slice(i + 1)); | ||
i = row.indexOf(':'); | ||
name = trim(toLower(row.slice(0, i))); | ||
value = trim(row.slice(i + 1)); | ||
if (headers[name]) { | ||
if (headers[name]) { | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = value; | ||
headers[name] = [headers[name], value]; | ||
} | ||
}); | ||
} | ||
} else { | ||
headers[name] = value; | ||
} | ||
}); | ||
return headers; | ||
@@ -1157,3 +1149,3 @@ } | ||
var self = this || {}, | ||
client = Client, | ||
client = Client(self.$vm), | ||
request, | ||
@@ -1163,3 +1155,3 @@ promise; | ||
Http.interceptors.forEach(function (handler) { | ||
client = interceptor(handler, self.$vm)(client); | ||
client.use(handler); | ||
}); | ||
@@ -1169,3 +1161,3 @@ | ||
request = merge({}, Http.options, self.$options, options); | ||
promise = client(request).bind(self.$vm).then(function (response) { | ||
promise = client(request).then(function (response) { | ||
@@ -1217,3 +1209,3 @@ return response.ok ? response : Promise$1.reject(response); | ||
Http.interceptors = [exports$4, exports$7, exports$3, exports$5, exports$2, exports$6, exports$1]; | ||
Http.interceptors = [before, timeout, jsonp, method, mime, header, cors]; | ||
@@ -1220,0 +1212,0 @@ ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { |
/*! | ||
* vue-resource v0.7.4 | ||
* vue-resource v0.8.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -20,12 +20,285 @@ * Released under the MIT License. | ||
/** | ||
* Utility functions. | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
var PromiseObj = window.Promise || Promise$2; | ||
function Promise$1(executor, context) { | ||
if (executor instanceof PromiseObj) { | ||
this.promise = executor; | ||
} else { | ||
this.promise = new PromiseObj(executor.bind(context)); | ||
} | ||
this.context = context; | ||
} | ||
Promise$1.all = function (iterable, context) { | ||
return new Promise$1(PromiseObj.all(iterable), context); | ||
}; | ||
Promise$1.resolve = function (value, context) { | ||
return new Promise$1(PromiseObj.resolve(value), context); | ||
}; | ||
Promise$1.reject = function (reason, context) { | ||
return new Promise$1(PromiseObj.reject(reason), context); | ||
}; | ||
Promise$1.race = function (iterable, context) { | ||
return new Promise$1(PromiseObj.race(iterable), context); | ||
}; | ||
var p = Promise$1.prototype; | ||
p.bind = function (context) { | ||
this.context = context; | ||
return this; | ||
}; | ||
p.then = function (fulfilled, rejected) { | ||
if (fulfilled && fulfilled.bind && this.context) { | ||
fulfilled = fulfilled.bind(this.context); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.then(fulfilled, rejected); | ||
return this; | ||
}; | ||
p.catch = function (rejected) { | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.catch(rejected); | ||
return this; | ||
}; | ||
p.finally = function (callback) { | ||
return this.then(function (value) { | ||
callback.call(this); | ||
return value; | ||
}, function (reason) { | ||
callback.call(this); | ||
return PromiseObj.reject(reason); | ||
}); | ||
}; | ||
p.success = function (callback) { | ||
warn('The `success` method has been deprecated. Use the `then` method instead.'); | ||
return this.then(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.error = function (callback) { | ||
warn('The `error` method has been deprecated. Use the `catch` method instead.'); | ||
return this.catch(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.always = function (callback) { | ||
warn('The `always` method has been deprecated. Use the `finally` method instead.'); | ||
var cb = function cb(response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}; | ||
return this.then(cb, cb); | ||
}; | ||
var debug = false; | ||
var util = {}; | ||
var config = {}; | ||
var array = []; | ||
var console = window.console; | ||
function Util (Vue) { | ||
util = Vue.util; | ||
config = Vue.config; | ||
debug = Vue.config.debug || !Vue.config.silent; | ||
} | ||
@@ -36,3 +309,3 @@ | ||
function warn(msg) { | ||
if (console && util.warn && (!config.silent || config.debug)) { | ||
if (typeof console !== 'undefined' && debug) { | ||
console.warn('[VueResource warn]: ' + msg); | ||
@@ -43,3 +316,3 @@ } | ||
function error(msg) { | ||
if (console) { | ||
if (typeof console !== 'undefined') { | ||
console.error(msg); | ||
@@ -77,2 +350,13 @@ } | ||
function when(value, fulfilled, rejected) { | ||
var promise = Promise$1.resolve(value); | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
function options(fn, obj, opts) { | ||
@@ -506,280 +790,2 @@ | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
var PromiseObj = window.Promise || Promise$2; | ||
function Promise$1(executor, context) { | ||
if (executor instanceof PromiseObj) { | ||
this.promise = executor; | ||
} else { | ||
this.promise = new PromiseObj(executor.bind(context)); | ||
} | ||
this.context = context; | ||
} | ||
Promise$1.all = function (iterable, context) { | ||
return new Promise$1(PromiseObj.all(iterable), context); | ||
}; | ||
Promise$1.resolve = function (value, context) { | ||
return new Promise$1(PromiseObj.resolve(value), context); | ||
}; | ||
Promise$1.reject = function (reason, context) { | ||
return new Promise$1(PromiseObj.reject(reason), context); | ||
}; | ||
Promise$1.race = function (iterable, context) { | ||
return new Promise$1(PromiseObj.race(iterable), context); | ||
}; | ||
var p = Promise$1.prototype; | ||
p.bind = function (context) { | ||
this.context = context; | ||
return this; | ||
}; | ||
p.then = function (fulfilled, rejected) { | ||
if (fulfilled && fulfilled.bind && this.context) { | ||
fulfilled = fulfilled.bind(this.context); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.then(fulfilled, rejected); | ||
return this; | ||
}; | ||
p.catch = function (rejected) { | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
this.promise = this.promise.catch(rejected); | ||
return this; | ||
}; | ||
p.finally = function (callback) { | ||
return this.then(function (value) { | ||
callback.call(this); | ||
return value; | ||
}, function (reason) { | ||
callback.call(this); | ||
return PromiseObj.reject(reason); | ||
}); | ||
}; | ||
p.success = function (callback) { | ||
warn('The `success` method has been deprecated. Use the `then` method instead.'); | ||
return this.then(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.error = function (callback) { | ||
warn('The `error` method has been deprecated. Use the `catch` method instead.'); | ||
return this.catch(function (response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}); | ||
}; | ||
p.always = function (callback) { | ||
warn('The `always` method has been deprecated. Use the `finally` method instead.'); | ||
var cb = function cb(response) { | ||
return callback.call(this, response.data, response.status, response) || response; | ||
}; | ||
return this.then(cb, cb); | ||
}; | ||
function xdrClient (request) { | ||
@@ -821,22 +827,20 @@ return new Promise$1(function (resolve) { | ||
var exports$1 = { | ||
request: function request(_request) { | ||
function cors (request, next) { | ||
if (_request.crossOrigin === null) { | ||
_request.crossOrigin = crossOrigin(_request); | ||
} | ||
if (request.crossOrigin === null) { | ||
request.crossOrigin = crossOrigin(request); | ||
} | ||
if (_request.crossOrigin) { | ||
if (request.crossOrigin) { | ||
if (!supportCors) { | ||
_request.client = xdrClient; | ||
} | ||
_request.emulateHTTP = false; | ||
if (!supportCors) { | ||
request.client = xdrClient; | ||
} | ||
return _request; | ||
request.emulateHTTP = false; | ||
} | ||
}; | ||
next(); | ||
} | ||
function crossOrigin(request) { | ||
@@ -849,30 +853,25 @@ | ||
var exports$2 = { | ||
request: function request(_request) { | ||
function mime (request, next) { | ||
if (_request.emulateJSON && isPlainObject(_request.data)) { | ||
_request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
_request.data = Url.params(_request.data); | ||
} | ||
if (request.emulateJSON && isPlainObject(request.data)) { | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.data = Url.params(request.data); | ||
} | ||
if (isObject(_request.data) && /FormData/i.test(_request.data.toString())) { | ||
delete _request.headers['Content-Type']; | ||
} | ||
if (isObject(request.data) && /FormData/i.test(request.data.toString())) { | ||
delete request.headers['Content-Type']; | ||
} | ||
if (isPlainObject(_request.data)) { | ||
_request.data = JSON.stringify(_request.data); | ||
} | ||
if (isPlainObject(request.data)) { | ||
request.data = JSON.stringify(request.data); | ||
} | ||
return _request; | ||
}, | ||
response: function response(_response) { | ||
next(function (response) { | ||
try { | ||
_response.data = JSON.parse(_response.data); | ||
response.data = JSON.parse(response.data); | ||
} catch (e) {} | ||
}); | ||
} | ||
return _response; | ||
} | ||
}; | ||
function jsonpClient (request) { | ||
@@ -923,24 +922,20 @@ return new Promise$1(function (resolve) { | ||
var exports$3 = { | ||
request: function request(_request) { | ||
function jsonp (request, next) { | ||
if (_request.method == 'JSONP') { | ||
_request.client = jsonpClient; | ||
} | ||
return _request; | ||
if (request.method == 'JSONP') { | ||
request.client = jsonpClient; | ||
} | ||
}; | ||
var exports$4 = { | ||
request: function request(_request) { | ||
next(); | ||
} | ||
if (isFunction(_request.beforeSend)) { | ||
_request.beforeSend.call(this, _request); | ||
} | ||
function before (request, next) { | ||
return _request; | ||
if (isFunction(request.beforeSend)) { | ||
request.beforeSend.call(this, request); | ||
} | ||
}; | ||
next(); | ||
} | ||
/** | ||
@@ -950,29 +945,25 @@ * HTTP method override Interceptor. | ||
var exports$5 = { | ||
request: function request(_request) { | ||
function method (request, next) { | ||
if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { | ||
_request.headers['X-HTTP-Method-Override'] = _request.method; | ||
_request.method = 'POST'; | ||
} | ||
return _request; | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.method = 'POST'; | ||
} | ||
}; | ||
var exports$6 = { | ||
request: function request(_request) { | ||
next(); | ||
} | ||
_request.method = _request.method.toUpperCase(); | ||
_request.headers = extend({}, Http.headers.common, !_request.crossOrigin ? Http.headers.custom : {}, Http.headers[_request.method.toLowerCase()], _request.headers); | ||
function header (request, next) { | ||
if (isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { | ||
extend(_request.params, _request.data); | ||
delete _request.data; | ||
} | ||
request.method = request.method.toUpperCase(); | ||
request.headers = extend({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[request.method.toLowerCase()], request.headers); | ||
return _request; | ||
if (isPlainObject(request.data) && /^(GET|JSONP)$/i.test(request.method)) { | ||
extend(request.params, request.data); | ||
delete request.data; | ||
} | ||
}; | ||
next(); | ||
} | ||
/** | ||
@@ -982,65 +973,18 @@ * Timeout Interceptor. | ||
var exports$7 = function exports() { | ||
function timeout (request, next) { | ||
var timeout; | ||
return { | ||
request: function request(_request) { | ||
if (request.timeout) { | ||
timeout = setTimeout(function () { | ||
request.cancel(); | ||
}, request.timeout); | ||
} | ||
if (_request.timeout) { | ||
timeout = setTimeout(function () { | ||
_request.cancel(); | ||
}, _request.timeout); | ||
} | ||
next(function (response) { | ||
return _request; | ||
}, | ||
response: function response(_response) { | ||
clearTimeout(timeout); | ||
return _response; | ||
} | ||
}; | ||
}; | ||
function interceptor (handler, vm) { | ||
return function (client) { | ||
if (isFunction(handler)) { | ||
handler = handler.call(vm, Promise$1); | ||
} | ||
return function (request) { | ||
if (isFunction(handler.request)) { | ||
request = handler.request.call(vm, request); | ||
} | ||
return when(request, function (request) { | ||
return when(client(request), function (response) { | ||
if (isFunction(handler.response)) { | ||
response = handler.response.call(vm, response); | ||
} | ||
return response; | ||
}); | ||
}); | ||
}; | ||
}; | ||
clearTimeout(timeout); | ||
}); | ||
} | ||
function when(value, fulfilled, rejected) { | ||
var promise = Promise$1.resolve(value); | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
function xhrClient (request) { | ||
@@ -1064,3 +1008,3 @@ return new Promise$1(function (resolve) { | ||
response.statusText = trim(xhr.statusText || ''); | ||
response.headers = xhr.getAllResponseHeaders(); | ||
response.allHeaders = xhr.getAllResponseHeaders(); | ||
@@ -1093,28 +1037,78 @@ resolve(response); | ||
function Client (request) { | ||
function Client (context) { | ||
var response = (request.client || xhrClient)(request); | ||
var reqHandlers = [sendRequest], | ||
resHandlers = []; | ||
return Promise$1.resolve(response).then(function (response) { | ||
if (!isObject(context)) { | ||
context = null; | ||
} | ||
if (response.headers) { | ||
function Client(request) { | ||
return new Promise$1(function (resolve) { | ||
var headers = parseHeaders(response.headers); | ||
function exec() { | ||
reqHandlers.pop().call(context, request, next); | ||
} | ||
response.headers = function (name) { | ||
function next(response) { | ||
when(response, function (response) { | ||
if (name) { | ||
return headers[toLower(name)]; | ||
} | ||
if (isFunction(response)) { | ||
return headers; | ||
}; | ||
} | ||
resHandlers.unshift(response); | ||
} else if (isObject(response)) { | ||
response.ok = response.status >= 200 && response.status < 300; | ||
processResponse(response); | ||
return response; | ||
}); | ||
resHandlers.forEach(function (handler) { | ||
handler.call(context, response); | ||
}); | ||
resolve(response); | ||
return; | ||
} | ||
exec(); | ||
}); | ||
} | ||
exec(); | ||
}, context); | ||
} | ||
Client.use = function (handler) { | ||
reqHandlers.push(handler); | ||
}; | ||
return Client; | ||
} | ||
function sendRequest(request, resolve) { | ||
var client = request.client || xhrClient; | ||
resolve(client(request)); | ||
} | ||
function processResponse(response) { | ||
var headers = response.headers || response.allHeaders; | ||
if (isString(headers)) { | ||
headers = parseHeaders(headers); | ||
} | ||
if (isObject(headers)) { | ||
response.headers = function (name) { | ||
return name ? headers[toLower(name)] : headers; | ||
}; | ||
} | ||
response.ok = response.status >= 200 && response.status < 300; | ||
return response; | ||
} | ||
function parseHeaders(str) { | ||
@@ -1127,23 +1121,21 @@ | ||
if (isString(str)) { | ||
each(str.split('\n'), function (row) { | ||
each(str.split('\n'), function (row) { | ||
i = row.indexOf(':'); | ||
name = trim(toLower(row.slice(0, i))); | ||
value = trim(row.slice(i + 1)); | ||
i = row.indexOf(':'); | ||
name = trim(toLower(row.slice(0, i))); | ||
value = trim(row.slice(i + 1)); | ||
if (headers[name]) { | ||
if (headers[name]) { | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = value; | ||
headers[name] = [headers[name], value]; | ||
} | ||
}); | ||
} | ||
} else { | ||
headers[name] = value; | ||
} | ||
}); | ||
return headers; | ||
@@ -1161,3 +1153,3 @@ } | ||
var self = this || {}, | ||
client = Client, | ||
client = Client(self.$vm), | ||
request, | ||
@@ -1167,3 +1159,3 @@ promise; | ||
Http.interceptors.forEach(function (handler) { | ||
client = interceptor(handler, self.$vm)(client); | ||
client.use(handler); | ||
}); | ||
@@ -1173,3 +1165,3 @@ | ||
request = merge({}, Http.options, self.$options, options); | ||
promise = client(request).bind(self.$vm).then(function (response) { | ||
promise = client(request).then(function (response) { | ||
@@ -1221,3 +1213,3 @@ return response.ok ? response : Promise$1.reject(response); | ||
Http.interceptors = [exports$4, exports$7, exports$3, exports$5, exports$2, exports$6, exports$1]; | ||
Http.interceptors = [before, timeout, jsonp, method, mime, header, cors]; | ||
@@ -1224,0 +1216,0 @@ ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { |
/*! | ||
* vue-resource v0.7.4 | ||
* vue-resource v0.8.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -7,2 +7,2 @@ * Released under the MIT License. | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";function t(t){z=t.util,B=t.config}function e(t){_&&z.warn&&(!B.silent||B.debug)&&_.warn("[VueResource warn]: "+t)}function n(t){_&&_.error(t)}function r(t,e){return z.nextTick(t,e)}function o(t){return t.replace(/^\s*|\s*$/g,"")}function u(t){return t?t.toLowerCase():""}function i(t){return"string"==typeof t}function a(t){return"function"==typeof t}function s(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":G(t))}function c(t){return s(t)&&Object.getPrototypeOf(t)==Object.prototype}function f(t,e,n){return n=n||{},a(n)&&(n=n.call(e)),p(t.bind({$vm:e,$options:n}),t,{$options:n})}function h(t,e){var n,r;if("number"==typeof t.length)for(n=0;n<t.length;n++)e.call(t[n],t[n],n);else if(s(t))for(r in t)t.hasOwnProperty(r)&&e.call(t[r],t[r],r);return t}function l(t){var e=W.slice.call(arguments,1);return e.forEach(function(e){d(t,e)}),t}function p(t){var e=W.slice.call(arguments,1);return e.forEach(function(e){d(t,e,!0)}),t}function d(t,e,n){for(var r in e)n&&(c(e[r])||K(e[r]))?(c(e[r])&&!c(t[r])&&(t[r]={}),K(e[r])&&!K(t[r])&&(t[r]=[]),d(t[r],e[r],n)):void 0!==e[r]&&(t[r]=e[r])}function m(t,e){var n=e(t);return i(t.root)&&!n.match(/^(https?:)?\//)&&(n=t.root+"/"+n),n}function v(t,e){var n=Object.keys(C.options.params),r={},o=e(t);return h(t.params,function(t,e){-1===n.indexOf(e)&&(r[e]=t)}),r=C.params(r),r&&(o+=(-1==o.indexOf("?")?"?":"&")+r),o}function y(t,n){var r=[],o=n(t);return o=o.replace(/(\/?):([a-z]\w*)/gi,function(n,o,u){return e("The `:"+u+"` parameter syntax has been deprecated. Use the `{"+u+"}` syntax instead."),t.params[u]?(r.push(u),o+g(t.params[u])):""}),r.forEach(function(e){delete t.params[e]}),o}function g(t){return w(t,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function w(t,e){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,e?"%20":"+")}function b(t,e,n){var r=T(t),o=r.expand(e);return n&&n.push.apply(n,r.vars),o}function T(t){var e=["+","#",".","/",";","?","&"],n=[];return{vars:n,expand:function(r){return t.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g,function(t,o,u){if(o){var i=null,a=[];if(-1!==e.indexOf(o.charAt(0))&&(i=o.charAt(0),o=o.substr(1)),o.split(/,/g).forEach(function(t){var e=/([^:\*]*)(?::(\d+)|(\*))?/.exec(t);a.push.apply(a,j(r,i,e[1],e[2]||e[3])),n.push(e[1])}),i&&"+"!==i){var s=",";return"?"===i?s="&":"#"!==i&&(s=i),(0!==a.length?i:"")+a.join(s)}return a.join(",")}return P(u)})}}}function j(t,e,n,r){var o=t[n],u=[];if(x(o)&&""!==o)if("string"==typeof o||"number"==typeof o||"boolean"==typeof o)o=o.toString(),r&&"*"!==r&&(o=o.substring(0,parseInt(r,10))),u.push(O(e,o,E(e)?n:null));else if("*"===r)Array.isArray(o)?o.filter(x).forEach(function(t){u.push(O(e,t,E(e)?n:null))}):Object.keys(o).forEach(function(t){x(o[t])&&u.push(O(e,o[t],t))});else{var i=[];Array.isArray(o)?o.filter(x).forEach(function(t){i.push(O(e,t))}):Object.keys(o).forEach(function(t){x(o[t])&&(i.push(encodeURIComponent(t)),i.push(O(e,o[t].toString())))}),E(e)?u.push(encodeURIComponent(n)+"="+i.join(",")):0!==i.length&&u.push(i.join(","))}else";"===e?u.push(encodeURIComponent(n)):""!==o||"&"!==e&&"?"!==e?""===o&&u.push(""):u.push(encodeURIComponent(n)+"=");return u}function x(t){return void 0!==t&&null!==t}function E(t){return";"===t||"&"===t||"?"===t}function O(t,e,n){return e="+"===t||"#"===t?P(e):encodeURIComponent(e),n?encodeURIComponent(n)+"="+e:e}function P(t){return t.split(/(%[0-9A-Fa-f]{2})/g).map(function(t){return/%[0-9A-Fa-f]/.test(t)||(t=encodeURI(t)),t}).join("")}function $(t){var e=[],n=b(t.url,t.params,e);return e.forEach(function(e){delete t.params[e]}),n}function C(t,e){var n,r=this||{},o=t;return i(t)&&(o={url:t,params:e}),o=p({},C.options,r.$options,o),C.transforms.forEach(function(t){n=S(t,n,r.$vm)}),n(o)}function S(t,e,n){return function(r){return t.call(n,r,e)}}function q(t,e,n){var r,o=K(e),u=c(e);h(e,function(e,i){r=s(e)||K(e),n&&(i=n+"["+(u||r?i:"")+"]"),!n&&o?t.add(e.name,e.value):r?q(t,e,i):t.add(i,e)})}function R(t){this.state=et,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(n){e.reject(n)}}function U(t,e){t instanceof rt?this.promise=t:this.promise=new rt(t.bind(e)),this.context=e}function A(t){return new U(function(e){var n,r=new XDomainRequest,o={request:t};t.cancel=function(){r.abort()},r.open(t.method,C(t),!0),n=function(t){o.data=r.responseText,o.status=r.status,o.statusText=r.statusText||"",e(o)},r.timeout=0,r.onload=n,r.onabort=n,r.onerror=n,r.ontimeout=function(){},r.onprogress=function(){},r.send(t.data)})}function k(t){var e=C.parse(C(t));return e.protocol!==ut.protocol||e.host!==ut.host}function H(t){return new U(function(e){var n,r,o="_jsonp"+Math.random().toString(36).substr(2),u={request:t,data:null};t.params[t.jsonp]=o,t.cancel=function(){n({type:"cancel"})},r=document.createElement("script"),r.src=C(t),r.type="text/javascript",r.async=!0,window[o]=function(t){u.data=t},n=function(t){"load"===t.type&&null!==u.data?u.status=200:"error"===t.type?u.status=404:u.status=0,e(u),delete window[o],document.body.removeChild(r)},r.onload=n,r.onerror=n,document.body.appendChild(r)})}function I(t,e){return function(n){return a(t)&&(t=t.call(e,U)),function(r){return a(t.request)&&(r=t.request.call(e,r)),L(r,function(r){return L(n(r),function(n){return a(t.response)&&(n=t.response.call(e,n)),n})})}}}function L(t,e,n){var r=U.resolve(t);return arguments.length<2?r:r.then(e,n)}function D(t){return new U(function(e){var n,r=new XMLHttpRequest,u={request:t};t.cancel=function(){r.abort()},r.open(t.method,C(t),!0),n=function(t){u.data="response"in r?r.response:r.responseText,u.status=1223===r.status?204:r.status,u.statusText=o(r.statusText||""),u.headers=r.getAllResponseHeaders(),e(u)},r.timeout=0,r.onload=n,r.onabort=n,r.onerror=n,r.ontimeout=function(){},r.onprogress=function(){},c(t.xhr)&&l(r,t.xhr),c(t.upload)&&l(r.upload,t.upload),h(t.headers||{},function(t,e){r.setRequestHeader(e,t)}),r.send(t.data)})}function J(t){var e=(t.client||D)(t);return U.resolve(e).then(function(t){if(t.headers){var e=M(t.headers);t.headers=function(t){return t?e[u(t)]:e}}return t.ok=t.status>=200&&t.status<300,t})}function M(t){var e,n,r,a={};return i(t)&&h(t.split("\n"),function(t){r=t.indexOf(":"),n=o(u(t.slice(0,r))),e=o(t.slice(r+1)),a[n]?K(a[n])?a[n].push(e):a[n]=[a[n],e]:a[n]=e}),a}function N(t,e){var r,o,u=this||{},i=J;return N.interceptors.forEach(function(t){i=I(t,u.$vm)(i)}),e=s(t)?t:l({url:t},e),r=p({},N.options,u.$options,e),o=i(r).bind(u.$vm).then(function(t){return t.ok?t:U.reject(t)},function(t){return t instanceof Error&&n(t),U.reject(t)}),r.success&&o.success(r.success),r.error&&o.error(r.error),o}function X(t,e,n,r){var o=this||{},u={};return n=l({},X.actions,n),h(n,function(n,i){n=p({url:t,params:e||{}},r,n),u[i]=function(){return(o.$http||N)(V(n,arguments))}}),u}function V(t,e){var n,r,o,u=l({},t),i={};switch(e.length){case 4:o=e[3],r=e[2];case 3:case 2:if(!a(e[1])){i=e[0],n=e[1],r=e[2];break}if(a(e[0])){r=e[0],o=e[1];break}r=e[1],o=e[2];case 1:a(e[0])?r=e[0]:/^(POST|PUT|PATCH)$/i.test(u.method)?n=e[0]:i=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return u.data=n,u.params=l({},u.params,i),r&&(u.success=r),o&&(u.error=o),u}function F(e){F.installed||(t(e),e.url=C,e.http=N,e.resource=X,e.Promise=U,Object.defineProperties(e.prototype,{$url:{get:function(){return f(e.url,this,this.$options.url)}},$http:{get:function(){return f(e.http,this,this.$options.http)}},$resource:{get:function(){return e.resource.bind(this)}},$promise:{get:function(){var t=this;return function(n){return new e.Promise(n,t)}}}}))}var G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},z={},B={},W=[],_=window.console,K=Array.isArray,Q=document.documentMode,Y=document.createElement("a");C.options={url:"",root:null,params:{}},C.transforms=[$,y,v,m],C.params=function(t){var e=[],n=encodeURIComponent;return e.add=function(t,e){a(e)&&(e=e()),null===e&&(e=""),this.push(n(t)+"="+n(e))},q(e,t),e.join("&").replace(/%20/g,"+")},C.parse=function(t){return Q&&(Y.href=t,t=Y.href),Y.href=t,{href:Y.href,protocol:Y.protocol?Y.protocol.replace(/:$/,""):"",port:Y.port,host:Y.host,hostname:Y.hostname,pathname:"/"===Y.pathname.charAt(0)?Y.pathname:"/"+Y.pathname,search:Y.search?Y.search.replace(/^\?/,""):"",hash:Y.hash?Y.hash.replace(/^#/,""):""}};var Z=0,tt=1,et=2;R.reject=function(t){return new R(function(e,n){n(t)})},R.resolve=function(t){return new R(function(e,n){e(t)})},R.all=function(t){return new R(function(e,n){function r(n){return function(r){u[n]=r,o+=1,o===t.length&&e(u)}}var o=0,u=[];0===t.length&&e(u);for(var i=0;i<t.length;i+=1)R.resolve(t[i]).then(r(i),n)})},R.race=function(t){return new R(function(e,n){for(var r=0;r<t.length;r+=1)R.resolve(t[r]).then(e,n)})};var nt=R.prototype;nt.resolve=function(t){var e=this;if(e.state===et){if(t===e)throw new TypeError("Promise settled with itself.");var n=!1;try{var r=t&&t.then;if(null!==t&&"object"===("undefined"==typeof t?"undefined":G(t))&&"function"==typeof r)return void r.call(t,function(t){n||e.resolve(t),n=!0},function(t){n||e.reject(t),n=!0})}catch(o){return void(n||e.reject(o))}e.state=Z,e.value=t,e.notify()}},nt.reject=function(t){var e=this;if(e.state===et){if(t===e)throw new TypeError("Promise settled with itself.");e.state=tt,e.value=t,e.notify()}},nt.notify=function(){var t=this;r(function(){if(t.state!==et)for(;t.deferred.length;){var e=t.deferred.shift(),n=e[0],r=e[1],o=e[2],u=e[3];try{t.state===Z?o("function"==typeof n?n.call(void 0,t.value):t.value):t.state===tt&&("function"==typeof r?o(r.call(void 0,t.value)):u(t.value))}catch(i){u(i)}}})},nt.then=function(t,e){var n=this;return new R(function(r,o){n.deferred.push([t,e,r,o]),n.notify()})},nt["catch"]=function(t){return this.then(void 0,t)};var rt=window.Promise||R;U.all=function(t,e){return new U(rt.all(t),e)},U.resolve=function(t,e){return new U(rt.resolve(t),e)},U.reject=function(t,e){return new U(rt.reject(t),e)},U.race=function(t,e){return new U(rt.race(t),e)};var ot=U.prototype;ot.bind=function(t){return this.context=t,this},ot.then=function(t,e){return t&&t.bind&&this.context&&(t=t.bind(this.context)),e&&e.bind&&this.context&&(e=e.bind(this.context)),this.promise=this.promise.then(t,e),this},ot["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),this.promise=this.promise["catch"](t),this},ot["finally"]=function(t){return this.then(function(e){return t.call(this),e},function(e){return t.call(this),rt.reject(e)})},ot.success=function(t){return e("The `success` method has been deprecated. Use the `then` method instead."),this.then(function(e){return t.call(this,e.data,e.status,e)||e})},ot.error=function(t){return e("The `error` method has been deprecated. Use the `catch` method instead."),this["catch"](function(e){return t.call(this,e.data,e.status,e)||e})},ot.always=function(t){e("The `always` method has been deprecated. Use the `finally` method instead.");var n=function(e){return t.call(this,e.data,e.status,e)||e};return this.then(n,n)};var ut=C.parse(location.href),it="withCredentials"in new XMLHttpRequest,at={request:function(t){return null===t.crossOrigin&&(t.crossOrigin=k(t)),t.crossOrigin&&(it||(t.client=A),t.emulateHTTP=!1),t}},st={request:function(t){return t.emulateJSON&&c(t.data)&&(t.headers["Content-Type"]="application/x-www-form-urlencoded",t.data=C.params(t.data)),s(t.data)&&/FormData/i.test(t.data.toString())&&delete t.headers["Content-Type"],c(t.data)&&(t.data=JSON.stringify(t.data)),t},response:function(t){try{t.data=JSON.parse(t.data)}catch(e){}return t}},ct={request:function(t){return"JSONP"==t.method&&(t.client=H),t}},ft={request:function(t){return a(t.beforeSend)&&t.beforeSend.call(this,t),t}},ht={request:function(t){return t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers["X-HTTP-Method-Override"]=t.method,t.method="POST"),t}},lt={request:function(t){return t.method=t.method.toUpperCase(),t.headers=l({},N.headers.common,t.crossOrigin?{}:N.headers.custom,N.headers[t.method.toLowerCase()],t.headers),c(t.data)&&/^(GET|JSONP)$/i.test(t.method)&&(l(t.params,t.data),delete t.data),t}},pt=function(){var t;return{request:function(e){return e.timeout&&(t=setTimeout(function(){e.cancel()},e.timeout)),e},response:function(e){return clearTimeout(t),e}}},dt={"Content-Type":"application/json"};return N.options={method:"get",data:"",params:{},headers:{},xhr:null,upload:null,jsonp:"callback",beforeSend:null,crossOrigin:null,emulateHTTP:!1,emulateJSON:!1,timeout:0},N.headers={put:dt,post:dt,patch:dt,"delete":dt,common:{Accept:"application/json, text/plain, */*"},custom:{"X-Requested-With":"XMLHttpRequest"}},N.interceptors=[ft,pt,ct,ht,st,lt,at],["get","put","post","patch","delete","jsonp"].forEach(function(t){N[t]=function(e,n,r,o){return a(n)&&(o=r,r=n,n=void 0),s(r)&&(o=r,r=void 0),this(e,l({method:t,data:n,success:r},o))}}),X.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},"delete":{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(F),F}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";function t(t){this.state=nt,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(n){e.reject(n)}}function e(t,e){t instanceof ot?this.promise=t:this.promise=new ot(t.bind(e)),this.context=e}function n(t){ut=t.util,at=t.config.debug||!t.config.silent}function r(t){"undefined"!=typeof console&&at&&console.warn("[VueResource warn]: "+t)}function o(t){"undefined"!=typeof console&&console.error(t)}function i(t,e){return ut.nextTick(t,e)}function a(t){return t.replace(/^\s*|\s*$/g,"")}function u(t){return t?t.toLowerCase():""}function c(t){return"string"==typeof t}function s(t){return"function"==typeof t}function f(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":Z(t))}function l(t){return f(t)&&Object.getPrototypeOf(t)==Object.prototype}function h(t,n,r){var o=e.resolve(t);return arguments.length<2?o:o.then(n,r)}function d(t,e,n){return n=n||{},s(n)&&(n=n.call(e)),v(t.bind({$vm:e,$options:n}),t,{$options:n})}function p(t,e){var n,r;if("number"==typeof t.length)for(n=0;n<t.length;n++)e.call(t[n],t[n],n);else if(f(t))for(r in t)t.hasOwnProperty(r)&&e.call(t[r],t[r],r);return t}function m(t){var e=ct.slice.call(arguments,1);return e.forEach(function(e){y(t,e)}),t}function v(t){var e=ct.slice.call(arguments,1);return e.forEach(function(e){y(t,e,!0)}),t}function y(t,e,n){for(var r in e)n&&(l(e[r])||st(e[r]))?(l(e[r])&&!l(t[r])&&(t[r]={}),st(e[r])&&!st(t[r])&&(t[r]=[]),y(t[r],e[r],n)):void 0!==e[r]&&(t[r]=e[r])}function g(t,e){var n=e(t);return c(t.root)&&!n.match(/^(https?:)?\//)&&(n=t.root+"/"+n),n}function b(t,e){var n=Object.keys(U.options.params),r={},o=e(t);return p(t.params,function(t,e){-1===n.indexOf(e)&&(r[e]=t)}),r=U.params(r),r&&(o+=(-1==o.indexOf("?")?"?":"&")+r),o}function w(t,e){var n=[],o=e(t);return o=o.replace(/(\/?):([a-z]\w*)/gi,function(e,o,i){return r("The `:"+i+"` parameter syntax has been deprecated. Use the `{"+i+"}` syntax instead."),t.params[i]?(n.push(i),o+T(t.params[i])):""}),n.forEach(function(e){delete t.params[e]}),o}function T(t){return j(t,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function j(t,e){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,e?"%20":"+")}function x(t,e,n){var r=E(t),o=r.expand(e);return n&&n.push.apply(n,r.vars),o}function E(t){var e=["+","#",".","/",";","?","&"],n=[];return{vars:n,expand:function(r){return t.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g,function(t,o,i){if(o){var a=null,u=[];if(-1!==e.indexOf(o.charAt(0))&&(a=o.charAt(0),o=o.substr(1)),o.split(/,/g).forEach(function(t){var e=/([^:\*]*)(?::(\d+)|(\*))?/.exec(t);u.push.apply(u,O(r,a,e[1],e[2]||e[3])),n.push(e[1])}),a&&"+"!==a){var c=",";return"?"===a?c="&":"#"!==a&&(c=a),(0!==u.length?a:"")+u.join(c)}return u.join(",")}return $(i)})}}}function O(t,e,n,r){var o=t[n],i=[];if(P(o)&&""!==o)if("string"==typeof o||"number"==typeof o||"boolean"==typeof o)o=o.toString(),r&&"*"!==r&&(o=o.substring(0,parseInt(r,10))),i.push(S(e,o,C(e)?n:null));else if("*"===r)Array.isArray(o)?o.filter(P).forEach(function(t){i.push(S(e,t,C(e)?n:null))}):Object.keys(o).forEach(function(t){P(o[t])&&i.push(S(e,o[t],t))});else{var a=[];Array.isArray(o)?o.filter(P).forEach(function(t){a.push(S(e,t))}):Object.keys(o).forEach(function(t){P(o[t])&&(a.push(encodeURIComponent(t)),a.push(S(e,o[t].toString())))}),C(e)?i.push(encodeURIComponent(n)+"="+a.join(",")):0!==a.length&&i.push(a.join(","))}else";"===e?i.push(encodeURIComponent(n)):""!==o||"&"!==e&&"?"!==e?""===o&&i.push(""):i.push(encodeURIComponent(n)+"=");return i}function P(t){return void 0!==t&&null!==t}function C(t){return";"===t||"&"===t||"?"===t}function S(t,e,n){return e="+"===t||"#"===t?$(e):encodeURIComponent(e),n?encodeURIComponent(n)+"="+e:e}function $(t){return t.split(/(%[0-9A-Fa-f]{2})/g).map(function(t){return/%[0-9A-Fa-f]/.test(t)||(t=encodeURI(t)),t}).join("")}function R(t){var e=[],n=x(t.url,t.params,e);return e.forEach(function(e){delete t.params[e]}),n}function U(t,e){var n,r=this||{},o=t;return c(t)&&(o={url:t,params:e}),o=v({},U.options,r.$options,o),U.transforms.forEach(function(t){n=A(t,n,r.$vm)}),n(o)}function A(t,e,n){return function(r){return t.call(n,r,e)}}function H(t,e,n){var r,o=st(e),i=l(e);p(e,function(e,a){r=f(e)||st(e),n&&(a=n+"["+(i||r?a:"")+"]"),!n&&o?t.add(e.name,e.value):r?H(t,e,a):t.add(a,e)})}function k(t){return new e(function(e){var n,r=new XDomainRequest,o={request:t};t.cancel=function(){r.abort()},r.open(t.method,U(t),!0),n=function(t){o.data=r.responseText,o.status=r.status,o.statusText=r.statusText||"",e(o)},r.timeout=0,r.onload=n,r.onabort=n,r.onerror=n,r.ontimeout=function(){},r.onprogress=function(){},r.send(t.data)})}function q(t,e){null===t.crossOrigin&&(t.crossOrigin=I(t)),t.crossOrigin&&(dt||(t.client=k),t.emulateHTTP=!1),e()}function I(t){var e=U.parse(U(t));return e.protocol!==ht.protocol||e.host!==ht.host}function L(t,e){t.emulateJSON&&l(t.data)&&(t.headers["Content-Type"]="application/x-www-form-urlencoded",t.data=U.params(t.data)),f(t.data)&&/FormData/i.test(t.data.toString())&&delete t.headers["Content-Type"],l(t.data)&&(t.data=JSON.stringify(t.data)),e(function(t){try{t.data=JSON.parse(t.data)}catch(e){}})}function D(t){return new e(function(e){var n,r,o="_jsonp"+Math.random().toString(36).substr(2),i={request:t,data:null};t.params[t.jsonp]=o,t.cancel=function(){n({type:"cancel"})},r=document.createElement("script"),r.src=U(t),r.type="text/javascript",r.async=!0,window[o]=function(t){i.data=t},n=function(t){"load"===t.type&&null!==i.data?i.status=200:"error"===t.type?i.status=404:i.status=0,e(i),delete window[o],document.body.removeChild(r)},r.onload=n,r.onerror=n,document.body.appendChild(r)})}function J(t,e){"JSONP"==t.method&&(t.client=D),e()}function M(t,e){s(t.beforeSend)&&t.beforeSend.call(this,t),e()}function N(t,e){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers["X-HTTP-Method-Override"]=t.method,t.method="POST"),e()}function X(t,e){t.method=t.method.toUpperCase(),t.headers=m({},_.headers.common,t.crossOrigin?{}:_.headers.custom,_.headers[t.method.toLowerCase()],t.headers),l(t.data)&&/^(GET|JSONP)$/i.test(t.method)&&(m(t.params,t.data),delete t.data),e()}function V(t,e){var n;t.timeout&&(n=setTimeout(function(){t.cancel()},t.timeout)),e(function(t){clearTimeout(n)})}function F(t){return new e(function(e){var n,r=new XMLHttpRequest,o={request:t};t.cancel=function(){r.abort()},r.open(t.method,U(t),!0),n=function(t){o.data="response"in r?r.response:r.responseText,o.status=1223===r.status?204:r.status,o.statusText=a(r.statusText||""),o.allHeaders=r.getAllResponseHeaders(),e(o)},r.timeout=0,r.onload=n,r.onabort=n,r.onerror=n,r.ontimeout=function(){},r.onprogress=function(){},l(t.xhr)&&m(r,t.xhr),l(t.upload)&&m(r.upload,t.upload),p(t.headers||{},function(t,e){r.setRequestHeader(e,t)}),r.send(t.data)})}function G(t){function n(n){return new e(function(e){function i(){r.pop().call(t,n,a)}function a(n){h(n,function(n){if(s(n))o.unshift(n);else if(f(n))return B(n),o.forEach(function(e){e.call(t,n)}),void e(n);i()})}i()},t)}var r=[z],o=[];return f(t)||(t=null),n.use=function(t){r.push(t)},n}function z(t,e){var n=t.client||F;e(n(t))}function B(t){var e=t.headers||t.allHeaders;return c(e)&&(e=W(e)),f(e)&&(t.headers=function(t){return t?e[u(t)]:e}),t.ok=t.status>=200&&t.status<300,t}function W(t){var e,n,r,o={};return p(t.split("\n"),function(t){r=t.indexOf(":"),n=a(u(t.slice(0,r))),e=a(t.slice(r+1)),o[n]?st(o[n])?o[n].push(e):o[n]=[o[n],e]:o[n]=e}),o}function _(t,n){var r,i,a=this||{},u=G(a.$vm);return _.interceptors.forEach(function(t){u.use(t)}),n=f(t)?t:m({url:t},n),r=v({},_.options,a.$options,n),i=u(r).then(function(t){return t.ok?t:e.reject(t)},function(t){return t instanceof Error&&o(t),e.reject(t)}),r.success&&i.success(r.success),r.error&&i.error(r.error),i}function K(t,e,n,r){var o=this||{},i={};return n=m({},K.actions,n),p(n,function(n,a){n=v({url:t,params:e||{}},r,n),i[a]=function(){return(o.$http||_)(Q(n,arguments))}}),i}function Q(t,e){var n,r,o,i=m({},t),a={};switch(e.length){case 4:o=e[3],r=e[2];case 3:case 2:if(!s(e[1])){a=e[0],n=e[1],r=e[2];break}if(s(e[0])){r=e[0],o=e[1];break}r=e[1],o=e[2];case 1:s(e[0])?r=e[0]:/^(POST|PUT|PATCH)$/i.test(i.method)?n=e[0]:a=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return i.data=n,i.params=m({},i.params,a),r&&(i.success=r),o&&(i.error=o),i}function Y(t){Y.installed||(n(t),t.url=U,t.http=_,t.resource=K,t.Promise=e,Object.defineProperties(t.prototype,{$url:{get:function(){return d(t.url,this,this.$options.url)}},$http:{get:function(){return d(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var e=this;return function(n){return new t.Promise(n,e)}}}}))}var Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},tt=0,et=1,nt=2;t.reject=function(e){return new t(function(t,n){n(e)})},t.resolve=function(e){return new t(function(t,n){t(e)})},t.all=function(e){return new t(function(n,r){function o(t){return function(r){a[t]=r,i+=1,i===e.length&&n(a)}}var i=0,a=[];0===e.length&&n(a);for(var u=0;u<e.length;u+=1)t.resolve(e[u]).then(o(u),r)})},t.race=function(e){return new t(function(n,r){for(var o=0;o<e.length;o+=1)t.resolve(e[o]).then(n,r)})};var rt=t.prototype;rt.resolve=function(t){var e=this;if(e.state===nt){if(t===e)throw new TypeError("Promise settled with itself.");var n=!1;try{var r=t&&t.then;if(null!==t&&"object"===("undefined"==typeof t?"undefined":Z(t))&&"function"==typeof r)return void r.call(t,function(t){n||e.resolve(t),n=!0},function(t){n||e.reject(t),n=!0})}catch(o){return void(n||e.reject(o))}e.state=tt,e.value=t,e.notify()}},rt.reject=function(t){var e=this;if(e.state===nt){if(t===e)throw new TypeError("Promise settled with itself.");e.state=et,e.value=t,e.notify()}},rt.notify=function(){var t=this;i(function(){if(t.state!==nt)for(;t.deferred.length;){var e=t.deferred.shift(),n=e[0],r=e[1],o=e[2],i=e[3];try{t.state===tt?o("function"==typeof n?n.call(void 0,t.value):t.value):t.state===et&&("function"==typeof r?o(r.call(void 0,t.value)):i(t.value))}catch(a){i(a)}}})},rt.then=function(e,n){var r=this;return new t(function(t,o){r.deferred.push([e,n,t,o]),r.notify()})},rt["catch"]=function(t){return this.then(void 0,t)};var ot=window.Promise||t;e.all=function(t,n){return new e(ot.all(t),n)},e.resolve=function(t,n){return new e(ot.resolve(t),n)},e.reject=function(t,n){return new e(ot.reject(t),n)},e.race=function(t,n){return new e(ot.race(t),n)};var it=e.prototype;it.bind=function(t){return this.context=t,this},it.then=function(t,e){return t&&t.bind&&this.context&&(t=t.bind(this.context)),e&&e.bind&&this.context&&(e=e.bind(this.context)),this.promise=this.promise.then(t,e),this},it["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),this.promise=this.promise["catch"](t),this},it["finally"]=function(t){return this.then(function(e){return t.call(this),e},function(e){return t.call(this),ot.reject(e)})},it.success=function(t){return r("The `success` method has been deprecated. Use the `then` method instead."),this.then(function(e){return t.call(this,e.data,e.status,e)||e})},it.error=function(t){return r("The `error` method has been deprecated. Use the `catch` method instead."),this["catch"](function(e){return t.call(this,e.data,e.status,e)||e})},it.always=function(t){r("The `always` method has been deprecated. Use the `finally` method instead.");var e=function(e){return t.call(this,e.data,e.status,e)||e};return this.then(e,e)};var at=!1,ut={},ct=[],st=Array.isArray,ft=document.documentMode,lt=document.createElement("a");U.options={url:"",root:null,params:{}},U.transforms=[R,w,b,g],U.params=function(t){var e=[],n=encodeURIComponent;return e.add=function(t,e){s(e)&&(e=e()),null===e&&(e=""),this.push(n(t)+"="+n(e))},H(e,t),e.join("&").replace(/%20/g,"+")},U.parse=function(t){return ft&&(lt.href=t,t=lt.href),lt.href=t,{href:lt.href,protocol:lt.protocol?lt.protocol.replace(/:$/,""):"",port:lt.port,host:lt.host,hostname:lt.hostname,pathname:"/"===lt.pathname.charAt(0)?lt.pathname:"/"+lt.pathname,search:lt.search?lt.search.replace(/^\?/,""):"",hash:lt.hash?lt.hash.replace(/^#/,""):""}};var ht=U.parse(location.href),dt="withCredentials"in new XMLHttpRequest,pt={"Content-Type":"application/json"};return _.options={method:"get",data:"",params:{},headers:{},xhr:null,upload:null,jsonp:"callback",beforeSend:null,crossOrigin:null,emulateHTTP:!1,emulateJSON:!1,timeout:0},_.headers={put:pt,post:pt,patch:pt,"delete":pt,common:{Accept:"application/json, text/plain, */*"},custom:{"X-Requested-With":"XMLHttpRequest"}},_.interceptors=[M,V,J,N,L,X,q],["get","put","post","patch","delete","jsonp"].forEach(function(t){_[t]=function(e,n,r,o){return s(n)&&(o=r,r=n,n=void 0),f(r)&&(o=r,r=void 0),this(e,m({method:t,data:n,success:r},o))}}),K.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},"delete":{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(Y),Y}); |
{ | ||
"name": "vue-resource", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"description": "A web request service for Vue.js", | ||
"main": "dist/vue-resource.common.js", | ||
"jsnext:main": "dist/vue-resource.es2015.js", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "build": "node build/build.js", |
@@ -7,15 +7,9 @@ /** | ||
const exports = { | ||
export default function (request, next) { | ||
request(request) { | ||
if (isFunction(request.beforeSend)) { | ||
request.beforeSend.call(this, request); | ||
} | ||
return request; | ||
if (isFunction(request.beforeSend)) { | ||
request.beforeSend.call(this, request); | ||
} | ||
}; | ||
export default exports; | ||
next(); | ||
} |
@@ -7,32 +7,79 @@ /** | ||
import xhrClient from './xhr'; | ||
import { each, trim, isArray, isString, toLower } from '../../util'; | ||
import { each, trim, when, isArray, isObject, isPlainObject, isString, isFunction, toLower } from '../../util'; | ||
export default function (request) { | ||
export default function (context) { | ||
var response = (request.client || xhrClient)(request); | ||
var reqHandlers = [sendRequest], resHandlers = []; | ||
return Promise.resolve(response).then((response) => { | ||
if (!isObject(context)) { | ||
context = null; | ||
} | ||
if (response.headers) { | ||
function Client(request) { | ||
return new Promise((resolve) => { | ||
var headers = parseHeaders(response.headers); | ||
function exec() { | ||
reqHandlers.pop().call(context, request, next); | ||
} | ||
response.headers = (name) => { | ||
function next(response) { | ||
when(response, (response) => { | ||
if (name) { | ||
return headers[toLower(name)]; | ||
} | ||
if (isFunction(response)) { | ||
return headers; | ||
}; | ||
resHandlers.unshift(response); | ||
} | ||
} else if (isObject(response)) { | ||
response.ok = response.status >= 200 && response.status < 300; | ||
processResponse(response); | ||
return response; | ||
}); | ||
resHandlers.forEach((handler) => { | ||
handler.call(context, response); | ||
}); | ||
resolve(response); | ||
return; | ||
} | ||
exec(); | ||
}); | ||
} | ||
exec(); | ||
}, context); | ||
} | ||
Client.use = (handler) => { | ||
reqHandlers.push(handler); | ||
}; | ||
return Client; | ||
} | ||
function sendRequest(request, resolve) { | ||
var client = request.client || xhrClient; | ||
resolve(client(request)); | ||
} | ||
function processResponse(response) { | ||
var headers = response.headers || response.allHeaders; | ||
if (isString(headers)) { | ||
headers = parseHeaders(headers); | ||
} | ||
if (isObject(headers)) { | ||
response.headers = (name) => name ? headers[toLower(name)] : headers; | ||
} | ||
response.ok = response.status >= 200 && response.status < 300; | ||
return response; | ||
} | ||
function parseHeaders(str) { | ||
@@ -42,26 +89,24 @@ | ||
if (isString(str)) { | ||
each(str.split('\n'), (row) => { | ||
each(str.split('\n'), (row) => { | ||
i = row.indexOf(':'); | ||
name = trim(toLower(row.slice(0, i))); | ||
value = trim(row.slice(i + 1)); | ||
i = row.indexOf(':'); | ||
name = trim(toLower(row.slice(0, i))); | ||
value = trim(row.slice(i + 1)); | ||
if (headers[name]) { | ||
if (headers[name]) { | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = value; | ||
headers[name] = [headers[name], value]; | ||
} | ||
}); | ||
} | ||
} else { | ||
headers[name] = value; | ||
} | ||
}); | ||
return headers; | ||
} |
@@ -25,3 +25,3 @@ /** | ||
response.statusText = trim(xhr.statusText || ''); | ||
response.headers = xhr.getAllResponseHeaders(); | ||
response.allHeaders = xhr.getAllResponseHeaders(); | ||
@@ -28,0 +28,0 @@ resolve(response); |
@@ -11,23 +11,19 @@ /** | ||
const exports = { | ||
export default function (request, next) { | ||
request(request) { | ||
if (request.crossOrigin === null) { | ||
request.crossOrigin = crossOrigin(request); | ||
} | ||
if (request.crossOrigin === null) { | ||
request.crossOrigin = crossOrigin(request); | ||
} | ||
if (request.crossOrigin) { | ||
if (request.crossOrigin) { | ||
if (!supportCors) { | ||
request.client = xdrClient; | ||
} | ||
request.emulateHTTP = false; | ||
if (!supportCors) { | ||
request.client = xdrClient; | ||
} | ||
return request; | ||
request.emulateHTTP = false; | ||
} | ||
}; | ||
next(); | ||
} | ||
@@ -40,3 +36,1 @@ function crossOrigin(request) { | ||
} | ||
export default exports; |
@@ -8,23 +8,17 @@ /** | ||
const exports = { | ||
export default function (request, next) { | ||
request(request) { | ||
request.method = request.method.toUpperCase(); | ||
request.headers = extend({}, Http.headers.common, | ||
!request.crossOrigin ? Http.headers.custom : {}, | ||
Http.headers[request.method.toLowerCase()], | ||
request.headers | ||
); | ||
request.method = request.method.toUpperCase(); | ||
request.headers = extend({}, Http.headers.common, | ||
!request.crossOrigin ? Http.headers.custom : {}, | ||
Http.headers[request.method.toLowerCase()], | ||
request.headers | ||
); | ||
if (isPlainObject(request.data) && /^(GET|JSONP)$/i.test(request.method)) { | ||
extend(request.params, request.data); | ||
delete request.data; | ||
} | ||
return request; | ||
if (isPlainObject(request.data) && /^(GET|JSONP)$/i.test(request.method)) { | ||
extend(request.params, request.data); | ||
delete request.data; | ||
} | ||
}; | ||
export default exports; | ||
next(); | ||
} |
@@ -14,3 +14,2 @@ /** | ||
import timeout from './timeout'; | ||
import interceptor from './interceptor'; | ||
import Client from './client/index'; | ||
@@ -22,6 +21,6 @@ import Promise from '../promise'; | ||
var self = this || {}, client = Client, request, promise; | ||
var self = this || {}, client = Client(self.$vm), request, promise; | ||
Http.interceptors.forEach((handler) => { | ||
client = interceptor(handler, self.$vm)(client); | ||
client.use(handler); | ||
}); | ||
@@ -31,3 +30,3 @@ | ||
request = merge({}, Http.options, self.$options, options); | ||
promise = client(request).bind(self.$vm).then((response) => { | ||
promise = client(request).then((response) => { | ||
@@ -82,3 +81,3 @@ return response.ok ? response : Promise.reject(response); | ||
['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { | ||
['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach((method) => { | ||
@@ -85,0 +84,0 @@ Http[method] = function (url, data, success, options) { |
@@ -7,15 +7,9 @@ /** | ||
const exports = { | ||
export default function (request, next) { | ||
request(request) { | ||
if (request.method == 'JSONP') { | ||
request.client = jsonpClient; | ||
} | ||
return request; | ||
if (request.method == 'JSONP') { | ||
request.client = jsonpClient; | ||
} | ||
}; | ||
export default exports; | ||
next(); | ||
} |
@@ -5,16 +5,10 @@ /** | ||
const exports = { | ||
export default function (request, next) { | ||
request(request) { | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.method = 'POST'; | ||
} | ||
return request; | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.method = 'POST'; | ||
} | ||
}; | ||
export default exports; | ||
next(); | ||
} |
@@ -8,24 +8,19 @@ /** | ||
const exports = { | ||
export default function (request, next) { | ||
request(request) { | ||
if (request.emulateJSON && isPlainObject(request.data)) { | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.data = Url.params(request.data); | ||
} | ||
if (request.emulateJSON && isPlainObject(request.data)) { | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.data = Url.params(request.data); | ||
} | ||
if (isObject(request.data) && /FormData/i.test(request.data.toString())) { | ||
delete request.headers['Content-Type']; | ||
} | ||
if (isObject(request.data) && /FormData/i.test(request.data.toString())) { | ||
delete request.headers['Content-Type']; | ||
} | ||
if (isPlainObject(request.data)) { | ||
request.data = JSON.stringify(request.data); | ||
} | ||
if (isPlainObject(request.data)) { | ||
request.data = JSON.stringify(request.data); | ||
} | ||
next((response) => { | ||
return request; | ||
}, | ||
response(response) { | ||
try { | ||
@@ -35,7 +30,3 @@ response.data = JSON.parse(response.data); | ||
return response; | ||
} | ||
}; | ||
export default exports; | ||
}); | ||
} |
@@ -5,29 +5,17 @@ /** | ||
const exports = function () { | ||
export default function (request, next) { | ||
var timeout; | ||
return { | ||
if (request.timeout) { | ||
timeout = setTimeout(() => { | ||
request.cancel(); | ||
}, request.timeout); | ||
} | ||
request(request) { | ||
next((response) => { | ||
if (request.timeout) { | ||
timeout = setTimeout(() => { | ||
request.cancel(); | ||
}, request.timeout); | ||
} | ||
clearTimeout(timeout); | ||
return request; | ||
}, | ||
response(response) { | ||
clearTimeout(timeout); | ||
return response; | ||
} | ||
}; | ||
}; | ||
export default exports; | ||
}); | ||
} |
@@ -22,4 +22,4 @@ /** | ||
vars: variables, | ||
expand: function (context) { | ||
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { | ||
expand(context) { | ||
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, (_, expression, literal) => { | ||
if (expression) { | ||
@@ -34,3 +34,3 @@ | ||
expression.split(/,/g).forEach(function (variable) { | ||
expression.split(/,/g).forEach((variable) => { | ||
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); | ||
@@ -80,7 +80,7 @@ values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3])); | ||
if (Array.isArray(value)) { | ||
value.filter(isDefined).forEach(function (value) { | ||
value.filter(isDefined).forEach((value) => { | ||
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); | ||
}); | ||
} else { | ||
Object.keys(value).forEach(function (k) { | ||
Object.keys(value).forEach((k) => { | ||
if (isDefined(value[k])) { | ||
@@ -95,7 +95,7 @@ result.push(encodeValue(operator, value[k], k)); | ||
if (Array.isArray(value)) { | ||
value.filter(isDefined).forEach(function (value) { | ||
value.filter(isDefined).forEach((value) => { | ||
tmp.push(encodeValue(operator, value)); | ||
}); | ||
} else { | ||
Object.keys(value).forEach(function (k) { | ||
Object.keys(value).forEach((k) => { | ||
if (isDefined(value[k])) { | ||
@@ -148,3 +148,3 @@ tmp.push(encodeURIComponent(k)); | ||
function encodeReserved(str) { | ||
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) { | ||
return str.split(/(%[0-9A-Fa-f]{2})/g).map((part) => { | ||
if (!/%[0-9A-Fa-f]/.test(part)) { | ||
@@ -151,0 +151,0 @@ part = encodeURI(part); |
@@ -5,7 +5,9 @@ /** | ||
var util = {}, config = {}, array = [], console = window.console; | ||
import Promise from './promise'; | ||
var debug = false, util = {}, array = []; | ||
export default function (Vue) { | ||
util = Vue.util; | ||
config = Vue.config; | ||
debug = Vue.config.debug || !Vue.config.silent; | ||
} | ||
@@ -16,3 +18,3 @@ | ||
export function warn(msg) { | ||
if (console && util.warn && (!config.silent || config.debug)) { | ||
if (typeof console !== 'undefined' && debug) { | ||
console.warn('[VueResource warn]: ' + msg); | ||
@@ -23,3 +25,3 @@ } | ||
export function error(msg) { | ||
if (console) { | ||
if (typeof console !== 'undefined') { | ||
console.error(msg); | ||
@@ -57,2 +59,13 @@ } | ||
export function when(value, fulfilled, rejected) { | ||
var promise = Promise.resolve(value); | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
export function options(fn, obj, opts) { | ||
@@ -59,0 +72,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
473096
14948