nci/static/js/app/stores/project.js

33 lines
637 B
JavaScript
Raw Normal View History

2015-05-03 23:04:51 +00:00
'use strict';
define([
2015-07-09 20:12:24 +00:00
'underscore',
2015-05-03 23:04:51 +00:00
'reflux', 'app/actions/project', 'app/resources'
2015-07-09 20:12:24 +00:00
], function(_, Reflux, ProjectActions, resources) {
2015-05-07 20:53:46 +00:00
var resource = resources.projects;
2015-05-03 23:04:51 +00:00
var Store = Reflux.createStore({
2015-05-07 20:53:46 +00:00
listenables: ProjectActions,
2015-07-09 20:12:24 +00:00
project: null,
onChange: function(data, action) {
this.trigger(data.project);
2015-05-03 23:04:51 +00:00
},
2015-07-09 20:12:24 +00:00
init: function() {
resource.subscribe('change', this.onChange);
},
onRead: function(params) {
2015-05-04 20:50:02 +00:00
var self = this;
2015-07-09 20:12:24 +00:00
resource.sync('read', params, function(err, project) {
2015-05-15 05:43:57 +00:00
if (err) throw err;
2015-07-09 20:12:24 +00:00
self.project = project;
self.trigger(self.project);
2015-05-03 23:04:51 +00:00
});
}
});
return Store;
});