From 971d3007c48e4017e15eba6c0651bd2f695edc1b Mon Sep 17 00:00:00 2001 From: Zack Yang Date: Thu, 13 Apr 2017 14:10:14 +0800 Subject: [PATCH 1/3] fix(bug): prevent modify options object through reference --- src/component/restful.provider.js | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/component/restful.provider.js b/src/component/restful.provider.js index 68e4885..fa2b426 100644 --- a/src/component/restful.provider.js +++ b/src/component/restful.provider.js @@ -21,9 +21,8 @@ class RestProvider { get: (uri, options) => { return makeRequest('get', uri, null, options); }, - post: (uri, data, files, options) => { + post: (uri, data, files, options = {}) => { if ('http' === config.service && Array.isArray(files)) { - options = options || {}; const base = options.basePath || config.basePath; const setting = { url: base + uri, @@ -32,12 +31,11 @@ class RestProvider { }; transformUploadSetting(setting, data, files); return Upload.upload(Object.assign(setting, options)); - } - else { + } else { return makeRequest('post', uri, data, options); } }, - put: (uri, data, files, options) => { + put: (uri, data, files, options = {}) => { if ('http' === config.service && Array.isArray(files)) { options = options || {}; const base = options.basePath || config.basePath; @@ -48,8 +46,7 @@ class RestProvider { }; transformUploadSetting(setting, data, files); return Upload.upload(Object.assign(setting, options)); - } - else { + } else { return makeRequest('put', uri, data, options); } }, @@ -60,7 +57,7 @@ class RestProvider { function transformUploadSetting(setting, data, files) { if (files[0] instanceof File) { - (files.length === 1) ? setting.data.file = files[0] : setting.data.files = files; + files.length === 1 ? (setting.data.file = files[0]) : (setting.data.files = files); } else { files.forEach(item => { if (item.key) { @@ -73,9 +70,9 @@ class RestProvider { } } - function makeRequest(verb, uri, data, options) { + function makeRequest(verb, uri, data, options = {}) { let defer = $q.defer(); - let reqConfig = options || {}; + let reqConfig = JSON.parse(JSON.stringify(options)); let base = reqConfig.basePath || config.basePath; //start with the uri let args = [base + uri]; @@ -97,13 +94,14 @@ class RestProvider { args.push(reqConfig); - rest[verb](args) - .then(function(res) { - defer.resolve(res); - }) - .catch(function(res) { - defer.reject(res); - }); + rest + [verb](args) + .then(function(res) { + defer.resolve(res); + }) + .catch(function(res) { + defer.reject(res); + }); return defer.promise; } From 0200205741fb74a7649493b52d409e616ac14f1f Mon Sep 17 00:00:00 2001 From: Zack Yang Date: Thu, 13 Apr 2017 14:21:05 +0800 Subject: [PATCH 2/3] style(format): modify rule for multiline --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index e8eb590..57049e3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,6 +19,7 @@ "__BASE_PATH__": true }, "rules": { + "no-unexpected-multiline": "off", "indent": [ "error", 2, From 4f8fef2c3a665a8059d69f8c6785d234b8182c07 Mon Sep 17 00:00:00 2001 From: Zack Yang Date: Thu, 13 Apr 2017 06:24:01 +0000 Subject: [PATCH 3/3] v1.4.2 --- dist/sanji-rest-ui.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 dist/sanji-rest-ui.js diff --git a/dist/sanji-rest-ui.js b/dist/sanji-rest-ui.js new file mode 100644 index 0000000..4f5b27d --- /dev/null +++ b/dist/sanji-rest-ui.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("angular"),require("ng-file-upload")):"function"==typeof define&&define.amd?define(["angular","ng-file-upload"],t):"object"==typeof exports?exports.sjRest=t(require("angular"),require("ng-file-upload")):e.sjRest=t(e.angular,e.ngFileUpload)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var u=n[r]={i:r,l:!1,exports:{}};return e[r].call(u.exports,u,u.exports,t),u.l=!0,u.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:{},o=e.defer(),c=JSON.parse(JSON.stringify(u)),f=c.basePath||a.basePath,l=[f+n];return t=t.toLowerCase(),t.match(/post|put/)&&l.push(r),t.match(/delete/)&&(c.data=r,c.headers?c.headers["Content-Type"]="application/json":c.headers={"Content-Type":"application/json"}),l.push(c),i[t](l).then(function(e){o.resolve(e)}).catch(function(e){o.reject(e)}),o.promise}var a=this.config,i=n.get(a.service);return{configure:function(e){return Object.assign(a,e)},get:function(e,t){return o("get",e,null,t)},post:function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("http"===a.service&&Array.isArray(n)){var c=i.basePath||a.basePath,f={url:c+e,method:"POST",data:{}};return u(f,t,n),r.upload(Object.assign(f,i))}return o("post",e,t,i)},put:function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("http"===a.service&&Array.isArray(n)){i=i||{};var c=i.basePath||a.basePath,f={url:c+e,method:"PUT",data:{}};return u(f,t,n),r.upload(Object.assign(f,i))}return o("put",e,t,i)},delete:function(e,t,n){return o("delete",e,t,n)}}}]}]),e}();o.$inject=u,t.default=o},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.sjRest=void 0;var u=n(2),o=r(u),a=n(3),i=r(a),c=n(0),f=r(c),l=n(1),s=r(l),p=o.default.module("sanji.rest",[i.default]).service("http",f.default).provider("rest",s.default).name;t.sjRest=p}])}); \ No newline at end of file diff --git a/package.json b/package.json index 49c685b..8362d6c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "sanji-rest-ui", "author": "Zack Yang (https://github.com/zack9433)", "description": "sanji-rest-ui UI", - "version": "0.0.0-semantic-released", + "version": "1.4.2", "main": "dist/sanji-rest-ui.js", "config": { "ghooks": {