mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 23:35:08 +00:00
39 lines
759 B
JavaScript
39 lines
759 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: [],
|
|
|
|
_onAction: function(build, action) {
|
|
var oldBuild = _(this.builds).findWhere({id: build.id});
|
|
if (oldBuild) {
|
|
_(oldBuild).extend(build);
|
|
} else {
|
|
this.builds.unshift(build);
|
|
}
|
|
|
|
this.trigger(this.builds);
|
|
},
|
|
|
|
init: function() {
|
|
resource.subscribe('create', 'update', this._onAction);
|
|
},
|
|
|
|
onReadAll: function() {
|
|
var self = this;
|
|
resource.sync('read', function(err, builds) {
|
|
self.builds = builds;
|
|
self.trigger(self.builds);
|
|
});
|
|
}
|
|
});
|
|
|
|
return Store;
|
|
});
|