-
Notifications
You must be signed in to change notification settings - Fork 36
/
compose.js
69 lines (56 loc) · 2.75 KB
/
compose.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
68
69
import * as Firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import * as Actions from './actions'
export default (config) => {
return next => (reducer, initialState, middleware) => {
const defaultConfig = {
userProfile: null
}
const store = next(reducer, initialState, middleware)
const {dispatch} = store
try {
Firebase.initializeApp(config)
} catch (err) {
console.warn('Firebase error:', err)
}
const ref = Firebase.database().ref()
const configs = Object.assign({}, defaultConfig, config)
const firebase = Object.defineProperty(Firebase, '_', {
value: {
watchers: {},
shouldClearAfterOnce: {},
timeouts: {},
aggregatedData: {},
aggregatedSnapshot: {},
config: configs,
authUid: null
},
writable: true,
enumerable: true,
configurable: true
})
const set = (path, value, onComplete) => ref.child(path).set(value, onComplete)
const push = (path, value, onComplete) => ref.child(path).push(value, onComplete)
const remove = (path, onComplete) => ref.child(path).remove(onComplete)
const update = (path, value, onComplete) => ref.child(path).update(value, onComplete)
const isWatchPath = (eventName, eventPath) => Actions.isWatchPath(firebase, dispatch, eventName, eventPath)
const watchEvent = (eventName, eventPath, isListenOnlyOnDelta, isAggregation, setFunc, setOptions) => Actions.watchEvent(firebase, dispatch, eventName, eventPath, 'Manual', isListenOnlyOnDelta, isAggregation, setFunc, setOptions)
const unWatchEvent = (eventName, eventPath, isSkipClean=false, connectID='Manual') => Actions.unWatchEvent(firebase, dispatch, eventName, eventPath, connectID, isSkipClean)
const login = credentials => Actions.login(dispatch, firebase, credentials)
const logout = (preserve = [], remove = []) => Actions.logout(dispatch, firebase, preserve, remove)
const createUser = (credentials, profile) => Actions.createUser(dispatch, firebase, credentials, profile)
const resetPassword = (credentials) => Actions.resetPassword(dispatch, firebase, credentials)
const changePassword = (credentials) => Actions.changePassword(dispatch, firebase, credentials)
firebase.helpers = {
set, push, remove, update,
createUser,
login, logout,
resetPassword, changePassword,
watchEvent, unWatchEvent, isWatchPath
}
Actions.init(dispatch, firebase)
store.firebase = firebase
return store
}
}