Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localStorage #80

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add localStorage #80

wants to merge 9 commits into from

Conversation

aagez
Copy link

@aagez aagez commented Mar 3, 2016

Use of localStorage to save the content of the editor


function loadEditorContent() {
var editorValue = $window.localStorage.getItem("editor." + exercise.id + "." + editor.getOption("mode"));
if (editorValue != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one of the common best practices to use === and !== instead of == and != to prevent type coercion during comparison.
For more details about type coercion and why we want to avoid it, you can check this link: http://blog.jeremymartin.name/2008/03/understanding-loose-typing-in.html

@MatthieuNICOLAS
Copy link
Member

Thanks for your work!

I tested out you changes and, unfortunately, I spotted one issue with the current implementation:

Basically, once you have stored one version of the code in the localStorage, you won't ever use again the code sent by the server anymore. It's not a problem if you always work using the same browser.

But let's say you're using two different browsers. Once you started working on a exercise, you store your current code version into this browser's localStorage.
Then you switch to the other browser and resume the exercise: you start from the last code you submitted, make some changes and submit it again.
When finally you switch back to the first browser, you will retrieve the last version of the code from the server but it will be overriden by the one stored in the localStorage.

So we need to add a mechanism to identify the more recent version of the code between the server's one and the localStorage's one so that we can choose which one to display.

@mquinson
Copy link
Member

Cant we use git to save the data on the localstorage too? This way, git would deal with the issue for us.

@oster
Copy link
Member

oster commented Mar 10, 2016

Student code is already stored in git. I thought the targeted goal of this PR (storing in localstorage) is to keep temporary student code (not yet compiled nor runned) in the browser. Of course, we could store it from time to time to the server (and therefore in git). But then, it means that we do not need localstorage at all, only pushing to the server more frequently (not only at a compilation request) the code written by a student.
Anyway, I have the feeling that we will need a kind of undo/restore/revert functionality to restore the "last compiled" code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants