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:
- user goes mysite.com/that/and/that (the app can't know type of thing 'that/and/that' is, can't handled in routing).
- server request our cms. cms returns data, including type of data (section listing, article, company profile, etc.)
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:
in same switch statement, dynamically execute action send data appropriate store, 'article' component rely on 'article' store having data.
send data component , let (for example) article component initialize article store data.
- 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
Post a Comment