-
Notifications
You must be signed in to change notification settings - Fork 37
Architecture
Vojta Smrcek edited this page Sep 7, 2018
·
3 revisions
General diagram of the FluxC architecture:
In the new architecture we're using Kotlin and coroutines instead of Dispatcher. New calls are now synchronous and defined as suspend. The dispatcher still exists and is used for backward compatibility. It is an event bus that should be used to broadcast events.
Notes:
- WP REST API client is not implemented yet (we have a proof of concept and discovery utils).
- Memory storage is optional, it makes sense to have some data in memory so we don't have to hit the DB everytime we call a Store's getter. The Account Store is currently the only Store using data stored in memory.
The calls to FluxC are now synchronous with the Store being the orchestrator of the flow:
- App sends synchronous requests to the Store suspended function with an Action as a parameter.
- Store sends request to the RestClient which synchronously waits for the Response from the API
- RestClient returns the Fetched Payload object back to the Store
- Store can send the object to the SqlUtils class to store it in DB
- Store returns the OnChanged event back to the app.
- App loads data via previously existing getters
Example:
- App asks FluxC to
FETCH_ACTIVITY_LOG
for site X by callingActivityLogStore::fetchActivities
method and suspends the current coroutine. -
ActivityLogStore
calls theActivityLogRestClient::fetchActivity
and awaits result. -
ActivityLogRestClient
callsWPComGsonRequestBuilder::syncGetRequest
and awaits result. -
WPComGsonRequestBuilder
builds a get request, adds it to the request queue and transforms callback to a synchronous call usingsuspendCoroutine
. -
ActivityLogRestClient
receives aResponse
, transforms it into aFetchedActivityLogPayload
and returns it to theActivityLogStore
-
ActivityLogStore
receives the payload and stores it into DB usingActivityLogSqlUtils
-
ActivityLogStore
returnsOnActivityLogFetched
object containing the change information back to the app. - App loads Activity log using
ActivityLogStore::getActivityLogForSite