There is a model User.js :
app.factory('User', function($http, Settings, ..., AnotherModel) { var settings, instance = { inited: false, loading: false, // ... anotherData: ..., behaviorMethod1: function(params) { // ... }, behaviorMethod2: function() { // ... } }; return function(){ if(instance.inited || instance.loading) return instance; instance.loading = true; $http.get('/user').then(function(response) { angular.extend(instance, response.data); instance.settings = new Settings(); // ... instance.anotherModel = new AnotherModel(); }); var loaded = 0, countLoaded = function() { loaded++; if(loaded == n) { instance.inited = true; instance.loading = false; $rootScope.$broadcast('user:loaded'); } }; $rootScope.$on('settings:loaded', countLoaded); // ... $rootScope.$on('anotherModel:loaded', countLoaded); $rootScope.$on('settings:save', function() { instance.settings = new Settings(); }); // ... $rootScope.$on('anotherModel:event', function() { instance.anotherModel = new AnotherModel(); }); return instance; }; }); It has several dependencies (about 10-20) of the form, such as, for example, Settings.js :
app.factory('Settings', function($http, $rootScope, ...) { var instance = { inited: false, loading: false, // ... anotherData: ..., behaviorMethod1: function() { // ... }, save: function() { $http.put('/settings', instance, function() { // ... instance.inited = false; $rootScope.$broadcast('settings:save'); }); } }; return function() { if(instance.inited || instance.loading) return instance; instance.loading = true; $http.get('/settings').then(function(response) { // ... angular.extend(instance, response.data); instance.inited = true; instance.loading = false; $rootScope.$broadcast('settings:loaded'); }); return instance; }; }); In general, this implementation copes with its responsibilities, if not for one thing: you have to wait until all relations of this model are fully loaded and the number of requests to the server increases. BUT! It is not necessary every time when any of the relations changes to load all the data again, but only to load some of them - this reduces the number of queries to the database. Question: in your opinion, what is wrong here? What can be improved?
For reference, not all of the requests to the server mean CRUD actions and cannot always return the changed data, but you have to reload the model after such actions.