/
featBitSlice.js
40 lines (32 loc) · 1.19 KB
/
featBitSlice.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
import fbClient from 'featbit-js-client-sdk';
import { createSlice } from '@reduxjs/toolkit';
import { flagsDefaultValues } from './featBit';
const initialState = {
flags: {}
};
export const featBitSlice = createSlice({
name: 'featBit',
initialState,
reducers: {
// Use the PayloadAction type to declare the contents of `action.payload`
updateFeatBitFlags: (state, PayloadAction) => {
const flags = new Proxy({}, {
get(target, prop, receiver) {
if (typeof prop === 'symbol') {
return;
}
return fbClient.variation(prop, flagsDefaultValues[prop] || '');
}
})
state.flags = flags;
}
}
});
export const { updateFeatBitFlags } = featBitSlice.actions;
// The function below is called a selector and allows us to select a value from
// the state. Selectors can also be defined inline where they're used instead of
// in the slice file. For example: `useSelector((state: RootState) => state.counter.value)`
export const featBitFlags = (state) => {
return state.featBit.flags;
}
export default featBitSlice.reducer;