Save to localStorage/uri on editor key debounce
parent
fe659b20f4
commit
83ad2e14eb
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in New Issue