reactjs flux - How to dynamically select store -


i'm trying figure out best way dynamically select component , store based on data server receives. app based on these examples: https://github.com/yahoo/flux-examples/tree/master/fluxible-router little different:

  1. user goes mysite.com/that/and/that (the app can't know type of thing 'that/and/that' is, can't handled in routing).
  2. server request our cms. cms returns data, including type of data (section listing, article, company profile, etc.)
  3. here can dynamically select component (this in render method of parent component now):

    switch (this.props.documenttype) { // cms     case 'section':         handler = require('../section/section');         break;     case 'article':         handler = require('../article/article');         break;     default:         // nothing } 

all good. want put data in particular store. best way that? ideas seem little hacky me:

  1. in same switch statement, dynamically execute action send data appropriate store, 'article' component rely on 'article' store having data.

  2. send data component , let (for example) article component initialize article store data.

  3. actually put document type in url, e.g. mysite.com/article/this/and/that , handle neatly in routes. i'd rather not mess urls because couldn't work out elegant solution :)

thanks in advance ideas.

this unfortunate limitation of having react rendering synchronous on server: decisions components render happen late load data ahead of time. reason, have moved decision of component render outside of parent component, , instead make mapping static (via configuration) or separate method gets executed action. in way, action calls function or checks static map, figures out 1 used, , calls action fetch data. action can dispatch data , component used store. component gets child store , renders dynamically.

it's not ideal solution , violates flux principles, it's thing have found lets dynamically load components on server correctly.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -