javascript - Where should store refetch action be made in Flux app after authentication? -
suppose have messages
, loginform
components, messagestore
, userstore
(for keeping logged-in user info).
anonymous users can view messages, favoriting , other properties available authenticated.
loginform
modal , when user logged-in need reload data api messagestore
messages objects containing user's specific properties.
- i can digest
login_success
inmessagestore
(or each interested store) , fire refetch action inside store. - i can fire refetch action controller-view after
userstore
changes. in case need know stores should refetch after user logged-in.
what right way doing logic in flux application?
in app made uses login page , fetches user-specific events api, structure used:
loginpage (on submit) -> webapiutils.login(email, password) webapiutils.login contacts api, upon response -> actions.receivelogin(response)
receivelogin calls dispatcher actiontype of login response
my sessionstore listens dispatch, , in switch statement case of login response sets user info in store sessionstorage. calls webapiutils.getevents()
webapiutils.getevents() requests user's events api, upon receipt dispatches receiveevents action, main store listens , updates events in store accordingly.
my components listen changes in main store, , when events updated after getevents(), triggers re-render.
you can find code here: https://github.com/hilary-l/react-cal-with-api
Comments
Post a Comment