aboutsummaryrefslogtreecommitdiff
path: root/demo/src/utils/editor-history.util.ts
blob: 023a6985f80c8213348cb746cf72c6f2a4da3325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const AVRJS8_EDITOR_HISTORY = 'AVRJS8_EDITOR_HISTORY';

export class EditorHistoryUtil {
  static hasLocalStorage = !!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);
  }
}