aboutsummaryrefslogtreecommitdiff
path: root/demo/src/utils/editor-history.util.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--demo/src/utils/editor-history.util.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/demo/src/utils/editor-history.util.ts b/demo/src/utils/editor-history.util.ts
new file mode 100644
index 0000000..65ca38a
--- /dev/null
+++ b/demo/src/utils/editor-history.util.ts
@@ -0,0 +1,20 @@
+const AVRJS8_EDITOR_HISTORY = 'AVRJS8_EDITOR_HISTORY';
+
+export class EditorHistoryUtil {
+ static hasLocalStorage: boolean = !!window.localStorage;
+
+ static storeSnippet(codeSnippet: string) {
+ 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);
+ }
+}