Save to localStorage/uri on editor key debounce

pull/4696/head
Berkeley Martinez 2015-11-21 20:30:30 -08:00
parent fe659b20f4
commit 83ad2e14eb
3 changed files with 19 additions and 9 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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(() => {