make sure "remove" return a promise

pull/11/head
yann300 5 years ago committed by ioedeveloper
parent c8fc7c9799
commit 2220068751
  1. 8
      apps/remix-ide/src/app/files/fileProvider.js
  2. 5
      apps/remix-ide/src/app/files/remixDProvider.js

@ -157,12 +157,13 @@ class FileProvider {
* @param {*} path is the folder to be removed * @param {*} path is the folder to be removed
*/ */
remove (path) { remove (path) {
return new Promise((resolve, reject) => {
path = this.removePrefix(path) path = this.removePrefix(path)
if (window.remixFileSystem.existsSync(path)) { if (window.remixFileSystem.existsSync(path)) {
const stat = window.remixFileSystem.statSync(path) const stat = window.remixFileSystem.statSync(path)
try { try {
if (!stat.isDirectory()) { if (!stat.isDirectory()) {
return this.removeFile(path) resolve(this.removeFile(path))
} else { } else {
const items = window.remixFileSystem.readdirSync(path) const items = window.remixFileSystem.readdirSync(path)
if (items.length !== 0) { if (items.length !== 0) {
@ -182,10 +183,11 @@ class FileProvider {
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
return false return resolve(false)
} }
} }
return true return resolve(true)
})
} }
removeFile (path) { removeFile (path) {

@ -130,19 +130,22 @@ module.exports = class RemixDProvider {
} }
remove (path) { remove (path) {
return new Promise((resolve, reject) => {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'remove', { path: unprefixedpath }) this._appManager.call('remixd', 'remove', { path: unprefixedpath })
.then(result => { .then(result => {
console.log('result: ', result) console.log('result: ', result)
const path = this.type + '/' + unprefixedpath const path = this.type + '/' + unprefixedpath
delete this.filesContent[path] delete this.filesContent[path]
resolve(true)
this.init(() => { this.init(() => {
this.event.trigger('fileRemoved', [path]) this.event.trigger('fileRemoved', [path])
}) })
}).catch(error => { }).catch(error => {
if (error) console.log(error) if (error) console.log(error)
resolve(false)
})
}) })
} }

Loading…
Cancel
Save