Skip to content

Commit 5d58153

Browse files
authored
Merge pull request #13 from kolohelios/dev
pre-alpha: Start wiring up Flipper client and send Recoil atom state data
2 parents 3594aa4 + d2111b8 commit 5d58153

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
import { useEffect } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { useRecoilSnapshot } from 'recoil';
3-
import { addPlugin } from 'react-native-flipper';
3+
import { addPlugin, Flipper } from 'react-native-flipper';
4+
5+
const API_VERSION = 0;
46

57
export const RecoilFlipperClient = () => {
68
const snapshot = useRecoilSnapshot();
9+
const [connectionReference, setConnectionReference] =
10+
useState<Flipper.FlipperConnection | null>(null);
711

812
useEffect(() => {
913
addPlugin({
1014
getId() {
1115
return 'recoil-state';
1216
},
1317
onConnect(connection) {
14-
console.log({ connection });
15-
// Incoming data from desktop client
16-
connection.receive('getData', (data, responder) => {
17-
console.log('Incoming data', data);
18-
// Respond with some data
19-
responder.success({
20-
ack: true,
21-
});
22-
});
23-
// Outgoing data to be sent to the desktop client
24-
connection.send('newRow', { message: 'Hello' });
18+
console.debug('Flipper: connected');
19+
setConnectionReference(connection);
20+
21+
connection.send('apiVersion', API_VERSION);
2522
},
2623
onDisconnect() {
27-
console.log('disconnected');
24+
console.debug('Flipper: disconnected');
2825
},
2926
runInBackground() {
3027
return false;
@@ -33,10 +30,15 @@ export const RecoilFlipperClient = () => {
3330
}, []);
3431

3532
useEffect(() => {
36-
console.debug('The following atoms were modified:');
3733
for (const node of snapshot.getNodes_UNSTABLE({ isModified: true })) {
38-
console.debug(node.key, snapshot.getLoadable(node));
34+
// TODO: review typing for Flipper.FlipperConnection because it does have a connected property
35+
(connectionReference as any)?.connected &&
36+
connectionReference?.send('newRow', {
37+
key: node.key,
38+
payload: snapshot.getLoadable(node),
39+
});
3940
}
41+
// eslint-disable-next-line react-hooks/exhaustive-deps
4042
}, [snapshot]);
4143

4244
// Return null because we don't want to render any UI; this is a state-listening component only

0 commit comments

Comments
 (0)