These are chat archives for reflux/refluxjs

29th
Apr 2015
Xavier Carpentier
@xcarpentier
Apr 29 2015 14:17
Hi, is it possible to use Reflux into React Native project ? Someone already tested it, some resources on that ? Thx :smile:
:)
max-zelinski
@max-zelinski
Apr 29 2015 16:38
Hi, if I'm implementing ajax calls in actions themselfes (using action.listen(function() {})), how can I prevent multiple AJAX calls? For instance, I create LOAD action, and I want to load data only once, and I've a lot of react components, that calls LOAD in their componentWillMount function, what is the best way to prevent loading same data other and other again?
max-zelinski
@max-zelinski
Apr 29 2015 17:06
or I should put AJAX calls in store (using some kind of API facade) and forget about this problem?:)
Joel Hawksley
@joelhawksley
Apr 29 2015 17:14
@max-zelinski I have some sample code that might help you here. let me grab it
In our reflux app, we're moving towards having all API calls happen in the store
onSubmitReview: function() {
  $.ajax({
    type: "PUT",
    url: url
  }).done(function(res) {
    ContentActions.addToHistory(res.data);
  }).fail(function(xhr) {
    var res = xhr.responseJSON
    ContentActions.addToHistory(res.data);
  });
},
components should be bound to the store, but not have any knowledge of how the data is retrieved
max-zelinski
@max-zelinski
Apr 29 2015 17:19
yep, got it. but why you decided to go with ajax calls in the stores? why didn't you put this logic in actions?
Joel Hawksley
@joelhawksley
Apr 29 2015 17:20
in our case, because we needed access to the data from the store for the api call
so rather than referencing the store from the action, we put the api call in the store
max-zelinski
@max-zelinski
Apr 29 2015 17:21
makes sense, and in my case I dont want to have multiple calls for the same previously loaded data
Joel Hawksley
@joelhawksley
Apr 29 2015 17:22
exactly
sorry, that sample code is less than helpful since I omitted the portion that depended on data from the store...
submitReview: function() {
  $.ajax({
    type: "PUT",
    url: Routes.XXX_path(this.data)
  }).done(function(res) {
    ContentReviewerActions.addToHistory(res.data);
  }).fail(function(xhr) {
    var res = xhr.responseJSON
    ContentReviewerActions.addToHistory(res.data);
  });
},
so you can see how that would be non-trivial to implement in an action