Skip to content

Commit

Permalink
Fix nasty bug that would erase entire app if the page was refreshed i…
Browse files Browse the repository at this point in the history
…n the httpuv mode
  • Loading branch information
nstrayer committed Apr 7, 2023
1 parent aefb778 commit 6aa03f4
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions R/launch_editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,29 @@ launch_editor <- function(app_loc,
}
}

setup_new_app_type <- function(new_app_type = app_type) {
app_type <<- new_app_type
# Turn off app preview and delete the watched files. This should only happen
# when the user has backed out of editing a template app and chosen a new file
# type
reset_app_type <- function() {
shutdown_app_preview()
file_change_watcher$delete_files()
}

if (!identical(new_app_type, "MISSING")) {
# Sets app type variable and also makes sure the files being watched are set.
# I'm not a huge fan of this pattern but it's the best I could come up with
# for now and since we probably will eventually rewrite this in another
# language it feels acceptable for now
setup_new_app_type <- function(new_app_type = app_type) {
# If app type is an existing app then we need to make sure the files being
# watched are properly recorded
is_existing_app <- !identical(new_app_type, "MISSING")
if (is_existing_app) {
file_change_watcher$set_watched_files(app_type_to_files[[new_app_type]])
}
}
app_type <<- new_app_type
}


# ----------------------------------------------------------------------------
# Main logic for responding to messages from the client. Messages have a path
# used for routing and an optional payload. A method of responding is provided
Expand Down Expand Up @@ -177,6 +190,7 @@ launch_editor <- function(app_loc,
# files and update the app type
changed_app_type <- !identical(update_type, app_type)
if (changed_app_type) {
reset_app_type()
setup_new_app_type(update_type)
}

Expand Down

0 comments on commit 6aa03f4

Please sign in to comment.