Skip to content

Instantly share code, notes, and snippets.

@bebraw
Last active October 28, 2015 10:23
Show Gist options
  • Save bebraw/2060641a7fae7264af2c to your computer and use it in GitHub Desktop.
Save bebraw/2060641a7fae7264af2c to your computer and use it in GitHub Desktop.

Revisions

  1. bebraw revised this gist Mar 30, 2015. 1 changed file with 15 additions and 16 deletions.
    31 changes: 15 additions & 16 deletions store.js
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,23 @@
    'use strict';
    var Reflux = require('reflux');
    var actions = require('./actions');


    module.exports = function(actions) {
    return Reflux.createStore({
    init: function() {
    this.data = [];
    module.exports = Reflux.createStore({
    init: function() {
    this.data = [];

    this.listenTo(actions.load.completed, this.loadCompleted);
    this.listenTo(actions.load.failed, this.loadFailed);
    },
    this.listenTo(actions.load.completed, this.loadCompleted);
    this.listenTo(actions.load.failed, this.loadFailed);
    },

    loadCompleted: function(data) {
    this.data = data;
    loadCompleted: function(data) {
    this.data = data;

    this.trigger(data);
    },
    this.trigger(data);
    },

    loadFailed: function(err) {
    console.error(err);
    },
    });
    };
    loadFailed: function(err) {
    console.error(err);
    },
    });
  2. bebraw created this gist Mar 30, 2015.
    20 changes: 20 additions & 0 deletions actions.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    'use strict';
    var Reflux = require('reflux');
    var axios = require('axios');


    var Actions = Reflux.createActions({
    load: {
    children: ['completed', 'failed']
    }
    });

    Actions.load.listen(function() {
    var that = this;

    axios.get('/whatever').then(function(res) {
    that.completed(res.data);
    }).catch(this.failed);
    });

    module.exports = Actions;
    24 changes: 24 additions & 0 deletions store.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    'use strict';
    var Reflux = require('reflux');


    module.exports = function(actions) {
    return Reflux.createStore({
    init: function() {
    this.data = [];

    this.listenTo(actions.load.completed, this.loadCompleted);
    this.listenTo(actions.load.failed, this.loadFailed);
    },

    loadCompleted: function(data) {
    this.data = data;

    this.trigger(data);
    },

    loadFailed: function(err) {
    console.error(err);
    },
    });
    };