-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (45 loc) · 1.34 KB
/
index.js
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
53
54
import React from 'react';
import ReactDOM from 'react-dom';
import { onSnapshot, getSnapshot } from 'mobx-state-tree';
import App from './components/App';
import AppSettings from './models/AppSettings';
import {User} from './models/Group';
import {WishList} from './models/WishList';
import {Provider} from 'mobx-react';
import usersData from './assets/users.json';
import stateData from './assets/data.json';
const appSettings = {
showUserAttributes: false
},
AppSettingsStore = AppSettings.create(appSettings);
const user = usersData.users[0],
userStore = User.create(user);
let initialState = stateData;
// const data = localStorage.getItem("wishlistapp");
// if(data){
// initialState = JSON.parse(data);
// }
let wishList = WishList.create(initialState,{
alert: m => console.log(m)
});
onSnapshot(wishList, snapshot => {
localStorage.setItem('wishlistapp', JSON.stringify(snapshot));
})
function renderApp(){
ReactDOM.render(
<Provider wishList={wishList} user={userStore} appSettings={AppSettingsStore} >
<App />
</Provider>
, document.getElementById('root'));
}
renderApp();
if(module.hot) {
module.hot.accept(['./components/App'], () => {
renderApp()
});
module.hot.accept(["./models/WishList"], () => {
const snapshot = getSnapshot(wishList);
wishList = WishList.create(snapshot);
renderApp();
});
}