-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.js
38 lines (32 loc) · 881 Bytes
/
hook.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
import sdk from 'hook.io-sdk'
export default function isomorphicHook(hook) {
hook.fetchStore = function() {
return new Promise((resolve, reject) => {
hook.datastore.get(hook.resource.name)
.then((externalDataStore) => {
hook._data = externalDataStore || {}
resolve(hook._data)
})
.catch(reject)
})
}
hook.set = function(key, value) {
return new Promise((resolve, reject) => {
let newDataStore = hook._data
newDataStore[key] = value
hook.datastore.set(hook.resource.name, newDataStore)
.then(() => {
hook._data = newDataStore
resolve(hook._data)
})
.catch(reject)
})
}
function initHook() {
hook.fetchStore().then(main)
} initHook()
function main(dataStore) {
//Add hook code here
hook.res.json(hook.req.params)
}
}