Reflux.createStore({ listenables: [Actions], getImage: function(id) { Api.get('gallery/' + id + '/comments') .then(function(json) { this.comment = json.data; this.triggerChange(); }.bind(this)); }, triggerChange: function() { this.trigger('change', this.comment); } })
Reflux.createStore({ listenables: SelectorActions, onSelect: function(chartId) { this.trigger(chartId); } })
Reflux.createStore({ listenables: BuildActions, build: null, onChange: function(data) { if (this.build && (data.buildId === this.build.id)) { _(this.build).extend(data.changes); this.trigger(this.build); } }, init: function() { resource.subscribe('change', this.onChange); }, onRead: function(id) { var self = this; resource.sync('read', {id: id}, function(err, build) { if (err) throw err; self.build = build; self.trigger(self.build); }); } })
Reflux.createStore({ init() { this.listenTo(Actions.addItem,this.onItemAdded); this.listenTo(Actions.checkItem,this.onItemChecked); this.listenTo(Actions.removeItem,this.onItemRemoved); this.listenTo(Actions.getData,this.onDataRequested); }, onItemAdded( item ) { request.post('/api/add').send(item).end(); this.trigger(); }, onItemChecked( index ) { request.patch(`/api/check/${index}`).end(); this.trigger(); }, onItemRemoved( index ) { request.del(`/api/remove/${index}`).end(); this.trigger(); }, onDataRequested( ) { request.get('/api/list').end(response => Actions.receiveData(response.body.data)); } })
Reflux.createStore({ listenables: ProjectActions, onRun: function(projectName, buildParams) { resource.sync('run', { projectName: projectName, buildParams: buildParams }, function(err) { if (err) throw err; }); }, onReadAll: function(params) { var self = this; resource.sync('readAll', params, function(err, projects) { if (err) throw err; self.trigger(projects); }); } })
Reflux.createStore({ listenables: ProjectActions, project: {}, getInitialState: function() { return this.project; }, onChange: function(data) { 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); }); } })
Reflux.createStore({ listenables: [Actions], onSetUrl: function(url){ this.url = url }, onSetOptions: function(options){ this.options = options }, onLoadOptions: function(options) { this.options = options request({url: this.url},function(error, response, body) { if(error || !body){ return console.error('Failed to load') } body = JSON.parse(body) this.options = body this.trigger(body) }.bind(this)) }, onAddOption: function(option, callback){ request({url: this.url, method: 'POST', json: {name: option}}, function(error, response, body) { if(error || !body){ return console.error('Failed to save') } this.options.unshift(body) callback(body) this.trigger(this.options) }.bind(this)) } })
Reflux.createStore({ listenables: ChartActions, mixins: [MapStoreMixin], // return cached data or populate from server onLoad: function(id) { var chartData = this.get(id); if (chartData) { this.trigger(chartData); } else { this._populateData(id); } }, // transform data returned from the server and cache _populateData: function(id) { var that = this; ChartService.get(id) .then(function(res) { console.log('Received data for: ' + id); this.set(id, res.body); }.bind(this)) .catch(function(error) { console.log(error); }); } })
Reflux.createStore({ listenables: [Actions], getImages: function(topicId) { return Api.get('topics/' + topicId) .then(function(json){ this.images = _.reject(json.data, function(image) { return image.is_album }); this.triggerChange(); }.bind(this)); }, triggerChange: function() { this.trigger('change', this.images); } })
Reflux.createStore({ listenables: BuildLogActions, data: { lines: [], total: 0 }, getInitialState: function() { return this.data; }, onGetTail: function(params) { var self = this; resource.sync('getBuildLogTail', params, function(err, data) { if (err) throw err; self.data = data; self.trigger(self.data); }); }, onGetLines: function(params) { var self = this; resource.sync('getBuildLogLines', params, function(err, data) { if (err) throw err; self.data.lines = data.lines; self.trigger(self.data); }); } })
Reflux.createStore({ // We listen to all actions // Our Actions listenables: Actions, getInitialState: function() { return {tasks: tasks} }, onAddTask: function(value){ // Add one task to the beginning of an array tasks.unshift({value: value, done: false}); // Pass the data on to listeners this.trigger(tasks); }, onCheckTask: function(id){ // Invert value tasks[id].done = !tasks[id].done; // Pass the data on to listeners this.trigger(tasks); }, onRemoveTask: function(i){ // Remove task tasks.splice(i, 1); // Pass the data on to listeners this.trigger(tasks); } })
Reflux.createStore({ listenables: [Actions], getTopics: function() { return Api.get('topics/defaults') .then(function(json){ this.topics = json.data; this.triggerChange(); }.bind(this)); }, triggerChange: function() { this.trigger('change', this.topics); } })
Reflux.createStore({ listenables: ChartActions, // propagate new maximum range value onSetRange: function(range) { this.trigger(range); } })
Reflux.createStore({ listenables: [ Actions ], getTopics: function() { Api.get('topics/defaults') .then(function(json) { this.topics = json.data; this.triggerChange(); }.bind(this)); }, triggerChange: function() { this.trigger('change', this.topics); } })