From 490f3ba5475d0d316f74a0aaf88562b56339ea73 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 30 Mar 2021 12:41:48 +0100 Subject: [PATCH] Make readonly immutable --- libs/remixd/src/bin/remixd.ts | 10 +++++----- libs/remixd/src/services/gitClient.ts | 6 ++---- libs/remixd/src/services/remixdClient.ts | 6 ++---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/libs/remixd/src/bin/remixd.ts b/libs/remixd/src/bin/remixd.ts index e0ba1b53017..671c9de8c0f 100644 --- a/libs/remixd/src/bin/remixd.ts +++ b/libs/remixd/src/bin/remixd.ts @@ -9,8 +9,8 @@ import * as path from 'path' import * as program from 'commander' const services = { - git: () => new servicesList.GitClient(), - folder: () => new servicesList.Sharedfolder() + git: (readOnly: boolean) => new servicesList.GitClient(readOnly), + folder: (readOnly: boolean) => new servicesList.Sharedfolder(readOnly) } const ports = { @@ -20,7 +20,7 @@ const ports = { const killCallBack: Array = [] function startService (service: S, callback: (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => void) { - const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () => services[service]()) + const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () => services[service](program.readOnly || false)) socket.start(callback) killCallBack.push(socket.close.bind(socket)) } @@ -57,12 +57,12 @@ function startService (service: S, callback: (ws: WS startService('folder', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => { sharedFolderClient.setWebSocket(ws) sharedFolderClient.setupNotifications(program.sharedFolder) - sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false) + sharedFolderClient.sharedFolder(program.sharedFolder) }) startService('git', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => { sharedFolderClient.setWebSocket(ws) - sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false) + sharedFolderClient.sharedFolder(program.sharedFolder) }) } catch (error) { throw new Error(error) diff --git a/libs/remixd/src/services/gitClient.ts b/libs/remixd/src/services/gitClient.ts index f4ba43bd1e6..d4658df554f 100644 --- a/libs/remixd/src/services/gitClient.ts +++ b/libs/remixd/src/services/gitClient.ts @@ -6,9 +6,8 @@ export class GitClient extends PluginClient { methods: Array websocket: WS currentSharedFolder: string - readOnly: boolean - constructor () { + constructor (private readOnly = false) { super() this.methods = ['execute'] } @@ -17,9 +16,8 @@ export class GitClient extends PluginClient { this.websocket = websocket } - sharedFolder (currentSharedFolder: string, readOnly: boolean): void { + sharedFolder (currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder - this.readOnly = readOnly } execute (cmd: string) { diff --git a/libs/remixd/src/services/remixdClient.ts b/libs/remixd/src/services/remixdClient.ts index 23bfd3ff964..121b7e677ee 100644 --- a/libs/remixd/src/services/remixdClient.ts +++ b/libs/remixd/src/services/remixdClient.ts @@ -11,9 +11,8 @@ export class RemixdClient extends PluginClient { trackDownStreamUpdate: TrackDownStreamUpdate = {} websocket: WS currentSharedFolder: string - readOnly: boolean - constructor () { + constructor (private readOnly = false) { super() this.methods = ['folderIsReadOnly', 'resolveDirectory', 'get', 'exists', 'isFile', 'set', 'rename', 'remove', 'isDirectory', 'list', 'createDir'] } @@ -22,9 +21,8 @@ export class RemixdClient extends PluginClient { this.websocket = websocket } - sharedFolder (currentSharedFolder: string, readOnly: boolean): void { + sharedFolder (currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder - this.readOnly = readOnly if (this.isLoaded) this.emit('rootFolderChanged') }