Selector Map
What is a Selector Map?
A selector map is an object holding key:value pairs used for defining parts of the state to observe and retrieve.
An array of property paths is also acceptable: indexes serve as keys for this purpose.
key
refers to an arbitrary name to be assigned to a given property in the store.data
.value
refers to the property path leading to a state slice whose value will be assigned to and observed by this store.data
property.A special '@@STATE' value may be used to access and observe the full state object.
Example:
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
// Given the following state object:
const state = {
a: 1, b: 2, c: 3, d: {
e: 5,
f: [ 6, {
x: 7,
y: 8,
z: 9
} ]
}
};
/* --------------------------------------------- */
/* a client observing the following selector map */
/* --------------------------------------------- */
const selectorMap = {
all: '@@STATE',
myData: 'd',
secondFElement: 'd.f[1]'
};
// will receive the following store data
store.data = {
all: state,
myData: state.d,
secondFElement: state.d.f[1]
};
/* --------------------------------------------------- */
/* a client observing the following property path list */
/* --------------------------------------------------- */
const propertyPaths = [ '@@STATE', 'd', 'd.f[1]' ];
// will receive the following store data
store.data = {
0: state,
1: state.d,
2: state.d.f[1]
};