Commit 3163c334 authored by lianahus's avatar lianahus Committed by yann300

refactors events

parent 46d44abc
...@@ -329,18 +329,18 @@ class FileManager extends Plugin { ...@@ -329,18 +329,18 @@ class FileManager extends Plugin {
workspaceExplorer: this._components.registry.get('fileproviders/workspace').api, workspaceExplorer: this._components.registry.get('fileproviders/workspace').api,
filesProviders: this._components.registry.get('fileproviders').api filesProviders: this._components.registry.get('fileproviders').api
} }
this._deps.browserExplorer.event.register('fileChanged', (path) => { this.fileChangedEvent(path) }) this._deps.browserExplorer.event.on('fileChanged', (path) => { this.fileChangedEvent(path) })
this._deps.browserExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) }) this._deps.browserExplorer.event.on('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.localhostExplorer.event.on('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.browserExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) this._deps.browserExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.browserExplorer.event.register('fileAdded', (path) => { this.fileAddedEvent(path) }) this._deps.browserExplorer.event.on('fileAdded', (path) => { this.fileAddedEvent(path) })
this._deps.localhostExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) this._deps.localhostExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.localhostExplorer.event.register('errored', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) this._deps.localhostExplorer.event.on('errored', (event) => { this.removeTabsOf(this._deps.localhostExplorer) })
this._deps.localhostExplorer.event.register('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) this._deps.localhostExplorer.event.on('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) })
this._deps.workspaceExplorer.event.register('fileChanged', (path) => { this.fileChangedEvent(path) }) this._deps.workspaceExplorer.event.on('fileChanged', (path) => { this.fileChangedEvent(path) })
this._deps.workspaceExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) }) this._deps.workspaceExplorer.event.on('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) })
this._deps.workspaceExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) this._deps.workspaceExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) })
this._deps.workspaceExplorer.event.register('fileAdded', (path) => { this.fileAddedEvent(path) }) this._deps.workspaceExplorer.event.on('fileAdded', (path) => { this.fileAddedEvent(path) })
this.getCurrentFile = this.file this.getCurrentFile = this.file
this.getFile = this.readFile this.getFile = this.readFile
......
'use strict' 'use strict'
const CompilerImport = require('../compiler/compiler-imports') const CompilerImport = require('../compiler/compiler-imports')
const EventManager = require('../../lib/events') const EventManager = require('events')
const modalDialogCustom = require('../ui/modal-dialog-custom') const modalDialogCustom = require('../ui/modal-dialog-custom')
const tooltip = require('../ui/tooltip') const tooltip = require('../ui/tooltip')
const remixLib = require('@remix-project/remix-lib') const remixLib = require('@remix-project/remix-lib')
...@@ -111,9 +111,9 @@ class FileProvider { ...@@ -111,9 +111,9 @@ class FileProvider {
return false return false
} }
if (!exists) { if (!exists) {
this.event.trigger('fileAdded', [this._normalizePath(unprefixedpath), false]) this.event.emit('fileAdded', this._normalizePath(unprefixedpath), false)
} else { } else {
this.event.trigger('fileChanged', [this._normalizePath(unprefixedpath)]) this.event.emit('fileChanged', this._normalizePath(unprefixedpath))
} }
cb() cb()
return true return true
...@@ -128,7 +128,7 @@ class FileProvider { ...@@ -128,7 +128,7 @@ class FileProvider {
currentCheck = currentCheck + '/' + value currentCheck = currentCheck + '/' + value
if (!window.remixFileSystem.existsSync(currentCheck)) { if (!window.remixFileSystem.existsSync(currentCheck)) {
window.remixFileSystem.mkdirSync(currentCheck) window.remixFileSystem.mkdirSync(currentCheck)
this.event.trigger('folderAdded', [this._normalizePath(currentCheck)]) this.event.emit('folderAdded', this._normalizePath(currentCheck))
} }
}) })
if (cb) cb() if (cb) cb()
...@@ -184,7 +184,7 @@ class FileProvider { ...@@ -184,7 +184,7 @@ class FileProvider {
// folder is empty // folder is empty
window.remixFileSystem.rmdirSync(path, console.log) window.remixFileSystem.rmdirSync(path, console.log)
} }
this.event.trigger('fileRemoved', [this._normalizePath(path)]) this.event.emit('fileRemoved', this._normalizePath(path))
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
...@@ -249,7 +249,7 @@ class FileProvider { ...@@ -249,7 +249,7 @@ class FileProvider {
path = this.removePrefix(path) path = this.removePrefix(path)
if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) { if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) {
window.remixFileSystem.unlinkSync(path, console.log) window.remixFileSystem.unlinkSync(path, console.log)
this.event.trigger('fileRemoved', [this._normalizePath(path)]) this.event.emit('fileRemoved', this._normalizePath(path))
return true return true
} else return false } else return false
} }
...@@ -259,11 +259,11 @@ class FileProvider { ...@@ -259,11 +259,11 @@ class FileProvider {
var unprefixednewPath = this.removePrefix(newPath) var unprefixednewPath = this.removePrefix(newPath)
if (this._exists(unprefixedoldPath)) { if (this._exists(unprefixedoldPath)) {
window.remixFileSystem.renameSync(unprefixedoldPath, unprefixednewPath) window.remixFileSystem.renameSync(unprefixedoldPath, unprefixednewPath)
this.event.trigger('fileRenamed', [ this.event.emit('fileRenamed',
this._normalizePath(unprefixedoldPath), this._normalizePath(unprefixedoldPath),
this._normalizePath(unprefixednewPath), this._normalizePath(unprefixednewPath),
isFolder isFolder
]) )
return true return true
} }
return false return false
......
...@@ -17,32 +17,32 @@ module.exports = class RemixDProvider extends FileProvider { ...@@ -17,32 +17,32 @@ module.exports = class RemixDProvider extends FileProvider {
var remixdEvents = ['connecting', 'connected', 'errored', 'closed'] var remixdEvents = ['connecting', 'connected', 'errored', 'closed']
remixdEvents.forEach((value) => { remixdEvents.forEach((value) => {
this._appManager.on('remixd', value, (event) => { this._appManager.on('remixd', value, (event) => {
this.event.trigger(value, [event]) this.event.emit(value, event)
}) })
}) })
this._appManager.on('remixd', 'folderAdded', (path) => { this._appManager.on('remixd', 'folderAdded', (path) => {
this.event.trigger('folderAdded', [path]) this.event.emit('folderAdded', path)
}) })
this._appManager.on('remixd', 'fileAdded', (path) => { this._appManager.on('remixd', 'fileAdded', (path) => {
this.event.trigger('fileAdded', [path]) this.event.emit('fileAdded', path)
}) })
this._appManager.on('remixd', 'fileChanged', (path) => { this._appManager.on('remixd', 'fileChanged', (path) => {
this.event.trigger('fileChanged', [path]) this.event.emit('fileChanged', path)
}) })
this._appManager.on('remixd', 'fileRemoved', (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._appManager.on('remixd', 'fileRenamed', (oldPath, newPath) => {
this.event.trigger('fileRemoved', [oldPath, newPath]) this.event.emit('fileRemoved', oldPath, newPath)
}) })
this._appManager.on('remixd', 'rootFolderChanged', () => { this._appManager.on('remixd', 'rootFolderChanged', () => {
this.event.trigger('rootFolderChanged', []) this.event.emit('rootFolderChanged')
}) })
} }
...@@ -53,11 +53,11 @@ module.exports = class RemixDProvider extends FileProvider { ...@@ -53,11 +53,11 @@ module.exports = class RemixDProvider extends FileProvider {
close (cb) { close (cb) {
this._isReady = false this._isReady = false
cb() cb()
this.event.trigger('disconnected') this.event.emit('disconnected')
} }
preInit () { preInit () {
this.event.trigger('loading') this.event.emit('loading')
} }
init (cb) { init (cb) {
...@@ -67,7 +67,7 @@ module.exports = class RemixDProvider extends FileProvider { ...@@ -67,7 +67,7 @@ module.exports = class RemixDProvider extends FileProvider {
this._isReady = true this._isReady = true
this._readOnlyMode = result this._readOnlyMode = result
this._registerEvent() this._registerEvent()
this.event.trigger('connected') this.event.emit('connected')
cb && cb() cb && cb()
}).catch((error) => { }).catch((error) => {
cb && cb(error) cb && cb(error)
...@@ -164,13 +164,13 @@ module.exports = class RemixDProvider extends FileProvider { ...@@ -164,13 +164,13 @@ module.exports = class RemixDProvider extends FileProvider {
this.filesContent[newPath] = this.filesContent[oldPath] this.filesContent[newPath] = this.filesContent[oldPath]
delete this.filesContent[oldPath] delete this.filesContent[oldPath]
this.init(() => { this.init(() => {
this.event.trigger('fileRenamed', [oldPath, newPath, isFolder]) this.event.emit('fileRenamed', oldPath, newPath, isFolder)
}) })
return result return result
}).catch(error => { }).catch(error => {
console.log(error) console.log(error)
if (this.error[error.code]) error = this.error[error.code] 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])
}) })
} }
......
'use strict' 'use strict'
const EventManager = require('../../lib/events') const EventManager = require('events')
const FileProvider = require('./fileProvider') const FileProvider = require('./fileProvider')
const pathModule = require('path') const pathModule = require('path')
...@@ -82,7 +82,7 @@ class WorkspaceFileProvider extends FileProvider { ...@@ -82,7 +82,7 @@ class WorkspaceFileProvider extends FileProvider {
createWorkspace (name) { createWorkspace (name) {
if (!name) name = 'default_workspace' if (!name) name = 'default_workspace'
this.event.trigger('createWorkspace', [name]) this.event.emit('createWorkspace', name)
} }
} }
......
...@@ -97,24 +97,24 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -97,24 +97,24 @@ export const Workspace = (props: WorkspaceProps) => {
props.fileManager.setMode('browser') props.fileManager.setMode('browser')
} }
} }
props.localhost.event.unregister('disconnected', localhostDisconnect) props.localhost.event.off('disconnected', localhostDisconnect)
props.localhost.event.register('disconnected', localhostDisconnect) props.localhost.event.on('disconnected', localhostDisconnect)
useEffect(() => { useEffect(() => {
props.localhost.event.register('connected', () => { props.localhost.event.on('connected', () => {
remixdExplorer.show() remixdExplorer.show()
setWorkspace(LOCALHOST) setWorkspace(LOCALHOST)
}) })
props.localhost.event.register('disconnected', () => { props.localhost.event.on('disconnected', () => {
remixdExplorer.hide() remixdExplorer.hide()
}) })
props.localhost.event.register('loading', () => { props.localhost.event.on('loading', () => {
remixdExplorer.loading() remixdExplorer.loading()
}) })
props.workspace.event.register('createWorkspace', (name) => { props.workspace.event.on('createWorkspace', (name) => {
createNewWorkspace(name) createNewWorkspace(name)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment