Skip to content

Commit

Permalink
Add built dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrom committed Oct 18, 2016
1 parent 2fb4db0 commit 9a68bcb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 29 deletions.
103 changes: 76 additions & 27 deletions dist/restangular.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/**
* Restful Resources service for AngularJS apps
* @version v1.5.2 - 2016-02-08 * @link https://github.com/mgonto/restangular
* @version v1.5.2 - 2016-10-18 * @link https://github.com/mgonto/restangular
* @author Martin Gontovnikas <martin@gon.to>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/(function() {
*/(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/templates/returnExports.js
if (typeof define === 'function' && define.amd) {
define(['lodash', 'angular'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('lodash'), require('angular'));
} else {
// No global export, Restangular will register itself as Angular.js module
factory(root._, root.angular);
}
}(this, function (_, angular) {

var restangular = angular.module('restangular', []);

Expand Down Expand Up @@ -61,6 +71,15 @@ restangular.provider('Restangular', function() {
return this;
};

/**
* Always return plain data, no restangularized object
**/
config.plainByDefault = config.plainByDefault || false;
object.setPlainByDefault = function(value) {
config.plainByDefault = value === true ? true : false;
return this;
};

config.withHttpValues = function(httpLocalConfig, obj) {
return _.defaults(obj, httpLocalConfig, config.defaultHttpFields);
};
Expand Down Expand Up @@ -188,12 +207,14 @@ restangular.provider('Restangular', function() {
oneUrl: 'oneUrl',
allUrl: 'allUrl',
customPUT: 'customPUT',
customPATCH: 'customPATCH',
customPOST: 'customPOST',
customDELETE: 'customDELETE',
customGET: 'customGET',
customGETLIST: 'customGETLIST',
customOperation: 'customOperation',
doPUT: 'doPUT',
doPATCH: 'doPATCH',
doPOST: 'doPOST',
doDELETE: 'doDELETE',
doGET: 'doGET',
Expand Down Expand Up @@ -424,6 +445,7 @@ restangular.provider('Restangular', function() {
* Add element transformers for certain routes.
*/
config.transformers = config.transformers || {};
config.matchTransformers = config.matchTransformers || [];
object.addElementTransformer = function(type, secondArg, thirdArg) {
var isCollection = null;
var transformer = null;
Expand All @@ -434,17 +456,24 @@ restangular.provider('Restangular', function() {
isCollection = secondArg;
}

var typeTransformers = config.transformers[type];
if (!typeTransformers) {
typeTransformers = config.transformers[type] = [];
}

typeTransformers.push(function(coll, elem) {
var transformerFn = function(coll, elem) {
if (_.isNull(isCollection) || (coll === isCollection)) {
return transformer(elem);
}
return elem;
});
};

if (_.isRegExp(type)) {
config.matchTransformers.push({
regexp: type,
transformer: transformerFn
});
} else {
if (!config.transformers[type]) {
config.transformers[type] = [];
}
config.transformers[type].push(transformerFn);
}

return object;
};
Expand All @@ -461,8 +490,19 @@ restangular.provider('Restangular', function() {
if (!force && !config.transformLocalElements && !elem[config.restangularFields.fromServer]) {
return elem;
}
var typeTransformers = config.transformers[route];

var changedElem = elem;

var matchTransformers = config.matchTransformers;
if (matchTransformers) {
_.each(matchTransformers, function (transformer) {
if (route.match(transformer.regexp)) {
changedElem = transformer.transformer(isCollection, changedElem);
}
});
}

var typeTransformers = config.transformers[route];
if (typeTransformers) {
_.each(typeTransformers, function(transformer) {
changedElem = transformer(isCollection, changedElem);
Expand Down Expand Up @@ -641,7 +681,7 @@ restangular.provider('Restangular', function() {
Path.prototype = new BaseCreator();

Path.prototype.normalizeUrl = function (url){
var parts = /(http[s]?:\/\/)?(.*)?/.exec(url);
var parts = /((?:http[s]?:)?\/\/)?(.*)?/.exec(url);
parts[2] = parts[2].replace(/[\\\/]+/g, '/');
return (typeof parts[1] !== 'undefined')? parts[1] + parts[2] : parts[2];
};
Expand Down Expand Up @@ -927,20 +967,16 @@ restangular.provider('Restangular', function() {

function addCustomOperation(elem) {
elem[config.restangularFields.customOperation] = _.bind(customFunction, elem);
_.each(['put', 'post', 'get', 'delete'], function(oper) {
var requestMethods = { get: customFunction, delete: customFunction };
_.each(['put', 'patch', 'post'], function(name) {
requestMethods[name] = function(operation, elem, path, params, headers) {
return _.bind(customFunction, this)(operation, path, params, headers, elem);
};
});
_.each(requestMethods, function(requestFunc, name) {
var callOperation = name === 'delete' ? 'remove' : name;
_.each(['do', 'custom'], function(alias) {
var callOperation = oper === 'delete' ? 'remove' : oper;
var name = alias + oper.toUpperCase();
var callFunction;

if (callOperation !== 'put' && callOperation !== 'post') {
callFunction = customFunction;
} else {
callFunction = function(operation, elem, path, params, headers) {
return _.bind(customFunction, this)(operation, path, params, headers, elem);
};
}
elem[name] = _.bind(callFunction, elem, callOperation);
elem[alias + name.toUpperCase()] = _.bind(requestFunc, elem, callOperation);
});
});
elem[config.restangularFields.customGETLIST] = _.bind(fetchFunction, elem);
Expand Down Expand Up @@ -1006,7 +1042,9 @@ restangular.provider('Restangular', function() {
function restangularizeCollectionAndElements(parent, element, route) {
var collection = restangularizeCollection(parent, element, route, false);
_.each(collection, function(elem) {
restangularizeElem(parent, elem, route, false);
if (elem) {
restangularizeElem(parent, elem, route, false);
}
});
return collection;
}
Expand Down Expand Up @@ -1074,6 +1112,11 @@ restangular.provider('Restangular', function() {
if (!_.isArray(data)) {
throw new Error('Response for getList SHOULD be an array and not an object or something else');
}

if (true === config.plainByDefault) {
return resolvePromise(deferred, response, data, filledArray);
}

var processedData = _.map(data, function(elem) {
if (!__this[config.restangularFields.restangularCollection]) {
return restangularizeElem(__this, elem, what, true, data);
Expand Down Expand Up @@ -1164,8 +1207,14 @@ restangular.provider('Restangular', function() {
var resData = response.data;
var fullParams = response.config.params;
var elem = parseResponse(resData, operation, route, fetchUrl, response, deferred);

if (elem) {
var data;

if (true === config.plainByDefault) {
return resolvePromise(deferred, response, elem, filledObject);
}

if (operation === 'post' && !__this[config.restangularFields.restangularCollection]) {
data = restangularizeElem(
__this[config.restangularFields.parentResource],
Expand Down Expand Up @@ -1351,5 +1400,5 @@ restangular.provider('Restangular', function() {
return createServiceForConfiguration(globalConfiguration);
}];
});

})();
return restangular.name;
}));
Loading

0 comments on commit 9a68bcb

Please sign in to comment.