[BaseObject] move to utils

This commit is contained in:
Spencer Alger 2015-05-07 22:49:27 -07:00
parent 9d6633d337
commit 4258f49d7b
3 changed files with 42 additions and 44 deletions

View file

@ -1,43 +0,0 @@
define(function (require) {
return function BaseObjectProvider() {
var _ = require('lodash');
var rison = require('utils/rison');
var angular = require('angular');
function BaseObject(attributes) {
// Set the attributes or default to an empty object
_.assign(this, attributes);
}
/**
* Returns the attirbutes for the objct
* @returns {object}
*/
BaseObject.prototype.toObject = function () {
// return just the data.
return _.omit(this, function (value, key) {
return key.charAt(0) === '$' || key.charAt(0) === '_' || _.isFunction(value);
});
};
/**
* Serialize the model to RISON
* @returns {string}
*/
BaseObject.prototype.toRISON = function () {
var obj = this.toObject();
// Use Angular to remove the private vars
return rison.encode(JSON.parse(angular.toJson(obj)));
};
/**
* Serialize the model to JSON
* @returns {object}
*/
BaseObject.prototype.toJSON = function () {
return this.toObject();
};
return BaseObject;
};
});

View file

@ -0,0 +1,41 @@
define(function (require) {
var _ = require('lodash');
var rison = require('utils/rison');
var angular = require('angular');
function BaseObject(attributes) {
// Set the attributes or default to an empty object
_.assign(this, attributes);
}
/**
* Returns the attirbutes for the objct
* @returns {object}
*/
BaseObject.prototype.toObject = function () {
// return just the data.
return _.omit(this, function (value, key) {
return key.charAt(0) === '$' || key.charAt(0) === '_' || _.isFunction(value);
});
};
/**
* Serialize the model to RISON
* @returns {string}
*/
BaseObject.prototype.toRISON = function () {
var obj = this.toObject();
// Use Angular to remove the private vars
return rison.encode(JSON.parse(angular.toJson(obj)));
};
/**
* Serialize the model to JSON
* @returns {object}
*/
BaseObject.prototype.toJSON = function () {
return this.toObject();
};
return BaseObject;
});

View file

@ -13,7 +13,7 @@ define(function (require) {
inject(function (_$rootScope_, Private) {
$rootScope = _$rootScope_;
BaseObject = Private(require('factories/base_object'));
BaseObject = require('utils/BaseObject');
});
});