-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.tsx
49 lines (45 loc) · 1.12 KB
/
index.tsx
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import localforage from 'localforage';
import { AsyncTrunk } from 'mobx-sync-lite';
import * as React from 'react';
import { render } from 'react-dom';
import { App } from '../shared/App';
import { store } from '../shared/store';
/**
* the initial state injected by SSR
*/
declare const __INITIAL_STATE__: any;
/**
* @desc create an async trunk with custom options
* @type {AsyncTrunk}
*/
const trunk = new AsyncTrunk(store, {
/**
* @desc custom storage: built in storage is supported
* - localStorage
* - sessionStorage
* - ReactNative.AsyncStorage
*/
storage: localforage as any,
/**
* @desc custom storage key, the default is `__mobx_sync__`
*/
storageKey: '__persist_mobx_stores__',
/**
* @desc the delay time, use for mobx reaction
*/
delay: 1e3,
});
/**
* @desc load persisted stores
*/
trunk.init(__INITIAL_STATE__).then(() => {
console.log('store loaded');
/**
* @desc do any staff with the loaded store,
* and any changes now will be persisted
* @type {boolean}
*/
store.storeLoaded = true;
});
const root = document.getElementById('root');
render(<App />, root);