From 9ece5bd28144f34fc336a37f4688a23371778603 Mon Sep 17 00:00:00 2001 From: lironh Date: Sun, 22 Mar 2020 08:42:02 +0200 Subject: feat(demo): saving user history --- demo/src/utils/editor-history.util.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'demo/src/utils') 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); } } -- cgit v1.2.3