Created
December 12, 2016 17:43
-
-
Save pitakill/09dffeaab8c76ddfc93120ca0daa1eba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* redsep backoffice | |
* */ | |
angular.module('redsep') | |
.factory('SharedData', ['$http', '$q', function($http, $q) { | |
var info = {}; | |
return $http.get('/api/v1/me').then(function(responseMe){ | |
info.user = responseMe.data; | |
if(info.user.channel){ | |
$http.get('/api/v1/channels/' + info.user.channel.id ).then(function(responseChannel){ | |
info.channel = responseChannel.data; | |
return info; | |
}); | |
} | |
return info; | |
}); | |
}]); | |
// Rewrite of the snippet above | |
angular | |
.module('redsep') | |
.factory('ShareData', [$http, $q, fuction($http, $q) { | |
var info = {}; | |
var me = $http.get('/api/v1/me') | |
var channels = $http.get('/api/v1/channels/' + info.user.channel.id ) | |
var promises = { | |
me: me, | |
channels: channels | |
}; | |
$q | |
.all(promises) | |
.then(function(responses){ | |
info.user = responses.me.data; | |
info.user.channel = responses.channels.data; | |
return info; | |
}) | |
.catch(function(errors){ | |
console.log(errors); | |
}) | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment