diff options
| author | Uri Shaked | 2020-03-22 10:28:31 +0200 |
|---|---|---|
| committer | GitHub | 2020-03-22 10:28:31 +0200 |
| commit | 87ef2c22913dbf07bbe4c10c6ea249a6dfa4b42c (patch) | |
| tree | 7a4e2df1ca890141623353702dc875f850174ba6 /demo/src/utils | |
| parent | Merge pull request #19 from gfeun/main-execute-loop-optimization (diff) | |
| parent | feat(demo): saving user history (diff) | |
| download | avr8js-87ef2c22913dbf07bbe4c10c6ea249a6dfa4b42c.tar.gz avr8js-87ef2c22913dbf07bbe4c10c6ea249a6dfa4b42c.tar.bz2 avr8js-87ef2c22913dbf07bbe4c10c6ea249a6dfa4b42c.zip | |
Merge pull request #25 from LironHazan/AVR8JS-24-editor-user-history
feat(demo): saving user history
Diffstat (limited to 'demo/src/utils')
| -rw-r--r-- | demo/src/utils/editor-history.util.ts | 20 |
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); + } +} |
