fix #1382 - React Native - Hermes Engine doesn't handle for await very well

This commit is contained in:
Ovidiu Cristescu 2023-07-03 05:03:25 +03:00
parent 5f104534b2
commit 6a4e1d3f00
2 changed files with 33 additions and 7 deletions

View File

@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { instrument, Options } from '@redux-devtools/instrument'; import { instrument, Options } from '@redux-devtools/instrument';
import { Action, Reducer, StoreEnhancerStoreCreator } from 'redux'; import { Action, Reducer, StoreEnhancerStoreCreator } from 'redux';

View File

@ -11,11 +11,14 @@ import {
StoreEnhancer, StoreEnhancer,
StoreEnhancerStoreCreator, StoreEnhancerStoreCreator,
} from 'redux'; } from 'redux';
import { import {
EnhancedStore, EnhancedStore,
LiftedAction, LiftedAction,
LiftedState, LiftedState,
PerformAction, PerformAction,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
} from '@redux-devtools/instrument'; } from '@redux-devtools/instrument';
import { import {
ActionCreatorObject, ActionCreatorObject,
@ -29,6 +32,8 @@ import {
filterState, filterState,
LocalFilter, LocalFilter,
State, State,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
} from '@redux-devtools/utils'; } from '@redux-devtools/utils';
function async(fn: () => unknown) { function async(fn: () => unknown) {
@ -400,7 +405,16 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
)) as string; )) as string;
this.channel = channelName; this.channel = channelName;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion // 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>); this.handleMessages(data as Message<S, A>);
} }
} catch (error) { } catch (error) {
@ -433,8 +447,11 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
void (async () => { void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('error')) { const consumer = this.socket!.listener('error').createConsumer();
// 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-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 // eslint-disable-next-line no-prototype-builtins,@typescript-eslint/no-unsafe-argument
this.errorCounts[data.error.name] = this.errorCounts.hasOwnProperty( this.errorCounts[data.error.name] = this.errorCounts.hasOwnProperty(
data.error.name data.error.name
@ -459,15 +476,22 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
void (async () => { void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion // 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'); 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.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
this.login(); this.login();
} }
})(); })();
void (async () => { void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const consumer = this.socket!.listener('disconnect').createConsumer();
for await (const data of this.socket!.listener('disconnect')) { // eslint-disable-next-line no-constant-condition
while (true) {
const {done} = await consumer.next();
if (done) break;
this.stop(true); this.stop(true);
} }
})(); })();
@ -566,7 +590,7 @@ class DevToolsEnhancer<S, A extends Action<unknown>> {
shouldHotReload: options.shouldHotReload, shouldHotReload: options.shouldHotReload,
shouldRecordChanges: options.shouldRecordChanges, shouldRecordChanges: options.shouldRecordChanges,
shouldStartLocked: options.shouldStartLocked, shouldStartLocked: options.shouldStartLocked,
pauseActionType: options.pauseActionType || '@@PAUSED', pauseActionType: options.pauseActionType || '@@Paused',
})(reducer, initialState); })(reducer, initialState);
if (realtime) this.start(); if (realtime) this.start();