mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 22:55:08 +00:00
42 lines
833 B
JavaScript
42 lines
833 B
JavaScript
'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: [],
|
|
|
|
onChange: function(data, action) {
|
|
var oldBuild = _(this.builds).findWhere({id: data.buildId});
|
|
if (oldBuild) {
|
|
_(oldBuild).extend(data.changes);
|
|
} else {
|
|
this.builds.unshift(
|
|
_({id: data.buildId}).extend(data.changes)
|
|
);
|
|
}
|
|
|
|
this.trigger(this.builds);
|
|
},
|
|
|
|
init: function() {
|
|
resource.subscribe('change', this.onChange);
|
|
},
|
|
|
|
onReadAll: function() {
|
|
var self = this;
|
|
resource.sync('readAll', function(err, builds) {
|
|
if (err) throw err;
|
|
self.builds = builds;
|
|
self.trigger(self.builds);
|
|
});
|
|
},
|
|
});
|
|
|
|
return Store;
|
|
});
|