-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
67 lines (63 loc) · 1.61 KB
/
store.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
55
56
57
58
59
60
61
62
63
64
65
66
67
import { createStore, combineReducers, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { ListView } from 'react-native'
import PouchDB from 'pouchdb-react-native'
const db = new PouchDB('trendy')
const ds = new ListView.DataSource({rowHasChanged:(r1,r2) => r1 != r2 })
const store = createStore(
combineReducers({
loading: (state=false, action) => {
switch(action.type) {
case 'ISLOADING':
return action.payload
default:
return state
}
},
repos: (state=[], action) => {
switch (action.type) {
case 'SET_REPOS':
return action.payload
default:
return state
}
},
dataSource: (state=ds.cloneWithRows([]), action) => {
switch(action.type) {
case 'SET_REPOS':
return ds.cloneWithRows(action.payload)
default:
return state
}
},
settings: () => null,
settingsDs: () => null,
repo: (state='', action) => {
switch(action.type) {
case 'SET_REPO':
return action.payload
default:
return state
}
},
db: (state=null, action) => {
switch (action.type) {
case 'SET_DB':
return action.payload
default:
return state
}
},
bookmarkDs: (state = ds.cloneWithRows([]), action) => {
switch (action.type) {
case 'SET_BOOKMARKS':
return ds.cloneWithRows(action.payload)
default:
return state
}
}
}),
applyMiddleware(thunk)
)
store.dispatch({ type: 'SET_DB', payload: db })
export default store