Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async requests with data from store #357

Open
deepsyx opened this issue Jun 21, 2015 · 0 comments
Open

Async requests with data from store #357

deepsyx opened this issue Jun 21, 2015 · 0 comments
Labels
Milestone

Comments

@deepsyx
Copy link

deepsyx commented Jun 21, 2015

I just started using refluxjs/react with webpack. I really liked the listenAndPromise async pattern, but I've encountered a problem. I got the following code:

Action:

var ResumeService = require('services/ResumeService');
var ResumeActions = Reflux.createActions({
    'save': {
        asyncResult: true
    }
});
ResumeActions.save.listenAndPromise(ResumeService.save);

ResumeService:

var http = require('utils/http');
var ENDPOINT = '/resumes/';
module.exports = {
    save: function() {
        return http.post(ENDPOINT + 'save', {
            resume: ??????????
        });
    },
}

And part of the store:

    var RendererActions = require('actions/RendererActions');
var ResumeStore = Reflux.createStore({
    listenables: [ResumeActions],
    resume: Immutable.fromJS(ResumeExample),  //nested object

    onSaveCompleted: function(id) {
        .....
    },

    onSaveFailed: function() {
        ....
    }
    ...
});

So when a user makes change, the resume variable in the store is updated. Now the user wants to save the changes and he hit a button which triggers Action.save(). Here comes my problem: How can I pass the resume variable from the store to the service file above?

The weird thing is that if I do var Store = require('stores/ResumeStore'); in the service file, it has the value object {}, this happens only if I include the store in the service, I think it has something to do with endless loop requiring or something like this. ( Store requires Action, Action requires Service, Service requires Store )

@LongLiveCHIEF LongLiveCHIEF added this to the 0.3.0 milestone Jul 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants