forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge.ts
More file actions
20 lines (17 loc) · 695 Bytes
/
merge.ts
File metadata and controls
20 lines (17 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
type Method = timer.stat.MergeMethod
export const ALL_MERGE_METHODS: Method[] = ['date', 'domain', 'cate', 'group']
function judgeAdded(target: Method, newVal: Method[], oldVal: Method[]): boolean {
return newVal?.includes?.(target) && !oldVal?.includes?.(target)
}
export function processNewMethod(oldVal: Method[] | undefined, newVal: Method[]): Method[] {
oldVal = oldVal || []
if (judgeAdded('cate', newVal, oldVal)) {
// Add cate, so remove domain
return newVal.filter?.(v => v !== 'domain')
}
if (judgeAdded('domain', newVal, oldVal)) {
// Add domain, so remove cate
return newVal.filter?.(v => v !== 'cate')
}
return newVal
}