-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (39 loc) · 1.03 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
// @flow
'use strict'
// =======================
// Domain: Data persistence
// =======================
import sbp from '@sbp/sbp'
const _store = new Map()
export default (sbp('sbp/selectors/register', {
'okTurtles.data/get': function (key: any): any {
return _store.get(key)
},
'okTurtles.data/set': function (key: any, data: any): any {
_store.set(key, data)
return data
},
'okTurtles.data/delete': function (key: any) {
return _store.delete(key)
},
'okTurtles.data/add': function (key: any, data: any) {
const array = _store.get(key)
if (array) {
array.push(data)
} else {
_store.set(key, [data])
}
},
'okTurtles.data/remove': function (key: any, data: any) {
const array = _store.get(key)
if (array) {
const aLen = array.length
const filtered = array.filter(v => v !== data)
_store.set(key, filtered)
return aLen - filtered.length
}
},
'okTurtles.data/apply': function (key: any, fn: Function) {
return fn(_store.get(key))
}
}): string[])