diff --git a/bower.json b/bower.json index 56c0dd8e..c704622b 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "vue-resource", "main": "dist/vue-resource.js", "description": "A web request service for Vue.js", - "version": "0.7.0", + "version": "0.7.1", "homepage": "https://github.com/vuejs/vue-resource", "license": "MIT", "ignore": [ diff --git a/build/webpack.build.config.js b/build/webpack.build.config.js index 8ede26bc..53d9df49 100644 --- a/build/webpack.build.config.js +++ b/build/webpack.build.config.js @@ -17,6 +17,11 @@ module.exports = [ library: "VueResource", libraryTarget: "umd" }, + module: { + loaders: [ + {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015-without-strict']}} + ] + }, plugins: [ new webpack.BannerPlugin(banner, {raw: true}) ] @@ -30,6 +35,11 @@ module.exports = [ library: "VueResource", libraryTarget: "umd" }, + module: { + loaders: [ + {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015-without-strict']}} + ] + }, plugins: [ new webpack.optimize.UglifyJsPlugin, new webpack.BannerPlugin(banner, {raw: true}) diff --git a/dist/vue-resource.js b/dist/vue-resource.js index 7d61b480..cf69b805 100644 --- a/dist/vue-resource.js +++ b/dist/vue-resource.js @@ -1,5 +1,5 @@ /** - * vue-resource v0.7.0 + * vue-resource v0.7.1 * https://github.com/vuejs/vue-resource * Released under the MIT License. */ @@ -64,7 +64,11 @@ return /******/ (function(modules) { // webpackBootstrap * Install plugin. */ - function install(Vue) { + function plugin(Vue) { + + if (plugin.installed) { + return; + } var _ = __webpack_require__(1); @@ -80,50 +84,55 @@ return /******/ (function(modules) { // webpackBootstrap Object.defineProperties(Vue.prototype, { $url: { - get: function () { + get: function get() { return _.options(Vue.url, this, this.$options.url); } }, $http: { - get: function () { + get: function get() { return _.options(Vue.http, this, this.$options.http); } }, $resource: { - get: function () { + get: function get() { return Vue.resource.bind(this); } }, $promise: { - get: function () { + get: function get() { + var _this = this; + return function (executor) { - return new Vue.Promise(executor, this); - }.bind(this); + return new Vue.Promise(executor, _this); + }; } } }); } - if (window.Vue) { - Vue.use(install); + if (typeof window !== 'undefined' && window.Vue) { + window.Vue.use(plugin); } - module.exports = install; - + module.exports = plugin; /***/ }, /* 1 */ /***/ function(module, exports) { + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + /** * Utility functions. */ - var _ = exports, array = [], console = window.console; + var _ = exports, + array = [], + console = window.console; _.warn = function (msg) { if (console && _.warning && (!_.config.silent || _.config.debug)) { @@ -156,7 +165,7 @@ return /******/ (function(modules) { // webpackBootstrap }; _.isObject = function (obj) { - return obj !== null && typeof obj === 'object'; + return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; }; _.isPlainObject = function (obj) { @@ -171,7 +180,7 @@ return /******/ (function(modules) { // webpackBootstrap options = options.call(obj); } - return _.merge(fn.bind({$vm: obj, $options: options}), fn, {$options: options}); + return _.merge(fn.bind({ $vm: obj, $options: options }), fn, { $options: options }); }; _.each = function (obj, iterator) { @@ -242,7 +251,6 @@ return /******/ (function(modules) { // webpackBootstrap } } - /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { @@ -257,10 +265,11 @@ return /******/ (function(modules) { // webpackBootstrap function Url(url, params) { - var options = url, transform; + var options = url, + transform; if (_.isString(url)) { - options = {url: url, params: params}; + options = { url: url, params: params }; } options = _.merge({}, Url.options, this.$options, options); @@ -286,12 +295,7 @@ return /******/ (function(modules) { // webpackBootstrap * Url transforms. */ - Url.transforms = [ - __webpack_require__(3), - __webpack_require__(5), - __webpack_require__(6), - __webpack_require__(7) - ]; + Url.transforms = [__webpack_require__(3), __webpack_require__(5), __webpack_require__(6), __webpack_require__(7)]; /** * Encodes a Url parameter string. @@ -301,7 +305,8 @@ return /******/ (function(modules) { // webpackBootstrap Url.params = function (obj) { - var params = [], escape = encodeURIComponent; + var params = [], + escape = encodeURIComponent; params.add = function (key, value) { @@ -356,7 +361,9 @@ return /******/ (function(modules) { // webpackBootstrap function serialize(params, obj, scope) { - var array = _.isArray(obj), plain = _.isPlainObject(obj), hash; + var array = _.isArray(obj), + plain = _.isPlainObject(obj), + hash; _.each(obj, function (value, key) { @@ -378,7 +385,6 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = _.url = Url; - /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { @@ -391,7 +397,8 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = function (options) { - var variables = [], url = UrlTemplate.expand(options.url, options.params, variables); + var variables = [], + url = UrlTemplate.expand(options.url, options.params, variables); variables.forEach(function (key) { delete options.params[key]; @@ -400,7 +407,6 @@ return /******/ (function(modules) { // webpackBootstrap return url; }; - /***/ }, /* 4 */ /***/ function(module, exports) { @@ -411,7 +417,8 @@ return /******/ (function(modules) { // webpackBootstrap exports.expand = function (url, params, variables) { - var tmpl = this.parse(url), expanded = tmpl.expand(params); + var tmpl = this.parse(url), + expanded = tmpl.expand(params); if (variables) { variables.push.apply(variables, tmpl.vars); @@ -422,15 +429,17 @@ return /******/ (function(modules) { // webpackBootstrap exports.parse = function (template) { - var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = []; + var operators = ['+', '#', '.', '/', ';', '?', '&'], + variables = []; return { vars: variables, - expand: function (context) { + expand: function expand(context) { return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { if (expression) { - var operator = null, values = []; + var operator = null, + values = []; if (operators.indexOf(expression.charAt(0)) !== -1) { operator = expression.charAt(0); @@ -457,7 +466,6 @@ return /******/ (function(modules) { // webpackBootstrap } else { return values.join(','); } - } else { return exports.encodeReserved(literal); } @@ -468,7 +476,8 @@ return /******/ (function(modules) { // webpackBootstrap exports.getValues = function (context, operator, key, modifier) { - var value = context[key], result = []; + var value = context[key], + result = []; if (this.isDefined(value) && value !== '') { if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { @@ -538,7 +547,7 @@ return /******/ (function(modules) { // webpackBootstrap exports.encodeValue = function (operator, value, key) { - value = (operator === '+' || operator === '#') ? this.encodeReserved(value) : encodeURIComponent(value); + value = operator === '+' || operator === '#' ? this.encodeReserved(value) : encodeURIComponent(value); if (key) { return encodeURIComponent(key) + '=' + value; @@ -556,7 +565,6 @@ return /******/ (function(modules) { // webpackBootstrap }).join(''); }; - /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { @@ -569,7 +577,8 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = function (options, next) { - var variables = [], url = next(options); + var variables = [], + url = next(options); url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { @@ -592,23 +601,14 @@ return /******/ (function(modules) { // webpackBootstrap function encodeUriSegment(value) { - return encodeUriQuery(value, true). - replace(/%26/gi, '&'). - replace(/%3D/gi, '='). - replace(/%2B/gi, '+'); + return encodeUriQuery(value, true).replace(/%26/gi, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+'); } function encodeUriQuery(value, spaces) { - return encodeURIComponent(value). - replace(/%40/gi, '@'). - replace(/%3A/gi, ':'). - replace(/%24/g, '$'). - replace(/%2C/gi, ','). - replace(/%20/g, (spaces ? '%20' : '+')); + return encodeURIComponent(value).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, spaces ? '%20' : '+'); } - /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { @@ -621,9 +621,11 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = function (options, next) { - var urlParams = Object.keys(_.url.options.params), query = {}, url = next(options); + var urlParams = Object.keys(_.url.options.params), + query = {}, + url = next(options); - _.each(options.params, function (value, key) { + _.each(options.params, function (value, key) { if (urlParams.indexOf(key) === -1) { query[key] = value; } @@ -638,7 +640,6 @@ return /******/ (function(modules) { // webpackBootstrap return url; }; - /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { @@ -660,7 +661,6 @@ return /******/ (function(modules) { // webpackBootstrap return url; }; - /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { @@ -673,22 +673,24 @@ return /******/ (function(modules) { // webpackBootstrap var Client = __webpack_require__(9); var Promise = __webpack_require__(10); var interceptor = __webpack_require__(13); - var jsonType = {'Content-Type': 'application/json'}; + var jsonType = { 'Content-Type': 'application/json' }; function Http(url, options) { + var _this = this; - var client = Client, request, promise; + var client = Client, + request, + promise; Http.interceptors.forEach(function (handler) { - client = interceptor(handler, this.$vm)(client); - }, this); + client = interceptor(handler, _this.$vm)(client); + }); - options = _.isObject(url) ? url : _.extend({url: url}, options); + options = _.isObject(url) ? url : _.extend({ url: url }, options); request = _.merge({}, Http.options, this.$options, options); promise = client(request).bind(this.$vm).then(function (response) { return response.ok ? response : Promise.reject(response); - }, function (response) { if (response instanceof Error) { @@ -724,23 +726,15 @@ return /******/ (function(modules) { // webpackBootstrap timeout: 0 }; - Http.interceptors = [ - __webpack_require__(14), - __webpack_require__(15), - __webpack_require__(16), - __webpack_require__(18), - __webpack_require__(19), - __webpack_require__(20), - __webpack_require__(21) - ]; + Http.interceptors = [__webpack_require__(14), __webpack_require__(15), __webpack_require__(16), __webpack_require__(18), __webpack_require__(19), __webpack_require__(20), __webpack_require__(21)]; Http.headers = { put: jsonType, post: jsonType, patch: jsonType, delete: jsonType, - common: {'Accept': 'application/json, text/plain, */*'}, - custom: {'X-Requested-With': 'XMLHttpRequest'} + common: { 'Accept': 'application/json, text/plain, */*' }, + custom: { 'X-Requested-With': 'XMLHttpRequest' } }; ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { @@ -758,13 +752,12 @@ return /******/ (function(modules) { // webpackBootstrap success = undefined; } - return this(url, _.extend({method: method, data: data, success: success}, options)); + return this(url, _.extend({ method: method, data: data, success: success }, options)); }; }); module.exports = _.http = Http; - /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { @@ -795,19 +788,20 @@ return /******/ (function(modules) { // webpackBootstrap return headers; }; - } response.ok = response.status >= 200 && response.status < 300; return response; }); - }; function parseHeaders(str) { - var headers = {}, value, name, i; + var headers = {}, + value, + name, + i; if (_.isString(str)) { _.each(str.split('\n'), function (row) { @@ -823,19 +817,16 @@ return /******/ (function(modules) { // webpackBootstrap } else { headers[name] = [headers[name], value]; } - } else { headers[name] = value; } - }); } return headers; } - /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { @@ -910,13 +901,12 @@ return /******/ (function(modules) { // webpackBootstrap p.finally = function (callback) { return this.then(function (value) { - callback.call(this); - return value; - }, function (reason) { - callback.call(this); - return PromiseObj.reject(reason); - } - ); + callback.call(this); + return value; + }, function (reason) { + callback.call(this); + return PromiseObj.reject(reason); + }); }; p.success = function (callback) { @@ -941,7 +931,7 @@ return /******/ (function(modules) { // webpackBootstrap _.warn('The `always` method has been deprecated. Use the `finally` method instead.'); - var cb = function (response) { + var cb = function cb(response) { return callback.call(this, response.data, response.status, response) || response; }; @@ -950,11 +940,12 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = Promise; - /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + /** * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) */ @@ -963,7 +954,7 @@ return /******/ (function(modules) { // webpackBootstrap var RESOLVED = 0; var REJECTED = 1; - var PENDING = 2; + var PENDING = 2; function Promise(executor) { @@ -998,7 +989,8 @@ return /******/ (function(modules) { // webpackBootstrap Promise.all = function all(iterable) { return new Promise(function (resolve, reject) { - var count = 0, result = []; + var count = 0, + result = []; if (iterable.length === 0) { resolve(result); @@ -1044,13 +1036,12 @@ return /******/ (function(modules) { // webpackBootstrap try { var then = x && x['then']; - if (x !== null && typeof x === 'object' && typeof then === 'function') { + 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); @@ -1135,7 +1126,6 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = Promise; - /***/ }, /* 12 */ /***/ function(module, exports, __webpack_require__) { @@ -1150,7 +1140,9 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = function (request) { return new Promise(function (resolve) { - var xhr = new XMLHttpRequest(), response = {request: request}, handler; + var xhr = new XMLHttpRequest(), + response = { request: request }, + handler; request.cancel = function () { xhr.abort(); @@ -1158,7 +1150,7 @@ return /******/ (function(modules) { // webpackBootstrap xhr.open(request.method, _.url(request), true); - handler = function (event) { + handler = function handler(event) { response.data = xhr.responseText; response.status = xhr.status; @@ -1191,7 +1183,6 @@ return /******/ (function(modules) { // webpackBootstrap }); }; - /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { @@ -1242,7 +1233,6 @@ return /******/ (function(modules) { // webpackBootstrap return promise.then(fulfilled, rejected); } - /***/ }, /* 14 */ /***/ function(module, exports, __webpack_require__) { @@ -1255,18 +1245,17 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { - request: function (request) { + request: function request(_request) { - if (_.isFunction(request.beforeSend)) { - request.beforeSend.call(this, request); + if (_.isFunction(_request.beforeSend)) { + _request.beforeSend.call(this, _request); } - return request; + return _request; } }; - /***/ }, /* 15 */ /***/ function(module, exports) { @@ -1281,28 +1270,27 @@ return /******/ (function(modules) { // webpackBootstrap return { - request: function (request) { + request: function request(_request) { - if (request.timeout) { + if (_request.timeout) { timeout = setTimeout(function () { - request.cancel(); - }, request.timeout); + _request.cancel(); + }, _request.timeout); } - return request; + return _request; }, - response: function (response) { + response: function response(_response) { clearTimeout(timeout); - return response; + return _response; } }; }; - /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { @@ -1315,18 +1303,17 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { - request: function (request) { + request: function request(_request) { - if (request.method == 'JSONP') { - request.client = jsonpClient; + if (_request.method == 'JSONP') { + _request.client = jsonpClient; } - return request; + return _request; } }; - /***/ }, /* 17 */ /***/ function(module, exports, __webpack_require__) { @@ -1341,11 +1328,14 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = function (request) { return new Promise(function (resolve) { - var callback = '_jsonp' + Math.random().toString(36).substr(2), response = {request: request, data: null}, handler, script; + var callback = '_jsonp' + Math.random().toString(36).substr(2), + response = { request: request, data: null }, + handler, + script; request.params[request.jsonp] = callback; request.cancel = function () { - handler({type: 'cancel'}); + handler({ type: 'cancel' }); }; script = document.createElement('script'); @@ -1357,7 +1347,7 @@ return /******/ (function(modules) { // webpackBootstrap response.data = data; }; - handler = function (event) { + handler = function handler(event) { if (event.type === 'load' && response.data !== null) { response.status = 200; @@ -1380,7 +1370,6 @@ return /******/ (function(modules) { // webpackBootstrap }); }; - /***/ }, /* 18 */ /***/ function(module, exports) { @@ -1391,19 +1380,18 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { - request: function (request) { + request: function request(_request) { - if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { - request.headers['X-HTTP-Method-Override'] = request.method; - request.method = 'POST'; + if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { + _request.headers['X-HTTP-Method-Override'] = _request.method; + _request.method = 'POST'; } - return request; + return _request; } }; - /***/ }, /* 19 */ /***/ function(module, exports, __webpack_require__) { @@ -1416,36 +1404,35 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { - request: function (request) { + request: function 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); } - return request; + return _request; }, - response: function (response) { + response: function response(_response) { try { - response.data = JSON.parse(response.data); + _response.data = JSON.parse(_response.data); } catch (e) {} - return response; + return _response; } }; - /***/ }, /* 20 */ /***/ function(module, exports, __webpack_require__) { @@ -1458,26 +1445,21 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { - request: function (request) { + request: function 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; + if (_.isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { + _.extend(_request.params, _request.data); + delete _request.data; } - return request; + return _request; } }; - /***/ }, /* 21 */ /***/ function(module, exports, __webpack_require__) { @@ -1493,22 +1475,22 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { - request: function (request) { + request: function 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 (!xhrCors) { - request.client = xdrClient; + _request.client = xdrClient; } - request.emulateHTTP = false; + _request.emulateHTTP = false; } - return request; + return _request; } }; @@ -1517,10 +1499,9 @@ return /******/ (function(modules) { // webpackBootstrap var requestUrl = _.url.parse(_.url(request)); - return (requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host); + return requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host; } - /***/ }, /* 22 */ /***/ function(module, exports, __webpack_require__) { @@ -1535,7 +1516,9 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = function (request) { return new Promise(function (resolve) { - var xdr = new XDomainRequest(), response = {request: request}, handler; + var xdr = new XDomainRequest(), + response = { request: request }, + handler; request.cancel = function () { xdr.abort(); @@ -1543,7 +1526,7 @@ return /******/ (function(modules) { // webpackBootstrap xdr.open(request.method, _.url(request), true); - handler = function (event) { + handler = function handler(event) { response.data = xdr.responseText; response.status = xdr.status; @@ -1563,7 +1546,6 @@ return /******/ (function(modules) { // webpackBootstrap }); }; - /***/ }, /* 23 */ /***/ function(module, exports, __webpack_require__) { @@ -1576,16 +1558,14 @@ return /******/ (function(modules) { // webpackBootstrap function Resource(url, params, actions, options) { - var self = this, resource = {}; + var self = this, + resource = {}; - actions = _.extend({}, - Resource.actions, - actions - ); + actions = _.extend({}, Resource.actions, actions); _.each(actions, function (action, name) { - action = _.merge({url: url, params: params || {}}, options, action); + action = _.merge({ url: url, params: params || {} }, options, action); resource[name] = function () { return (self.$http || _.http)(opts(action, arguments)); @@ -1597,7 +1577,11 @@ return /******/ (function(modules) { // webpackBootstrap function opts(action, args) { - var options = _.extend({}, action), params = {}, data, success, error; + var options = _.extend({}, action), + params = {}, + data, + success, + error; switch (args.length) { @@ -1621,7 +1605,6 @@ return /******/ (function(modules) { // webpackBootstrap success = args[1]; error = args[2]; - } else { params = args[0]; @@ -1668,18 +1651,17 @@ return /******/ (function(modules) { // webpackBootstrap Resource.actions = { - get: {method: 'GET'}, - save: {method: 'POST'}, - query: {method: 'GET'}, - update: {method: 'PUT'}, - remove: {method: 'DELETE'}, - delete: {method: 'DELETE'} + get: { method: 'GET' }, + save: { method: 'POST' }, + query: { method: 'GET' }, + update: { method: 'PUT' }, + remove: { method: 'DELETE' }, + delete: { method: 'DELETE' } }; module.exports = _.resource = Resource; - /***/ } /******/ ]) }); diff --git a/dist/vue-resource.min.js b/dist/vue-resource.min.js index 0a983121..330bf68a 100644 --- a/dist/vue-resource.min.js +++ b/dist/vue-resource.min.js @@ -1,7 +1,7 @@ /** - * vue-resource v0.7.0 + * vue-resource v0.7.1 * https://github.com/vuejs/vue-resource * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueResource=e():t.VueResource=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t){var e=n(1);e.config=t.config,e.warning=t.util.warn,e.nextTick=t.util.nextTick,t.url=n(2),t.http=n(8),t.resource=n(23),t.Promise=n(10),Object.defineProperties(t.prototype,{$url:{get:function(){return e.options(t.url,this,this.$options.url)}},$http:{get:function(){return e.options(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){return function(e){return new t.Promise(e,this)}.bind(this)}}})}window.Vue&&Vue.use(r),t.exports=r},function(t,e){function n(t,e,o){for(var i in e)o&&(r.isPlainObject(e[i])||r.isArray(e[i]))?(r.isPlainObject(e[i])&&!r.isPlainObject(t[i])&&(t[i]={}),r.isArray(e[i])&&!r.isArray(t[i])&&(t[i]=[]),n(t[i],e[i],o)):void 0!==e[i]&&(t[i]=e[i])}var r=e,o=[],i=window.console;r.warn=function(t){i&&r.warning&&(!r.config.silent||r.config.debug)&&i.warn("[VueResource warn]: "+t)},r.error=function(t){i&&i.error(t)},r.trim=function(t){return t.replace(/^\s*|\s*$/g,"")},r.toLower=function(t){return t?t.toLowerCase():""},r.isArray=Array.isArray,r.isString=function(t){return"string"==typeof t},r.isFunction=function(t){return"function"==typeof t},r.isObject=function(t){return null!==t&&"object"==typeof t},r.isPlainObject=function(t){return r.isObject(t)&&Object.getPrototypeOf(t)==Object.prototype},r.options=function(t,e,n){return n=n||{},r.isFunction(n)&&(n=n.call(e)),r.merge(t.bind({$vm:e,$options:n}),t,{$options:n})},r.each=function(t,e){var n,o;if("number"==typeof t.length)for(n=0;n=200&&t.status<300,t})}},function(t,e,n){function r(t,e){t instanceof i?this.promise=t:this.promise=new i(t.bind(e)),this.context=e}var o=n(1),i=window.Promise||n(11);r.all=function(t,e){return new r(i.all(t),e)},r.resolve=function(t,e){return new r(i.resolve(t),e)},r.reject=function(t,e){return new r(i.reject(t),e)},r.race=function(t,e){return new r(i.race(t),e)};var s=r.prototype;s.bind=function(t){return this.context=t,this},s.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},s["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),this.promise=this.promise["catch"](t),this},s["finally"]=function(t){return this.then(function(e){return t.call(this),e},function(e){return t.call(this),i.reject(e)})},s.success=function(t){return o.warn("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})},s.error=function(t){return o.warn("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})},s.always=function(t){o.warn("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)},t.exports=r},function(t,e,n){function r(t){this.state=a,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)}}var o=n(1),i=0,s=1,a=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 o(n){return function(r){s[n]=r,i+=1,i===t.length&&e(s)}}var i=0,s=[];0===t.length&&e(s);for(var a=0;a=200&&t.status<300,t})}},function(t,e,n){function r(t,e){t instanceof i?this.promise=t:this.promise=new i(t.bind(e)),this.context=e}var o=n(1),i=window.Promise||n(11);r.all=function(t,e){return new r(i.all(t),e)},r.resolve=function(t,e){return new r(i.resolve(t),e)},r.reject=function(t,e){return new r(i.reject(t),e)},r.race=function(t,e){return new r(i.race(t),e)};var s=r.prototype;s.bind=function(t){return this.context=t,this},s.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},s["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),this.promise=this.promise["catch"](t),this},s["finally"]=function(t){return this.then(function(e){return t.call(this),e},function(e){return t.call(this),i.reject(e)})},s.success=function(t){return o.warn("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})},s.error=function(t){return o.warn("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})},s.always=function(t){o.warn("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)},t.exports=r},function(t,e,n){function r(t){this.state=a,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)}}var o="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},i=n(1),s=0,u=1,a=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 o(n){return function(r){s[n]=r,i+=1,i===t.length&&e(s)}}var i=0,s=[];0===t.length&&e(s);for(var u=0;u { client = interceptor(handler, this.$vm)(client); - }, this); + }); options = _.isObject(url) ? url : _.extend({url: url}, options); request = _.merge({}, Http.options, this.$options, options); - promise = client(request).bind(this.$vm).then(function (response) { + promise = client(request).bind(this.$vm).then((response) => { return response.ok ? response : Promise.reject(response); - }, function (response) { + }, (response) => { if (response instanceof Error) { _.error(response); diff --git a/src/index.js b/src/index.js index ade72990..852d7236 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,11 @@ * Install plugin. */ -function install(Vue) { +function plugin(Vue) { + + if (plugin.installed) { + return; + } var _ = require('./util'); @@ -18,36 +22,34 @@ function install(Vue) { Object.defineProperties(Vue.prototype, { $url: { - get: function () { + get() { return _.options(Vue.url, this, this.$options.url); } }, $http: { - get: function () { + get() { return _.options(Vue.http, this, this.$options.http); } }, $resource: { - get: function () { + get() { return Vue.resource.bind(this); } }, $promise: { - get: function () { - return function (executor) { - return new Vue.Promise(executor, this); - }.bind(this); + get() { + return (executor) => new Vue.Promise(executor, this); } } }); } -if (window.Vue) { - Vue.use(install); +if (typeof window !== 'undefined' && window.Vue) { + window.Vue.use(plugin); } -module.exports = install; +module.exports = plugin; diff --git a/test/url.js b/test/url.js index e26debd8..9e333ae6 100644 --- a/test/url.js +++ b/test/url.js @@ -16,6 +16,13 @@ describe('Vue.url', function () { }); + it('data{/array}', function () { + + expect(Vue.url('data{?array}')).toBe('data'); + expect(Vue.url('data{?array}', {array: [1,2,3]})).toBe('data?array=1,2,3'); + + }); + it('{+path}data', function () { expect(Vue.url('{+path}data')).toBe('data'); diff --git a/test/webpack.config.js b/test/webpack.config.js index 88365884..f978c69e 100644 --- a/test/webpack.config.js +++ b/test/webpack.config.js @@ -3,5 +3,10 @@ module.exports = { output: { path: __dirname + "/", filename: "specs.js" + }, + module: { + loaders: [ + {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015-without-strict']}} + ] } };