GithubHelp home page GithubHelp logo

Comments (2)

gaearon avatar gaearon commented on July 28, 2024

Mostly it would follow the same flow:

  1. In component: StuffActionCreators.post(something)
  2. In action creator: StuffAPI.post(something)
  3. In stuff API: ajax('POST', '/stuff/post', something, StuffServerActionCreators.handlePost)
  4. In server action creator:
  handlePostStuff(err, response) {
    AppDispatcher.handleServerAction({
      type: err ? ActionTypes.POST_STUFF_ERROR : ActionTypes.POST_STUFF_SUCCESS,
      response: response,
      stuffId: err ? null : response.result
    });

    if (err) {
      console.error(err);
      // You might want to show error
      AlertActionCreators.showAlert(err.status ? AlertTypes.SERVER_ERROR : AlertTypes.CONNECTION_ERROR);
    } else {
      router.replaceWith('stuff', {
        stuffId: response.result
      });
    }
  }

Note that I'm assuming you're using Normalizr to flatten API responses, and thus POST /stuff is normalized into something like:

{
  result: 10, // stuff id
  entities: {
    stuffs: {
      10: {
        someStuffField: 'lala',
        otherStuffField: 42
      }
    }
    // if Stuff has any related nested entities, they will go here too
  }
}

This gives StuffStore the opportunity to consume posted stuff when POST_STUFF_SUCCESS is dispatched, similar to how content stores consume entities in this example.

Finallly, replaceWith (or transitionTo) is called on router instance. See flux howto in react-router.

from flux-react-router-example.

neverov avatar neverov commented on July 28, 2024

Awesome!

Thanks a lot, that worked great!

from flux-react-router-example.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.