marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 793 forks source link

Add function to save code snippets in localStore #468

Closed JoshStern closed 5 years ago

JoshStern commented 5 years ago

There were a few times while going through the book that I refreshed the page and lost my work. I put together a simple localStore mechanism for saving code snippets using their c_ident id. This commit is the bare minimum to get it working and I could easily extend it to a key binding/menu option if you'd like.

I'm not sure about using firstChild to get the node's c_ident. If this assumption isn't safe enough I can access it in a different way.

Thank you for the book; it has been a great resource for learning and teaching javascript!

marijnh commented 5 years ago

That's a good idea. Maybe we can save the code (through a debounced timeout) every time it is edited, instead of when run, to avoid a situation where you had made changes, but not ran them yet when the tab was closed?

JoshStern commented 5 years ago

I like that a lot. Changes made in the last commit.

marijnh commented 5 years ago

Thank you! Merged as 01a97b2b5984