fix(app): remove remotedev option (#845)

This commit is contained in:
Nathan Bierema 2021-09-06 18:29:41 +00:00 committed by GitHub
parent d1462690ba
commit 5f1b7e9de5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 44 deletions

View File

@ -66,16 +66,13 @@ export default function configureStore(
); );
} }
const store = createStore(persistedReducer, enhancer); const store = createStore(persistedReducer, enhancer);
const persistor = persistStore(store); const persistor = persistStore(store, null, () => {
if (store.getState().connection.type !== 'disabled') {
if (
store.getState().connection.options.hostname &&
store.getState().connection.options.port
) {
store.dispatch({ store.dispatch({
type: CONNECT_REQUEST, type: CONNECT_REQUEST,
}); });
} }
});
return { store, persistor }; return { store, persistor };
} }

View File

@ -332,7 +332,7 @@ export function toggleDispatcher(): ToggleDispatcherAction {
return { type: TOGGLE_DISPATCHER }; return { type: TOGGLE_DISPATCHER };
} }
export type ConnectionType = 'disabled' | 'remotedev' | 'custom'; export type ConnectionType = 'disabled' | 'custom';
export interface ConnectionOptions { export interface ConnectionOptions {
readonly type: ConnectionType; readonly type: ConnectionType;
readonly hostname: string; readonly hostname: string;

View File

@ -2,7 +2,6 @@ import React, { Component } from 'react';
import { connect, ResolveThunks } from 'react-redux'; import { connect, ResolveThunks } from 'react-redux';
import { Container, Form } from 'devui'; import { Container, Form } from 'devui';
import { import {
JSONSchema7,
JSONSchema7Definition, JSONSchema7Definition,
JSONSchema7Type, JSONSchema7Type,
JSONSchema7TypeName, JSONSchema7TypeName,
@ -33,12 +32,8 @@ const defaultSchema: Schema = {
type: { type: {
title: 'Connection settings (for getting reports and remote debugging)', title: 'Connection settings (for getting reports and remote debugging)',
type: 'string', type: 'string',
enum: ['disabled', 'remotedev', 'custom'], enum: ['disabled', 'custom'],
enumNames: [ enumNames: ['no remote connection', 'use local (custom) server'],
'no remote connection',
'connect via remotedev.io',
'use local (custom) server',
],
}, },
hostname: { hostname: {
type: 'string', type: 'string',

View File

@ -1,12 +0,0 @@
const socketOptions = {
hostname: 'remotedev.io',
port: 443,
protocol: 'https',
autoReconnect: true,
secure: true,
autoReconnectOptions: {
randomness: 30000,
},
};
export default socketOptions;

View File

@ -14,13 +14,18 @@ class Root extends Component {
persistor?: Persistor; persistor?: Persistor;
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
const { store, persistor } = configureStore(); const { store, persistor } = configureStore(
this.store = store; (store: Store<StoreState, StoreAction>) => {
this.persistor = persistor; if (store.getState().connection.type !== 'disabled') {
store.dispatch({ store.dispatch({
type: CONNECT_REQUEST, type: CONNECT_REQUEST,
}); });
} }
}
);
this.store = store;
this.persistor = persistor;
}
render() { render() {
if (!this.store) return null; if (!this.store) return null;

View File

@ -1,7 +1,6 @@
import socketCluster, { SCClientSocket } from 'socketcluster-client'; import socketCluster, { SCClientSocket } from 'socketcluster-client';
import { stringify } from 'jsan'; import { stringify } from 'jsan';
import { Dispatch, MiddlewareAPI } from 'redux'; import { Dispatch, MiddlewareAPI } from 'redux';
import socketOptions from '../constants/socketOptions';
import * as actions from '../constants/socketActionTypes'; import * as actions from '../constants/socketActionTypes';
import { getActiveInstance } from '../reducers/instances'; import { getActiveInstance } from '../reducers/instances';
import { import {
@ -193,9 +192,7 @@ function connect() {
if (process.env.NODE_ENV === 'test') return; if (process.env.NODE_ENV === 'test') return;
const connection = store.getState().connection; const connection = store.getState().connection;
try { try {
socket = socketCluster.create( socket = socketCluster.create(connection.options);
connection.type === 'remotedev' ? socketOptions : connection.options
);
handleConnection(); handleConnection();
} catch (error) { } catch (error) {
store.dispatch({ type: actions.CONNECT_ERROR, error }); store.dispatch({ type: actions.CONNECT_ERROR, error });
@ -204,9 +201,11 @@ function connect() {
} }
function disconnect() { function disconnect() {
if (socket) {
socket.disconnect(); socket.disconnect();
socket.off(); socket.off();
} }
}
function login() { function login() {
socket.emit('login', {}, (error: Error, baseChannel: string) => { socket.emit('login', {}, (error: Error, baseChannel: string) => {

View File

@ -14,7 +14,7 @@ export interface ConnectionState {
export default function connection( export default function connection(
state: ConnectionState = { state: ConnectionState = {
options: { hostname: 'localhost', port: 8000, secure: false }, options: { hostname: 'localhost', port: 8000, secure: false },
type: 'remotedev', type: 'disabled',
}, },
action: StoreAction action: StoreAction
) { ) {

View File

@ -1,4 +1,4 @@
import { createStore, compose, applyMiddleware, Reducer } from 'redux'; import { createStore, compose, applyMiddleware, Reducer, Store } from 'redux';
import localForage from 'localforage'; import localForage from 'localforage';
import { persistReducer, persistStore } from 'redux-persist'; import { persistReducer, persistStore } from 'redux-persist';
import api from '../middlewares/api'; import api from '../middlewares/api';
@ -17,7 +17,9 @@ const persistedReducer: Reducer<StoreState, StoreAction> = persistReducer(
rootReducer rootReducer
) as any; ) as any;
export default function configureStore() { export default function configureStore(
callback: (store: Store<StoreState, StoreAction>) => void
) {
let composeEnhancers = compose; let composeEnhancers = compose;
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
if ( if (
@ -47,6 +49,8 @@ export default function configureStore() {
persistedReducer, persistedReducer,
composeEnhancers(applyMiddleware(exportState, api)) composeEnhancers(applyMiddleware(exportState, api))
); );
const persistor = persistStore(store); const persistor = persistStore(store, null, () => {
callback(store);
});
return { store, persistor }; return { store, persistor };
} }