Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit cad1165

Browse files
committed
[relay] update RelayStore tab when the changes happen
Previously, we were only showing the state of when the devtools were opened. Now it updates when changes happen. We could probably improve the transport of the data by sending a delta over the bridge, but that can be further optimization.
1 parent 26e2549 commit cad1165

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

plugins/Relay/backend.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
import type Bridge from '../../agent/Bridge';
1414
import type Agent from '../../agent/Agent';
1515

16+
function decorate(obj, attr, fn) {
17+
var old = obj[attr];
18+
obj[attr] = function() {
19+
var res = old.apply(this, arguments);
20+
fn.apply(this, arguments);
21+
return res;
22+
};
23+
return () => {
24+
obj[attr] = old;
25+
};
26+
}
27+
1628
module.exports = (bridge: Bridge, agent: Agent, hook: Object) => {
1729
var shouldEnable = !!(
1830
hook._relayInternals &&
@@ -28,7 +40,17 @@ module.exports = (bridge: Bridge, agent: Agent, hook: Object) => {
2840
setRequestListener,
2941
} = hook._relayInternals;
3042

31-
bridge.send('relay:store', {id: 'relay:store', nodes: DefaultStoreData.getNodeData()});
43+
function sendStoreData() {
44+
bridge.send('relay:store', {
45+
id: 'relay:store',
46+
nodes: DefaultStoreData.getNodeData(),
47+
});
48+
}
49+
50+
sendStoreData();
51+
decorate(DefaultStoreData, 'handleUpdatePayload', sendStoreData);
52+
decorate(DefaultStoreData, 'handleQueryPayload', sendStoreData);
53+
3254
var removeListener = setRequestListener((event, data) => {
3355
bridge.send(event, data);
3456
});

0 commit comments

Comments
 (0)