aboutsummaryrefslogtreecommitdiff
path: root/demo/src/utils/editor-history.util.ts
blob: 65ca38ab4193717f85062cc0b5b51e605a5e06da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);
  }
}