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

Commit

Permalink
Merge pull request #257 from kassens/update-store
Browse files Browse the repository at this point in the history
[relay] update RelayStore tab when the changes happen
  • Loading branch information
kassens committed Oct 9, 2015
2 parents 26e2549 + cad1165 commit e8b760d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion plugins/Relay/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
import type Bridge from '../../agent/Bridge';
import type Agent from '../../agent/Agent';

function decorate(obj, attr, fn) {
var old = obj[attr];
obj[attr] = function() {
var res = old.apply(this, arguments);
fn.apply(this, arguments);
return res;
};
return () => {
obj[attr] = old;
};
}

module.exports = (bridge: Bridge, agent: Agent, hook: Object) => {
var shouldEnable = !!(
hook._relayInternals &&
Expand All @@ -28,7 +40,17 @@ module.exports = (bridge: Bridge, agent: Agent, hook: Object) => {
setRequestListener,
} = hook._relayInternals;

bridge.send('relay:store', {id: 'relay:store', nodes: DefaultStoreData.getNodeData()});
function sendStoreData() {
bridge.send('relay:store', {
id: 'relay:store',
nodes: DefaultStoreData.getNodeData(),
});
}

sendStoreData();
decorate(DefaultStoreData, 'handleUpdatePayload', sendStoreData);
decorate(DefaultStoreData, 'handleQueryPayload', sendStoreData);

var removeListener = setRequestListener((event, data) => {
bridge.send(event, data);
});
Expand Down

0 comments on commit e8b760d

Please sign in to comment.