Reflux + Axios.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Reflux = require('reflux'); | |
var actions = require('./actions'); | |
module.exports = 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); | |
}, | |
}); |
Wow this helped, but please how do you use this inside the react component.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
God dammit, I got it now...
I have to trigger actions.load() to actually trigger the ajax call... I thought the first one was automatically triggered... my fault...
Thanks for the example :)