Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / burst / isolate-burst.js
blobf3f73ad15c9aa4ad3b5fac92617762cbafee7a8a
1 'use strict';
3 /**
4 * Isolate a burst, given a model and a list of models
5 */
6 function findBurstModels(_, collection, model) {
7 var startIndex = _.indexOf(collection, model);
8 var endIndex = startIndex + 1;
9 var result = [model];
10 var i;
12 if (startIndex < 0) return result;
14 if (!_.get(model, 'burstStart')) {
15 startIndex--;
17 i = _.at(collection, startIndex);
18 while (startIndex >= 0) {
19 result.unshift(i);
20 if (_.get(i, 'burstStart')) break; // Quit the loop
21 startIndex--;
23 if (startIndex >= 0) {
24 i = _.at(collection, startIndex);
29 while (
30 endIndex < collection.length &&
31 (i = _.at(collection, endIndex)) &&
32 !_.get(i, 'burstStart')
33 ) {
34 result.push(i);
35 endIndex++;
38 return result;
41 module.exports = findBurstModels;