Skip to content

Instantly share code, notes, and snippets.

@freidamachoi
Created May 20, 2014 16:50
Show Gist options
  • Save freidamachoi/51ed79e1f39e07fac015 to your computer and use it in GitHub Desktop.
Save freidamachoi/51ed79e1f39e07fac015 to your computer and use it in GitHub Desktop.
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
angular.module('myApp', ['ngCookies']).factory('BaseObject', [
'$log', '$http', function($log, $http) {
var BaseObject;
return BaseObject = (function() {
function BaseObject(options) {
this.options = options;
}
BaseObject.prototype.send = function(args) {
$log.log('sending', args);
return $http(args);
};
return BaseObject;
})();
}
]).factory('ParentObject', [
'BaseObject', '$cookies', function(BaseObject, $cookies) {
var ParentObject;
return ParentObject = (function(_super) {
__extends(ParentObject, _super);
function ParentObject(options) {
ParentObject.__super__.constructor.call(this, options);
$log.log('Parent created with', options);
}
ParentObject.prototype.save = function() {
return this.send(this);
};
return ParentObject;
})(BaseObject);
}
]).factory('ChildObject', [
'ParentObject', function(ParentObject) {
var ChildObject;
return ChildObject = (function(_super) {
__extends(ChildObject, _super);
function ChildObject() {
return ChildObject.__super__.constructor.apply(this, arguments);
}
ChildObject.prototype.save = function() {
this.name = 'child';
return ChildObject.__super__.save.call(this);
};
return ChildObject;
})(ParentObject);
}
]).factory('SingletonObject', [
'BaseObject', function(BaseObject) {
var SingletonObject;
SingletonObject = (function(_super) {
__extends(SingletonObject, _super);
function SingletonObject() {
return SingletonObject.__super__.constructor.apply(this, arguments);
}
SingletonObject.prototype.get = function(args) {
return this.send(args);
};
return SingletonObject;
})(BaseObject);
return new SingletonObject();
}
]).controller('MyCtrl', [
'$scope', 'ChildObject', 'SingletonObject', function($scope, ChildObject, SingletonObject) {
$scope.item = new ChildObject();
return SingletonObject.get().then(function(data) {
return $scope.options = data;
});
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment