-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Copy pathselectors.js
45 lines (39 loc) · 993 Bytes
/
selectors.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
import { createSelector } from "reselect"
import { Map } from "immutable"
const state = state => state || Map()
export const getGenerators = createSelector(
state,
state => {
const languageKeys = state
.get("languages")
const generators = state
.get("generators", Map())
if(!languageKeys) {
return generators
}
return generators
.filter((v, key) => languageKeys.includes(key))
}
)
export const getSnippetGenerators = (state) => ({ fn }) => {
const getGenFn = (key) => fn[`requestSnippetGenerator_${key}`]
return getGenerators(state)
.map((gen, key) => {
const genFn = getGenFn(key)
if(typeof genFn !== "function") {
return null
}
return gen.set("fn", genFn)
})
.filter(v => v)
}
export const getActiveLanguage = createSelector(
state,
state => state
.get("activeLanguage")
)
export const getDefaultExpanded = createSelector(
state,
state => state
.get("defaultExpanded")
)