nci/static/js/app/stores/builds.js

42 lines
833 B
JavaScript
Raw Normal View History

2015-05-07 21:55:40 +00:00
'use strict';
define([
'underscore',
'reflux', 'app/actions/build', 'app/resources'
], function(_, Reflux, BuildActions, resources) {
var resource = resources.builds;
var Store = Reflux.createStore({
listenables: BuildActions,
builds: [],
2015-05-10 10:04:54 +00:00
onChange: function(data, action) {
var oldBuild = _(this.builds).findWhere({id: data.buildId});
2015-05-07 21:55:40 +00:00
if (oldBuild) {
2015-05-10 10:04:54 +00:00
_(oldBuild).extend(data.changes);
2015-05-07 21:55:40 +00:00
} else {
2015-05-10 10:04:54 +00:00
this.builds.unshift(
_({id: data.buildId}).extend(data.changes)
);
2015-05-07 21:55:40 +00:00
}
this.trigger(this.builds);
},
init: function() {
2015-05-10 10:04:54 +00:00
resource.subscribe('change', this.onChange);
2015-05-07 21:55:40 +00:00
},
onReadAll: function() {
var self = this;
2015-05-17 13:48:16 +00:00
resource.sync('readAll', function(err, builds) {
2015-05-15 05:43:57 +00:00
if (err) throw err;
self.builds = builds;
self.trigger(self.builds);
2015-05-07 21:55:40 +00:00
});
2015-05-17 13:48:16 +00:00
},
2015-05-07 21:55:40 +00:00
});
return Store;
});