Update existing subscriptions to use sideEffect
Summary: See previous two diffs, this applies the abstraction to our code base Reviewed By: passy Differential Revision: D20679687 fbshipit-source-id: 05e340dca3f832971783a844a78d1ffd553ff9d2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7a40d3f0a3
commit
8fa4b5ccb2
@@ -26,6 +26,7 @@ import invariant from 'invariant';
|
||||
import {flipperRecorderAddEvent} from './utils/pluginStateRecorder';
|
||||
import {getPluginKey} from './utils/pluginUtils';
|
||||
import {processMessageLater} from './utils/messageQueue';
|
||||
import {sideEffect} from './utils/sideEffect';
|
||||
|
||||
type Plugins = Array<string>;
|
||||
|
||||
@@ -207,21 +208,25 @@ export default class Client extends EventEmitter {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
}, 5000);
|
||||
unsubscribe = this.store.subscribe(() => {
|
||||
const newDeviceList = this.store.getState().connections.devices;
|
||||
if (newDeviceList === this.lastSeenDeviceList) {
|
||||
return;
|
||||
}
|
||||
this.lastSeenDeviceList = this.store.getState().connections.devices;
|
||||
const matchingDevice = newDeviceList.find(
|
||||
(device) => device.serial === this.query.device_id,
|
||||
);
|
||||
if (matchingDevice) {
|
||||
clearTimeout(timeout);
|
||||
resolve(matchingDevice);
|
||||
unsubscribe();
|
||||
}
|
||||
});
|
||||
unsubscribe = sideEffect(
|
||||
this.store,
|
||||
{name: 'waitForDevice', throttleMs: 100},
|
||||
(state) => state.connections.devices,
|
||||
(newDeviceList) => {
|
||||
if (newDeviceList === this.lastSeenDeviceList) {
|
||||
return;
|
||||
}
|
||||
this.lastSeenDeviceList = newDeviceList;
|
||||
const matchingDevice = newDeviceList.find(
|
||||
(device) => device.serial === this.query.device_id,
|
||||
);
|
||||
if (matchingDevice) {
|
||||
clearTimeout(timeout);
|
||||
resolve(matchingDevice);
|
||||
unsubscribe();
|
||||
}
|
||||
},
|
||||
);
|
||||
}),
|
||||
'client-setMatchingDevice',
|
||||
).then((device) => {
|
||||
|
||||
Reference in New Issue
Block a user