javascript - Where to set cookie in Isomorphic Redux Application? -


i have 3 general questions redux , isomorphic application:

  • what best way share 'runtime' data between client , server? instance, when user logged in distant api, store session object in cookies. in way, next time client requests front-end, front-end server can read cookies , initialize redux store it's previous session. downside of client has validate/invalidate session on boot (eg in componentdidmount of root component). should request session server side rather read cookies?
  • where should execute operation of cookie storing, in action creators or in reducers? should store cookie in reducer handle user session?
  • where should execute operation of redirect user (via react-router)? mean when user logged in, should dispatch redirect action (from loginactioncreator once login promise resolved?, somewhere else? )

thanks in advance.

i managed neat app structure. here's found each questions:

  • i share between client , front-end server api server token via cookies. each time client request site. front-end server calls api server validate session. if these servers on same network it's fast (< 5ms). prefetch useful data client on server before initial render. manage application loaded , ready (javascript loaded) in client in 600ms. pretty decent.

  • the action of storing cookie in actions creators. ethan clark said, must keep reducers pure. it's more easier test.

  • i still dispatch redirect in signin creator once user authenticated. guess it's easier test dispatch action after promise resolution in component or elsewhere.

in fact, keeping in mind allows have app easy test (expect actions creator must have ton of spies).

hope someone.

thanks participating.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -