Skip to content

Commit

Permalink
fix: separation of concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Jan 6, 2024
1 parent 6688102 commit 5054a6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/common/BatchedTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class BatchedTransport {
this._transport.addListener(BATCHED_TRANSPORT_CHANNEL, stack => {
stack.forEach(entry => {
const [channel, args] = entry;
const callbacks = this._listeners.get(channel);

callbacks.forEach(callback => {
callback(...args);
});
// server side the transport is the same EventEmitter instance
// for both state manager server and client, so channel might not exist
// one side or the other.
if (this._listeners.has(channel)) {
const callbacks = this._listeners.get(channel);
callbacks.forEach(callback => callback(...args));
};
});
});
}
Expand Down
8 changes: 2 additions & 6 deletions src/server/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class StateManager extends BaseStateManager {
this._observers = new Set();
this._hooksBySchemaName = new Map(); // protected

this.addClient(localClientId, this.client.transport);
this.addClient(localClientId, localTransport);
}

[kIsObservableState](state) {
Expand All @@ -345,11 +345,7 @@ class StateManager extends BaseStateManager {
* @private
*/
addClient(nodeId, transport) {
// server adds itself as client, and its transport is a raw EventEmitter
// so we don't want to proxy it twice with BatchedTransport.
if (nodeId !== SERVER_ID) {
transport = new BatchedTransport(transport);
}
transport = new BatchedTransport(transport);

const client = { id: nodeId, transport };
this._clientByNodeId.set(nodeId, client);
Expand Down

0 comments on commit 5054a6a

Please sign in to comment.