nci/static/js/app/stores/terminal.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-05-07 21:55:40 +00:00
'use strict';
define([
'underscore',
'reflux', 'app/actions/build', 'app/connect'
], function(_, Reflux, BuildActions, connect) {
var Store = Reflux.createStore({
listenables: BuildActions,
init: function() {
2015-06-14 21:10:42 +00:00
// the only purpose of this hash to reconnect all the time
// except first, see notes at using
this.connectedResourcesHash = {};
2015-05-07 21:55:40 +00:00
},
2015-05-14 20:37:44 +00:00
onReadTerminalOutput: function(build) {
var self = this,
output = '',
resourceName = 'build' + build.id;
2015-05-07 21:55:40 +00:00
var connectToBuildDataResource = function() {
2015-06-14 21:10:42 +00:00
// reconnect for get data below (at subscribe), coz
// data emitted only once during connect
if (self.connectedResourcesHash[resourceName]) {
connect.resource(resourceName).reconnect();
} else {
self.connectedResourcesHash[resourceName] = 1;
}
connect.resource(resourceName).subscribe('data', function(data) {
output += data;
self.trigger({
buildId: build.id,
name: 'Console for build #' + build.id,
data: output
});
2015-05-07 21:55:40 +00:00
});
};
// create data resource for completed build
2015-05-21 19:04:38 +00:00
if (build.completed) {
connect.resource('projects')
.sync('createBuildDataResource', function(err) {
if (err) throw err;
connectToBuildDataResource();
});
} else {
connectToBuildDataResource();
}
2015-05-07 21:55:40 +00:00
}
});
return Store;
});