aboutsummaryrefslogtreecommitdiff
path: root/demo/src
diff options
context:
space:
mode:
authorlironh2020-03-22 08:42:02 +0200
committerlironh2020-03-22 08:42:02 +0200
commit9ece5bd28144f34fc336a37f4688a23371778603 (patch)
tree7a4e2df1ca890141623353702dc875f850174ba6 /demo/src
parentfeat(demo): saving user history (diff)
downloadavr8js-9ece5bd28144f34fc336a37f4688a23371778603.tar.gz
avr8js-9ece5bd28144f34fc336a37f4688a23371778603.tar.bz2
avr8js-9ece5bd28144f34fc336a37f4688a23371778603.zip
feat(demo): saving user history
Diffstat (limited to '')
-rw-r--r--demo/src/index.html2
-rw-r--r--demo/src/index.ts2
-rw-r--r--demo/src/utils/editor-history.util.ts9
3 files changed, 8 insertions, 5 deletions
diff --git a/demo/src/index.html b/demo/src/index.html
index 9b69306..332ccb3 100644
--- a/demo/src/index.html
+++ b/demo/src/index.html
@@ -17,7 +17,7 @@
<div class="toolbar">
<button id="run-button">Run</button>
<button id="stop-button" disabled>Stop</button>
- <button id="revert-button">Back to leds example</button>
+ <button id="revert-button">Back to LEDS example</button>
<div class="spacer"></div>
<div id="status-label"></div>
</div>
diff --git a/demo/src/index.ts b/demo/src/index.ts
index 4246547..e3f9a67 100644
--- a/demo/src/index.ts
+++ b/demo/src/index.ts
@@ -102,9 +102,9 @@ async function compileAndRun() {
}
} catch (err) {
runButton.removeAttribute('disabled');
+ revertButton.removeAttribute('disabled');
alert('Failed: ' + err);
} finally {
- revertButton.removeAttribute('disabled');
statusLabel.textContent = '';
}
}
diff --git a/demo/src/utils/editor-history.util.ts b/demo/src/utils/editor-history.util.ts
index 33d1916..65ca38a 100644
--- a/demo/src/utils/editor-history.util.ts
+++ b/demo/src/utils/editor-history.util.ts
@@ -1,17 +1,20 @@
const AVRJS8_EDITOR_HISTORY = 'AVRJS8_EDITOR_HISTORY';
export class EditorHistoryUtil {
+ static hasLocalStorage: boolean = !!window.localStorage;
+
static storeSnippet(codeSnippet: string) {
- if (window.localStorage) {
- window.localStorage.setItem(AVRJS8_EDITOR_HISTORY, codeSnippet);
- } else throw new Error('no localStorage support');
+ if (!EditorHistoryUtil.hasLocalStorage) return;
+ window.localStorage.setItem(AVRJS8_EDITOR_HISTORY, codeSnippet);
}
static clearSnippet() {
+ if (!EditorHistoryUtil.hasLocalStorage) return;
localStorage.removeItem(AVRJS8_EDITOR_HISTORY);
}
static getValue() {
+ if (!EditorHistoryUtil.hasLocalStorage) return;
return localStorage.getItem(AVRJS8_EDITOR_HISTORY);
}
}