-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
62 lines (51 loc) · 1.67 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
angular.module('statedatastreamApp')
.controller('MainCtrl', function ($scope, Sds, Api, Helper) {
Sds.init()
// Write stuff to stream
.write('repos.peter', Api.getRepos('petercrona'))
.write('repos.bambu', Api.getRepos('bumbu'))
.write('repos.ariutta', Api.getRepos('ariutta'))
.write('snapshotOfState[]', Helper.stateCopyFn)
.write('repos.freescale', Api.getRepos('Freescale'))
.write('snapshotOfState[]', Helper.stateCopyFn)
// Attach handlers to stream
.error(function(err, state) {
console.log('error', err, state);
})
.execute(function(state) {
console.log('state', state);
});
})
// Dummy API with some open APIs found on the Internet.
.service('Api', function($http) {
this.getRepos = function(username) {
return $http.get('https://api.github.com/users/'+username+'/repos');
};
this.getWeather = function(city) {
return $http.get('http://api.openweathermap.org/data/2.5/weather?q='+city);
};
this.listAgencies = function() {
return $http.jsonp('http://govdata.se/api/lista?jsonp=JSON_CALLBACK');
};
this.getReposLazy = function(username) {
return function() {
return $http.get('https://api.github.com/users/'+username+'/repos');
};
};
this.getWeatherLazy = function(city) {
return function() {
return $http.get('http://api.openweathermap.org/data/2.5/weather?q='+city);
};
};
this.listAgenciesLazy = function() {
return function() {
return $http.jsonp('http://govdata.se/api/lista?jsonp=JSON_CALLBACK');
};
};
})
.service('Helper', function() {
this.stateCopyFn = function stateCopyFn(state) {
return JSON.parse(JSON.stringify(state));
};
});