patch-resource
Version:
JSON Patch extension for Angular's ngResource module
3 lines (2 loc) • 1.1 kB
JavaScript
;function patchResourceService(e){return function(){for(var r=arguments.length,t=Array(r>3?r-3:0),o=3;o<r;o++)t[o-3]=arguments[o];var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=void 0;if(a.patch)throw new Error('PatchResource: "Patch" is already extended with an action');return a.patch={method:"PATCH",transformRequest:function(e){var r=observers.filter(function(r){return r.resourceObject===e})[0],t=void 0;if(!r)throw new Error("No JSON Patch observer available for $patch");return t=window.jsonpatch.generate(r.observer),window.angular.toJson(t)}},s=e.apply(void 0,[n,c,a].concat(t)),s.__get=s.get,s.get=function(){var e=this.__get.apply(this,arguments);return e.$promise.then(function(){observers.push({resourceObject:e,observer:window.jsonpatch.observe(e)})}),e},s}}var observers=[];window.angular.module("patchResource",["ngResource"]).service("$patchResource",["$resource",patchResourceService]);
//# sourceMappingURL=patch-resource.min.js.map