Skip to content

Commit

Permalink
separate cleanup from close function
Browse files Browse the repository at this point in the history
`close()` delegates to `OCA.Viewer.close()`.
It is just a shortcut to be used in the template.

`cleanup()` does the actual work.
`OCA.Viewer.close()` will set `file` to `''`.
`file` is being watched and the watch function triggers the cleanup.

This way each step is only getting called once.

Here's what was happening before:
* clicking the ❌ triggers the close function
* close function calls `OCA.Viewer.close()` and triggers the callback
* `OCA.Viewer.close()` sets `file` to `''`
* the `file` watcher triggers the close function again
* close function calls  `OCA.Viewer.close()` and triggers the callback again
* `OCA.Viewer.close()` sets `file` to `''`
* this time it has no effect because it already was empty.

Signed-off-by: Azul <azul@riseup.net>
  • Loading branch information
azul committed Jun 22, 2020
1 parent 0386a2e commit dc72592
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
38 changes: 19 additions & 19 deletions js/viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ export default {
if (path.trim() !== '') {
console.info('Opening viewer for file ', path)
this.openFile(path)
} else if (this.initiated) {
// path is empty, closing!
this.close()
} else {
// path is empty, we're closing!
this.cleanup()
}
},
Expand Down Expand Up @@ -580,8 +580,13 @@ export default {
* Close the viewer
*/
close() {
// reset all properties
// This will set file to ''
// which then triggers cleanup.
OCA.Viewer.close()
},
cleanup() {
// reset all properties
this.currentFile = {}
this.currentModal = null
this.fileList = []
Expand Down

0 comments on commit dc72592

Please sign in to comment.