-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstores.js
118 lines (111 loc) · 3.29 KB
/
stores.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var Reflux = require('reflux');
var Immutable = require('immutable');
var actions = require('./actions');
var RepoStore = Reflux.createStore({
listenables: actions,
updateRepoListCompleted: function (data) {
this.state = data;
this.trigger(this.state);
}
});
var OwnerStore = Reflux.createStore({
init: function () {
this.listenTo(RepoStore, 'populate');
this.state = Immutable.Set();
},
populate: function (repos) {
this.state = repos.map(function (repo) {
return repo.get('owner').get('login');
}).toSet();
this.trigger(this.state);
},
getInitialState: function () {
return this.state;
}
});
var SelectedOwnerStore = Reflux.createStore({
listenables: actions,
init: function () {
this.state = "";
},
onSelectOwner: function (owner) {
if (owner) {
this.state = owner;
}
else {
this.state = "";
}
this.trigger(this.state);
},
getInitialState: function () {
return this.state;
}
});
var PRStore = Reflux.createStore({
listenables: actions,
init: function () {
this.state = Immutable.List([]);
},
updatePRListCompleted: function (data) {
var updated = data.map(function (pr) { return pr.get('id'); });
this.state = this.state.filterNot(function (pr) {
return updated.find(function (id) { return pr.get('id') === id; });
}).merge(data);
this.trigger(this.state);
}
});
var RepoDisplayStore = Reflux.createStore({
listenables: actions,
init: function () {
this.listenTo(RepoStore, 'updateRepos');
this.listenTo(PRStore, 'updatePRCounts');
this.state = Immutable.List([]);
this.filter = function () { return true; };
},
output: function () {
this.trigger(this.state.filter(this.filter).sortBy(function (repo) { return repo.get('count'); }).reverse());
},
onFilterByOwner: function (owner) {
if (owner) {
this.filter = function (repo) {
return repo.get('owner') === owner;
};
}
else {
this.filter = function () { return true; };
}
this.output();
},
updateRepos: function (repos) {
this.state = repos.map(function (repo) {
return Immutable.Map({
id: repo.get('id'),
owner: repo.get('owner').get('login'),
name: repo.get('name'),
count: 0
});
});
this.output();
},
updatePRCounts: function (prs) {
this.state = this.state.map(function (repo) {
var pr_count = prs.filter(function (pr) {
return pr.get('head').get('repo').get('id') === repo.get('id');
}).size;
if (pr_count) {
return repo.set('count', pr_count);
}
else {
return repo;
}
});
this.output();
},
getInitialState: function () {
console.log('repostore initial state call', this.state);
return this.state;
}
});
module.exports.RepoDisplayStore = RepoDisplayStore;
module.exports.OwnerStore = OwnerStore;
module.exports.SelectedOwnerStore = SelectedOwnerStore;