mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 22:45:07 +00:00
41 lines
805 B
JavaScript
41 lines
805 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('read', function(err, builds) {
|
|
self.builds = builds;
|
|
self.trigger(self.builds);
|
|
});
|
|
}
|
|
});
|
|
|
|
return Store;
|
|
});
|