UNPKG

816 BJavaScriptView Raw
1import {storiesOf} from '@storybook/html';
2
3import Storage from './storage';
4
5storiesOf('Components|Storage', module).
6 addParameters({
7 notes: 'Provides a façade to localStorage/sessionStorage/cookies.',
8 hermione: {skip: true}
9 }).
10 add('basic', () => {
11 const STORAGE_KEY = 'storage-example-key';
12 const storage = new Storage();
13 const node = document.createElement('div');
14
15 let value;
16
17 async function init() {
18 const storedValue = await storage.get(STORAGE_KEY);
19 if (!storedValue) {
20 const generatedValue = Math.random().toString();
21 await storage.set(STORAGE_KEY, generatedValue);
22 value = generatedValue;
23 } else {
24 value = storedValue;
25 }
26
27 node.innerText = `Stored value = ${value}`;
28 }
29
30 init();
31
32 return node;
33 });