all files / src/ configuration.js

20% Statements 3/15
0% Branches 0/12
0% Functions 0/2
20% Lines 3/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                                                                                           
/* globals angular */
 
angular
	.module( "absync" )
	.service( "AbsyncServiceConfiguration", AbsyncServiceConfigurationFactory );
 
function AbsyncServiceConfigurationFactory() {
	return AbsyncServiceConfiguration;
}
 
/**
 * Configuration for an absync service.
 * Using this type is entirely optional. Providing a hash with the same configuration options will work just fine.
 * @param {Object|String} model Reference to a constructor for the model type, or it's name.
 * If a name is given, absync will try to retrieve instances of the type through injection.
 * @param {String} collectionUri The REST API URI where the collection can be found.
 * Must not end with /
 * @param {String} entityUri The REST API URI where single entities out of the collection can be found.
 * Must not end with /
 * @param {String} [collectionName] The name of the collection. Uses the model name suffixed with "s" by default.
 * Using the default value is not recommended.
 * @param {String} [entityName] The name of an entity. Uses the model name by default.
 * Using the default value is not recommended.
 * @param {Function} [deserialize] A function that takes an object received from the server and turns it into a model.
 * By default, absync will just store the raw object without extending it to the model type.
 * Deserializers operate on the actual data received from the websocket.
 * @param {Function} [serialize] A function that takes a model and turns it into something the server expects.
 * By default, absync will just send the complete model.
 * Serializers operate on a copy of the actual model, which already had complex members reduced to their IDs.
 * @param {Function} [injector] An injector to use for model instantiation. Uses $injector by default.
 * Usually, you don't need to provide an alternative here.
 * @param {Boolean} [debug=false] Should additional debugging output be enabled?
 * @param {Object} [allowBrowserCache] A hash that controls the browsing caching behavior.
 * @constructor
 */
function AbsyncServiceConfiguration( model, collectionUri, entityUri, collectionName, entityName, deserialize, serialize, injector, debug, allowBrowserCache ) {
	this.model         = model;
	this.collectionUri = collectionUri;
	this.entityUri     = entityUri;
 
	var _modelName      = model.prototype.constructor.name.toLowerCase();
	this.collectionName = collectionName || ( _modelName + "s" );
	this.entityName     = entityName || _modelName;
 
	this.deserialize = deserialize || undefined;
	this.serialize   = serialize || undefined;
 
	this.injector = injector || undefined;
 
	this.debug = debug || false;
 
	this.allowBrowserCache = angular.merge( {}, {
		sync    : true,
		request : true
	}, allowBrowserCache );
}