The desktop plugin communicates with the React Native application through an RPC communication established by WebSockets. The plugin uses the Client Plugin API defined by Flipper. The architecture of using Flipper with React Native is further documented under Architecture in the Flipper Docs.
A typical round-trip consists of the plugin making a request to the app by calling client.send('eventName')
, thus emitting an event from the desktop the app. The event is received by the app by connection.receive('eventName', () => {})
, where the callback usually calls a function on the Realm (using the RealmJS SDK) and sends back the result using responder.success({result})
or connection.send({result})
. The roundtrip can be visualized:
The plugin and app listens for events emitted bi-directionally, to faciliate data sharing over the wire. Specifically, the Realm Flipper Plugin communicates with the React Native application through the following methods:
The app listens for the following events:
Gets the user-specified realms and sends them to the plugin.
Gets the schemas for a given realm and sends them to the plugin.
Takes a query request object, and sends back 50 amount of objects.
Adds a user-specified object to the Realm database.
Modifies an object in the Realm database.
Removed an object in the Realm database.
The plugin listens for the following events:
When an object is added to the Realm, an event is sent to the desktop plugin, allowing it to update the view.
When an object is deleted from the Realm, an event is sent to the desktop plugin, allowing it to update the view.
When an object is edited from the Realm, an event is sent to the desktop plugin, allowing it to update the view.
The plugin uses Realm Collection listeners to keep an updated view on the desktop plugin, as a key feature of Realm Databases is Live Objects. The event listeners liveObjectDeleted
and liveObjectEdited
, send an index in the database to delete or edit. Consequently, it's crucial that the listener constantly reflects what the user is currently viewing. For this purpose, the app implements two events, getCurrentQuery
and receivedCurrentQuery
who work together to keep the application updated on what the desktop plugin views, indenpendently of what is happening on the React Native app. This means that the user can (hot) reload the React Native app without the Realm Collection listeners becoming stale in regards to what the desktop plugin is showing. A typical roundtrip consists of:
- The React Native app
connection.send('getCurrentQuery')
s to the plugin. - The desktop plugin listens for
'getCurrentQuery'
, andclient.send('receivedCurrentQuery')
s back the current query state, consisting of the current schema, realm, sortingColumn and sortingDirection. - The app listens for
'receivedCurrentQuery'
and attaches a new listener according to the received information.
The desktop plugin listens for getCurrentQuery
as to send back the current query state to the app.
The app listens for receivedCurrentQuery
as to attach an updated Realm collection listener.
A QueryObject
consists of the neccessary arguments for querying:
type QueryObject = {
schema: string;
realm: string;
cursor: number | null;
sortingColumn: string;
sortingDirection: 'ascend' | 'descend';
query: string;
}
A RealmObject is an object in a realm:
type RealmObject = Record<string, unknown>;
These functions define the communication between the plugin and the API, and are necessary for supporting the required functionality.