Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1382 - React Native - Hermes Engine isn't supporting for await yet #1430

Closed
wants to merge 7 commits into from
2 changes: 2 additions & 0 deletions packages/redux-devtools-remote/src/configureStore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { instrument, Options } from '@redux-devtools/instrument';
import { Action, Reducer, StoreEnhancerStoreCreator } from 'redux';

Expand Down
41 changes: 34 additions & 7 deletions packages/redux-devtools-remote/src/devTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import {
StoreEnhancer,
StoreEnhancerStoreCreator,
} from 'redux';

import {
EnhancedStore,
LiftedAction,
LiftedState,
PerformAction,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
} from '@redux-devtools/instrument';
import {
ActionCreatorObject,
Expand All @@ -29,6 +32,8 @@ import {
filterState,
LocalFilter,
State,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
} from '@redux-devtools/utils';

function async(fn: () => unknown) {
Expand Down Expand Up @@ -271,6 +276,7 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
!this.actionSanitizer
? action
: this.actionSanitizer(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
(action as PerformAction<A>).action,
nextActionId! - 1,
),
Expand Down Expand Up @@ -400,7 +406,16 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
)) as string;
this.channel = channelName;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.subscribe(channelName)) {
// for await (const data of this.socket!.subscribe(channelName)) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const consumer = this.socket!.listener(channelName).createConsumer();
// eslint-disable-next-line no-constant-condition
while (true) {
const { value: data, done } = await consumer.next();
if (done) break;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.handleMessages(data as Message<S, A>);
}
} catch (error) {
Expand Down Expand Up @@ -433,8 +448,11 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {

void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('error')) {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
const consumer = this.socket!.listener('error').createConsumer();
// eslint-disable-next-line no-constant-condition
while (true) {
const { value: data, done } = await consumer.next();
if (done) break; // if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins,@typescript-eslint/no-unsafe-argument
this.errorCounts[data.error.name] = this.errorCounts.hasOwnProperty(
data.error.name,
Expand All @@ -459,15 +477,22 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {

void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('connect')) {
const consumer = this.socket!.listener('connect').createConsumer();
// eslint-disable-next-line no-constant-condition
while (true) {
const { done } = await consumer.next();
if (done) break;
console.log('connected to remotedev-server');
this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
this.login();
}
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('disconnect')) {
const consumer = this.socket!.listener('disconnect').createConsumer();
// eslint-disable-next-line no-constant-condition
while (true) {
const { done } = await consumer.next();
if (done) break;
this.stop(true);
}
})();
Expand Down Expand Up @@ -525,6 +550,7 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
const nextActionId = liftedState.nextActionId;
const liftedAction = liftedState.actionsById[nextActionId - 1];
if (isFiltered(liftedAction.action, this.filters)) return;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.relay('ACTION', state, liftedAction, nextActionId);
if (!this.isExcess && maxAge)
this.isExcess = liftedState.stagedActionIds.length >= maxAge;
Expand Down Expand Up @@ -566,13 +592,14 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
shouldHotReload: options.shouldHotReload,
shouldRecordChanges: options.shouldRecordChanges,
shouldStartLocked: options.shouldStartLocked,
pauseActionType: options.pauseActionType || '@@PAUSED',
pauseActionType: options.pauseActionType || '@@Paused',
})(reducer, initialState);

if (realtime) this.start();
this.store.subscribe(() => {
if (this.isMonitored)
this.handleChange(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.store.getState(),
this.getLiftedStateRaw(),
maxAge,
Expand Down