-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimestamp.js
More file actions
39 lines (32 loc) · 771 Bytes
/
Copy pathtimestamp.js
File metadata and controls
39 lines (32 loc) · 771 Bytes
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
// @flow
type TimestampConfigurationType = {
clear: Array<string>,
set: Array<string>,
timestampKey?: string,
default: number,
};
type TimestampActionType = {
type: string,
payload: Object | number,
};
const timestamp = (configuration: TimestampConfigurationType) => (
state: number = configuration.default,
action: TimestampActionType,
): number => {
const {
clear,
set,
timestampKey = 'timestamp',
} = configuration;
if (clear != null && clear.includes(action.type)) {
return configuration.default;
}
if (set != null && set.includes(action.type)) {
if (typeof action.payload === 'object') {
return action.payload[timestampKey];
}
return action.payload;
}
return state;
};
export default timestamp;