Skip to content

Instantly share code, notes, and snippets.

@SinisterMinister
Created November 20, 2013 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SinisterMinister/7555897 to your computer and use it in GitHub Desktop.
Save SinisterMinister/7555897 to your computer and use it in GitHub Desktop.
var _ = require('underscore');
Kumo.AppsAppController = Ember.ObjectController.extend({
branches: null,
_refreshContainer: null,
_active: false,
init: function () {
var self = this;
this._super();
Kumo.PollManager.addPoller('app.branches', 10, function () {
self._refreshBranches();
});
},
_refreshBranches: function () {
var self = this;
ORM.factory('branch').where('repositoryId').isEqual(self.get('repositoryId')).findAll().then(function (branches) {
var toAdd = [], toRemove = [];
_.each(self.get('branches'), function (branch) {
var has = false;
for (var i = branches.length - 1; i >= 0; i--) {
if (branches[i].get('id') === branch.get('id')) {
has = true;
break;
}
}
if ( ! has)
toRemove.push(branch);
});
_.each(branches, function (branch) {
var has = false;
for (var i = self.get('branches').length - 1; i >= 0; i--) {
if (self.get('branches')[i].get('id') === branch.get('id')) {
has = true;
self.get('branches')[i].reload();
break;
}
}
if ( ! has)
toAdd.push(branch);
});
self.get('branches').removeObjects(toRemove);
self.get('branches').pushObjects(toAdd);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment