(function () {
"use strict";
var app = angular.module('App', ['FatModelProvider']);
app.run([
'$FatModelProvider',
'$timeout',
'$q',
'$http',
function ($FatModelProvider, $timeout, $q, $http) {
var fetch = function () {
var defer = $q.defer();
$http({
method: 'GET',
url: 'http://localhost',
withCredentials: true
}).success(function () {
defer.resolve.apply(defer.resolve, arguments);
}).error(function () {
defer.reject.apply(defer.reject, arguments);
});
return defer.promise;
};
$FatModelProvider.register({
name: 'model-1',
promise: fetch,
refresh: true,
groups: ['group-1'],
success: function () {
console.log('success 1');
},
error: function () {
console.log('error 1');
}
});
$FatModelProvider.register({
name: 'model-2',
promise: fetch,
refresh: true,
groups: ['group-1'],
success: function () {
console.log('success 1');
},
error: function () {
console.log('error 1');
}
});
$FatModelProvider.register({
name: 'model-3',
promise: fetch,
refresh: true,
groups: ['other-group'],
success: function () {
console.log('success 1');
},
error: function () {
console.log('error 1');
}
});
$FatModelProvider.$on('FatModel:fetch:started', function () {
console.log('Started fetching');
});
$FatModelProvider.$on('FatModel:fetch:finished', function () {
console.log('Finished fetching - Do something when all models have been fetched!');
});
$FatModelProvider.$on('FatModel:fetch:error', function ($event, error) {
console.log('Fetching with errors', errors);
});
$FatModelProvider.getModel('model-1').$on('FatModel:fetch:started', function () {
console.log('Started fetching model-1');
});
$FatModelProvider.getModel('model-2').$on('FatModel:fetch:finished', function () {
console.log('Finished fetching model-1');
});
$FatModelProvider.$on('FatModel:fetch:main:started', function () {
console.log('Started fetching group main');
});
$FatModelProvider.$on('FatModel:fetch:main:finished', function () {
console.log('Finished fetching group main');
});
$FatModelProvider.fetch().then(function (response) {
console.log('All fetch response:', response);
});
$FatModelProvider.fetchGroup(['other']).then(function (response) {
console.log('Group fetch response:', response);
});
$FatModelProvider.getModel('model-1').fetch().then(function (response) {
console.log('Model-1 response:', response);
});
]);
})();