nci/app/stores/project.js
2015-12-12 15:44:41 +03:00

36 lines
698 B
JavaScript

'use strict';
var _ = require('underscore'),
Reflux = require('reflux'),
ProjectActions = require('../actions/project'),
resources = require('../resources'),
resource = resources.projects;
var Store = Reflux.createStore({
listenables: ProjectActions,
project: {},
getInitialState: function() {
return this.project;
},
onChange: function(data, action) {
this.trigger(data.project);
},
init: function() {
resource.subscribe('change', this.onChange);
},
onRead: function(params) {
var self = this;
resource.sync('read', params, function(err, project) {
if (err) throw err;
self.project = project;
self.trigger(self.project);
});
}
});
module.exports = Store;