Prompt user with a native confirmation dialog when they are closing a file that has unsaved changes.
Solution:
We had a CodeMirror plugin already in place to update the content on a class property so the place to send a signal about code change was already in place.
Since we instantiate the CodeMirrorEditor instance through choo's cache, we can't pass a callback through parameters so we need to do a method overwrite. I thought it would be natural to call it onChange and be called without arguments.
On the store.js file, we instantiate a new file when we start the app and when we open a file. I overwrote the default onChange method by a local function that sets the file object property hasChange to true and calls for a screen re-render.
The hasChanges property won't compare previous and current content of the tab but if the file has received any new input, it will trigger there are changes if you write and erase what you wrote.
Summary:
Prompt user with a native confirmation dialog when they are closing a file that has unsaved changes.
Solution:
We had a CodeMirror plugin already in place to update the content on a class property so the place to send a signal about code change was already in place.
Since we instantiate the
CodeMirrorEditor
instance through choo's cache, we can't pass a callback through parameters so we need to do a method overwrite. I thought it would be natural to call itonChange
and be called without arguments.On the
store.js
file, we instantiate a new file when we start the app and when we open a file. I overwrote the defaultonChange
method by a local function that sets the file object propertyhasChange
totrue
and calls for a screen re-render.The
hasChanges
property won't compare previous and current content of the tab but if the file has received any new input, it will trigger there are changes if you write and erase what you wrote.