Skip to content

Commit

Permalink
Make readonly immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
ioedeveloper committed Mar 30, 2021
1 parent d84df86 commit 490f3ba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
10 changes: 5 additions & 5 deletions libs/remixd/src/bin/remixd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -20,7 +20,7 @@ const ports = {

const killCallBack: Array<Function> = []
function startService<S extends 'git' | 'folder'> (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))
}
Expand Down Expand Up @@ -57,12 +57,12 @@ function startService<S extends 'git' | 'folder'> (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)
Expand Down
6 changes: 2 additions & 4 deletions libs/remixd/src/services/gitClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export class GitClient extends PluginClient {
methods: Array<string>
websocket: WS
currentSharedFolder: string
readOnly: boolean

constructor () {
constructor (private readOnly = false) {
super()
this.methods = ['execute']
}
Expand All @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions libs/remixd/src/services/remixdClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand All @@ -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')
}

Expand Down

0 comments on commit 490f3ba

Please sign in to comment.