Skip to content

Commit dd898a8

Browse files
committed
Make the filter function global
1 parent 199c24d commit dd898a8

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

website/src/queries-logic.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ let RATE_LIMIT_EXCEEDED;
99
let AHEAD_COMMITS_FILTER;
1010
let TOTAL_API_CALLS_COUNTER;
1111
let ONGOING_REQUESTS_COUNTER = 0;
12+
let IS_USEFUL_FORK; // function that determines if a fork is useful or not
13+
1214

1315
/** Used to reset the state for a brand new query. */
1416
function clear_old_data() {
@@ -184,16 +186,16 @@ function compareDates(date, html) {
184186
return REPO_DATE <= new Date(date) ? `<strong>${html}</strong>` : html;
185187
}
186188

187-
function update_table_trying_use_filter(is_useful_fork) {
188-
if (typeof is_useful_fork === 'function') {
189-
update_table(TABLE_DATA.filter(is_useful_fork));
189+
function update_table_trying_use_filter() {
190+
if (typeof IS_USEFUL_FORK === 'function') {
191+
update_table(TABLE_DATA.filter(IS_USEFUL_FORK));
190192
} else {
191193
update_table(TABLE_DATA);
192194
}
193195
}
194196

195197
/** Updates table data, then calls function to update the table. */
196-
function update_table_data(responseData, user, repo, parentDefaultBranch, is_useful_fork) {
198+
function update_table_data(responseData, user, repo, parentDefaultBranch) {
197199
if (isEmpty(responseData)) {
198200
return;
199201
}
@@ -230,7 +232,7 @@ function update_table_data(responseData, user, repo, parentDefaultBranch, is_use
230232
TABLE_DATA.push(datum);
231233
if (TABLE_DATA.length > 1) showFilterContainer();
232234

233-
update_table_trying_use_filter(is_useful_fork);
235+
update_table_trying_use_filter();
234236
}
235237
};
236238
const onFailure = () => { }; // do nothing
@@ -244,8 +246,8 @@ function update_table_data(responseData, user, repo, parentDefaultBranch, is_use
244246
}
245247

246248
function update_filter() {
247-
let is_useful_fork = getFilterFunction()
248-
update_table_trying_use_filter(is_useful_fork);
249+
updateFilterFunction();
250+
update_table_trying_use_filter();
249251

250252
updateBasedOnTable();
251253
}
@@ -282,7 +284,7 @@ function update_table(data) {
282284
* 2. Filter string is a list of conditions separated by spaces.
283285
* 3. If a condition is invalid, it is ignored, and the rest of the conditions are applied.
284286
*/
285-
function getFilterFunction() {
287+
function updateFilterFunction() {
286288
const filter = getFilterOrDefault();
287289
if (filter === '') {
288290
return; // no filter
@@ -318,8 +320,8 @@ function getFilterFunction() {
318320
}
319321
conditionObj[attribute] = { operator, value };
320322
}
321-
// construct filter function 'is_useful_fork'
322-
let is_useful_fork = (datum) => {
323+
324+
IS_USEFUL_FORK = (datum) => {
323325
for (const [attribute, { operator, value }] of Object.entries(conditionObj)) {
324326
switch (operator) {
325327
case '>':
@@ -346,7 +348,6 @@ function getFilterFunction() {
346348
}
347349
return true;
348350
}
349-
return is_useful_fork;
350351
}
351352

352353
/** Paginated (index starts at 1) recursive forks scan. */
@@ -378,12 +379,7 @@ function request_fork_page(page_number, user, repo, defaultBranch) {
378379
}
379380
}
380381

381-
let is_useful_fork = getFilterFunction()
382-
if (typeof is_useful_fork === 'function') {
383-
update_table_data(responseData, user, repo, defaultBranch, is_useful_fork);
384-
} else {
385-
update_table_data(responseData, user, repo, defaultBranch);
386-
}
382+
update_table_data(responseData, user, repo, defaultBranch);
387383
};
388384
const onFailure = () => displayConditionalErrorMsg();
389385
send(requestPromise, onSuccess, onFailure);

0 commit comments

Comments
 (0)