From ee5708e0babd08e3ed4fffbf9a24d7cd5755a782 Mon Sep 17 00:00:00 2001 From: lironh Date: Sat, 21 Mar 2020 21:47:31 +0200 Subject: feat(demo): saving user history --- demo/src/utils/editor-history.util.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 demo/src/utils/editor-history.util.ts (limited to 'demo/src/utils/editor-history.util.ts') diff --git a/demo/src/utils/editor-history.util.ts b/demo/src/utils/editor-history.util.ts new file mode 100644 index 0000000..33d1916 --- /dev/null +++ b/demo/src/utils/editor-history.util.ts @@ -0,0 +1,17 @@ +const AVRJS8_EDITOR_HISTORY = 'AVRJS8_EDITOR_HISTORY'; + +export class EditorHistoryUtil { + static storeSnippet(codeSnippet: string) { + if (window.localStorage) { + window.localStorage.setItem(AVRJS8_EDITOR_HISTORY, codeSnippet); + } else throw new Error('no localStorage support'); + } + + static clearSnippet() { + localStorage.removeItem(AVRJS8_EDITOR_HISTORY); + } + + static getValue() { + return localStorage.getItem(AVRJS8_EDITOR_HISTORY); + } +} -- cgit v1.2.3