diff --git a/client/commonFramework/code-storage.js b/client/commonFramework/code-storage.js index d2999b2e2f..26f6bd5b5b 100644 --- a/client/commonFramework/code-storage.js +++ b/client/commonFramework/code-storage.js @@ -19,8 +19,8 @@ window.common = (function(global) { return '' + localStorage.getItem(key + 'Val'); }, - isAlive: function() { - var val = this.getStoredValue(); + isAlive: function(key) { + var val = this.getStoredValue(key); return val !== 'null' && val !== 'undefined' && (val && val.length > 0); diff --git a/client/commonFramework/create-editor.js b/client/commonFramework/create-editor.js index 809b71db33..7990fb9c4f 100644 --- a/client/commonFramework/create-editor.js +++ b/client/commonFramework/create-editor.js @@ -38,12 +38,11 @@ window.common = (function(global) { editor.setSize('100%', 'auto'); - common.editorKeyUp$ = Observable.fromEventPattern( - () => editor.on('keyup'), - () => editor.off('keyup') - ); - common.editorExecute$ = new Subject(); + common.editorKeyUp$ = Observable.fromEventPattern( + (handler) => editor.on('keyup', handler), + (handler) => editor.off('keyup', handler) + ); editor.setOption('extraKeys', { Tab: function(cm) { @@ -99,8 +98,8 @@ window.common = (function(global) { if (common.codeUri.isAlive()) { editorValue = common.codeUri.parse(); } else { - editorValue = common.codeStorage.isAlive() ? - common.codeStorage.getStoredValue() : + editorValue = common.codeStorage.isAlive(common.challengeName) ? + common.codeStorage.getStoredValue(common.challengeName) : common.seed; } diff --git a/client/commonFramework/end.js b/client/commonFramework/end.js index 0ae61ad01c..e0c36961ad 100644 --- a/client/commonFramework/end.js +++ b/client/commonFramework/end.js @@ -7,6 +7,17 @@ $(document).ready(function() { init($); }); + common.editorKeyUp$ + .debounce(750) + .map(() => common.editor.getValue()) + .doOnNext(() => console.log('updating value')) + .subscribe( + code => { + common.codeStorage.updateStorage(common.challengeName, code); + common.codeUri.querify(code); + }, + err => console.error(err) + ); common.resetBtn$ .doOnNext(() => {