topMatchesComponent.js
1.13 KB
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
import jsonpatch from 'fast-json-patch/src/json-patch';
angular.module('footyroom')
.component('topMatches', {
controller: ['livescores', '$rootScope', function (livescores, $rootScope) {
var ctrl = this;
ctrl.$onInit = init;
function init() {
var lsSocket = livescores.connect();
lsSocket.on('top-matches', onFullData);
lsSocket.on('top-matches-patches', onPatches);
lsSocket.on('connect', function () {
lsSocket.emit('subscribe-top');
});
}
function onFullData(data) {
ctrl.matchesById = data.matchesById;
processMatches();
}
function onPatches(data) {
jsonpatch.apply(ctrl.matchesById, data.patches);
processMatches();
}
function processMatches() {
ctrl.matches = _.sortBy(ctrl.matchesById, function (match) {
return match.datetime;
});
ctrl.show = ctrl.matches.length > 0;
$rootScope.$apply();
}
}],
templateUrl: '/views/ng/topMatches/topMatches.html?3',
});