refactors events

pull/1119/head
lianahus 4 years ago committed by yann300
parent 46d44abc9d
commit 3163c33464
  1. 24
      apps/remix-ide/src/app/files/fileManager.js
  2. 16
      apps/remix-ide/src/app/files/fileProvider.js
  3. 24
      apps/remix-ide/src/app/files/remixDProvider.js
  4. 4
      apps/remix-ide/src/app/files/workspaceFileProvider.js
  5. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -329,18 +329,18 @@ class FileManager extends Plugin {
workspaceExplorer: this._components.registry.get('fileproviders/workspace').api,
filesProviders: this._components.registry.get('fileproviders').api
}
this._deps.browserExplorer.event.register('fileChanged', (path) => { this.fileChangedEvent(path) })
this._deps.browserExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.localhostExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.browserExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.browserExplorer.event.register('fileAdded', (path) => { this.fileAddedEvent(path) })
this._deps.localhostExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.localhostExplorer.event.register('errored', (event) => { this.removeTabsOf(this._deps.localhostExplorer) })
this._deps.localhostExplorer.event.register('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) })
this._deps.workspaceExplorer.event.register('fileChanged', (path) => { this.fileChangedEvent(path) })
this._deps.workspaceExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.workspaceExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.workspaceExplorer.event.register('fileAdded', (path) => { this.fileAddedEvent(path) })
this._deps.browserExplorer.event.on('fileChanged', (path) => { this.fileChangedEvent(path) })
this._deps.browserExplorer.event.on('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.localhostExplorer.event.on('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.browserExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.browserExplorer.event.on('fileAdded', (path) => { this.fileAddedEvent(path) })
this._deps.localhostExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.localhostExplorer.event.on('errored', (event) => { this.removeTabsOf(this._deps.localhostExplorer) })
this._deps.localhostExplorer.event.on('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) })
this._deps.workspaceExplorer.event.on('fileChanged', (path) => { this.fileChangedEvent(path) })
this._deps.workspaceExplorer.event.on('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.workspaceExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.workspaceExplorer.event.on('fileAdded', (path) => { this.fileAddedEvent(path) })
this.getCurrentFile = this.file
this.getFile = this.readFile

@ -1,7 +1,7 @@
'use strict'
const CompilerImport = require('../compiler/compiler-imports')
const EventManager = require('../../lib/events')
const EventManager = require('events')
const modalDialogCustom = require('../ui/modal-dialog-custom')
const tooltip = require('../ui/tooltip')
const remixLib = require('@remix-project/remix-lib')
@ -111,9 +111,9 @@ class FileProvider {
return false
}
if (!exists) {
this.event.trigger('fileAdded', [this._normalizePath(unprefixedpath), false])
this.event.emit('fileAdded', this._normalizePath(unprefixedpath), false)
} else {
this.event.trigger('fileChanged', [this._normalizePath(unprefixedpath)])
this.event.emit('fileChanged', this._normalizePath(unprefixedpath))
}
cb()
return true
@ -128,7 +128,7 @@ class FileProvider {
currentCheck = currentCheck + '/' + value
if (!window.remixFileSystem.existsSync(currentCheck)) {
window.remixFileSystem.mkdirSync(currentCheck)
this.event.trigger('folderAdded', [this._normalizePath(currentCheck)])
this.event.emit('folderAdded', this._normalizePath(currentCheck))
}
})
if (cb) cb()
@ -184,7 +184,7 @@ class FileProvider {
// folder is empty
window.remixFileSystem.rmdirSync(path, console.log)
}
this.event.trigger('fileRemoved', [this._normalizePath(path)])
this.event.emit('fileRemoved', this._normalizePath(path))
}
} catch (e) {
console.log(e)
@ -249,7 +249,7 @@ class FileProvider {
path = this.removePrefix(path)
if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) {
window.remixFileSystem.unlinkSync(path, console.log)
this.event.trigger('fileRemoved', [this._normalizePath(path)])
this.event.emit('fileRemoved', this._normalizePath(path))
return true
} else return false
}
@ -259,11 +259,11 @@ class FileProvider {
var unprefixednewPath = this.removePrefix(newPath)
if (this._exists(unprefixedoldPath)) {
window.remixFileSystem.renameSync(unprefixedoldPath, unprefixednewPath)
this.event.trigger('fileRenamed', [
this.event.emit('fileRenamed',
this._normalizePath(unprefixedoldPath),
this._normalizePath(unprefixednewPath),
isFolder
])
)
return true
}
return false

@ -17,32 +17,32 @@ module.exports = class RemixDProvider extends FileProvider {
var remixdEvents = ['connecting', 'connected', 'errored', 'closed']
remixdEvents.forEach((value) => {
this._appManager.on('remixd', value, (event) => {
this.event.trigger(value, [event])
this.event.emit(value, event)
})
})
this._appManager.on('remixd', 'folderAdded', (path) => {
this.event.trigger('folderAdded', [path])
this.event.emit('folderAdded', path)
})
this._appManager.on('remixd', 'fileAdded', (path) => {
this.event.trigger('fileAdded', [path])
this.event.emit('fileAdded', path)
})
this._appManager.on('remixd', 'fileChanged', (path) => {
this.event.trigger('fileChanged', [path])
this.event.emit('fileChanged', path)
})
this._appManager.on('remixd', 'fileRemoved', (path) => {
this.event.trigger('fileRemoved', [path])
this.event.emit('fileRemoved', path)
})
this._appManager.on('remixd', 'fileRenamed', (oldPath, newPath) => {
this.event.trigger('fileRemoved', [oldPath, newPath])
this.event.emit('fileRemoved', oldPath, newPath)
})
this._appManager.on('remixd', 'rootFolderChanged', () => {
this.event.trigger('rootFolderChanged', [])
this.event.emit('rootFolderChanged')
})
}
@ -53,11 +53,11 @@ module.exports = class RemixDProvider extends FileProvider {
close (cb) {
this._isReady = false
cb()
this.event.trigger('disconnected')
this.event.emit('disconnected')
}
preInit () {
this.event.trigger('loading')
this.event.emit('loading')
}
init (cb) {
@ -67,7 +67,7 @@ module.exports = class RemixDProvider extends FileProvider {
this._isReady = true
this._readOnlyMode = result
this._registerEvent()
this.event.trigger('connected')
this.event.emit('connected')
cb && cb()
}).catch((error) => {
cb && cb(error)
@ -164,13 +164,13 @@ module.exports = class RemixDProvider extends FileProvider {
this.filesContent[newPath] = this.filesContent[oldPath]
delete this.filesContent[oldPath]
this.init(() => {
this.event.trigger('fileRenamed', [oldPath, newPath, isFolder])
this.event.emit('fileRenamed', oldPath, newPath, isFolder)
})
return result
}).catch(error => {
console.log(error)
if (this.error[error.code]) error = this.error[error.code]
this.event.trigger('fileRenamedError', [this.error[error.code]])
this.event.emit('fileRenamedError', this.error[error.code])
})
}

@ -1,6 +1,6 @@
'use strict'
const EventManager = require('../../lib/events')
const EventManager = require('events')
const FileProvider = require('./fileProvider')
const pathModule = require('path')
@ -82,7 +82,7 @@ class WorkspaceFileProvider extends FileProvider {
createWorkspace (name) {
if (!name) name = 'default_workspace'
this.event.trigger('createWorkspace', [name])
this.event.emit('createWorkspace', name)
}
}

@ -97,24 +97,24 @@ export const Workspace = (props: WorkspaceProps) => {
props.fileManager.setMode('browser')
}
}
props.localhost.event.unregister('disconnected', localhostDisconnect)
props.localhost.event.register('disconnected', localhostDisconnect)
props.localhost.event.off('disconnected', localhostDisconnect)
props.localhost.event.on('disconnected', localhostDisconnect)
useEffect(() => {
props.localhost.event.register('connected', () => {
props.localhost.event.on('connected', () => {
remixdExplorer.show()
setWorkspace(LOCALHOST)
})
props.localhost.event.register('disconnected', () => {
props.localhost.event.on('disconnected', () => {
remixdExplorer.hide()
})
props.localhost.event.register('loading', () => {
props.localhost.event.on('loading', () => {
remixdExplorer.loading()
})
props.workspace.event.register('createWorkspace', (name) => {
props.workspace.event.on('createWorkspace', (name) => {
createNewWorkspace(name)
})

Loading…
Cancel
Save