Skip to content

Commit 275dd89

Browse files
author
Sebastian Porto
committed
Remove unnecessary ajax request to get users
1 parent 6397881 commit 275dd89

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

js/polyhack.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
var Poly = angular.module('poly', []);
22

3-
Poly.controller('UserListController', function($scope, $http, $q) {
3+
Poly.factory('users', function () {
4+
return [
5+
{ "github" : "markmandel", "nick" : "[Neurotic]", "lang" : "Go, Clojure, J/Ruby" },
6+
{ "github" : "andrebuchanan", "nick" : "andrebuchanan", "lang" : "Node.js" },
7+
{ "github" : "aussiegeek", "nick" : "aussiegeek", "lang" : "Ruby, Go" },
8+
{ "github" : "mwotton", "nick" : "blackdog", "lang" : "Haskell, Ansible, not-Javascript, not-Go." },
9+
{ "github" : "bulkan", "nick" : "bulkan", "lang" : "Node.js" },
10+
{ "github" : "cgiffard", "nick" : "cgiffard", "lang" : "Node.js, Erlang" },
11+
{ "github" : "deoxxa", "nick" : "deoxxa", "lang" : "Node.js, C" },
12+
{ "github" : "eugeneware", "nick" : "eugeneware", "lang" : "Node.js" },
13+
{ "github" : "joshwnj", "nick" : "joshwnj", "lang" : "Node.js, PHP" },
14+
{ "github" : "michaelneale", "nick" : "michaelneale", "lang" : "Erlang, Clojure, Scala, Bash, Haskell, Go, Javascript." },
15+
{ "github" : "nicholasf", "nick" : "nicholasf", "lang" : "Elixir, Javascript, post Ruby, post Java." },
16+
{ "github" : "ocke", "nick" : "ocke", "lang" : "Javascript, PHP" },
17+
{ "github" : "pomke", "nick" : "pomke", "lang" : "Javascript, Python" },
18+
{ "github" : "rkstedman", "nick" : "rkstedman", "lang" : "Node.js" },
19+
{ "github" : "robzolkos", "nick" : "robzolkos", "lang" : "Ruby, Node.js, Javascript, Go" },
20+
{ "github" : "rvagg", "nick" : "rvagg", "lang" : "Node.js" },
21+
{ "github" : "SomeoneWeird", "nick" : "SomeoneWeird", "lang" : "Javascript, Go" },
22+
{ "github" : "sporto", "nick" : "sporto", "lang" : "Javascript, Ruby, Go" },
23+
{ "github" : "timoxley", "nick" : "timoxley", "lang" : "Node.js" },
24+
{ "github" : "yangwao", "nick" : "wao-ender", "lang" : "Node.js" }
25+
];
26+
});
427

5-
$http.get('./js/users.json').then(function(res) {
6-
$scope.details = {};
7-
$scope.users = res.data;
8-
var git = [];
9-
angular.forEach($scope.users, function(u) {
10-
git.push($http.get('https://api.github.com/users/'+u.github));
11-
});
12-
$q.all(git).then(function(res) {
13-
angular.forEach(res, function(item) {
14-
$scope.details[item.data.login] = item.data;
15-
});
28+
Poly.controller('UserListController', function($scope, $http, $q, users) {
29+
$scope.details = {};
30+
$scope.users = users;
31+
var git = [];
32+
angular.forEach($scope.users, function(u) {
33+
git.push($http.get('https://api.github.com/users/'+u.github));
34+
});
35+
$q.all(git).then(function(res) {
36+
angular.forEach(res, function(item) {
37+
$scope.details[item.data.login] = item.data;
1638
});
1739
});
1840
});

js/users.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)