forked from acrazing/mobx-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
52 lines (47 loc) · 1.16 KB
/
index.tsx
File metadata and controls
52 lines (47 loc) · 1.16 KB
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
50
51
52
/*!
* Copyright 2018 acrazing <joking.young@gmail.com>. All rights reserved.
* @since 2018-09-08 10:46:07
*/
import * as React from 'react';
import { render } from 'react-dom';
import { AsyncTrunk } from '../src';
import { App } from './App';
import { store } from './store';
import localforage = require('localforage');
/**
* 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(() => {
/**
* @desc do any staff with the loaded store,
* and any changes now will be persisted
* @type {boolean}
*/
store.storeLoaded = true;
});
render(<App/>, document.getElementById('root'));