-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonChange.js
53 lines (46 loc) · 1.38 KB
/
onChange.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
46
47
48
49
50
51
52
53
/**
* Copyright (C) 2022, BBC R&D
* This source code is licensed under the GPL license found in the LICENSE file in this repository.
*/
/**
* The onChange behaviour sets some flags that are then handled by applyOnChangeBehaviour during the
* allocation algorithm. No changes are made to the lists.
*/
const onChange = ({ behaviourParameters }) => {
const flagsToAdd = ['onChange-applied'];
const allStartOptions = [
'canAlwaysStart',
'canNeverRestart',
'canOnlyStartOnFirstRun',
];
const allAllocateOptions = [
'moveToPreferred',
'stayInPrevious',
'moveToAllowedNotPrevious',
'moveToAllowed',
];
const {
start = 'canAlwaysStart',
allocate = allAllocateOptions,
} = behaviourParameters;
// Set flags based on start options
if (allStartOptions.includes(start)) {
flagsToAdd.push(`onChange-${start}`);
} else {
console.warn(`Invalid onChange start value: ${start}`);
}
// Set flags based on allocate options
// Loop over values, see if it's valid, if it is then add a flag
allocate.forEach((valueInAllocateList) => {
if (allAllocateOptions.includes(valueInAllocateList)) {
flagsToAdd.push(`onChange-${valueInAllocateList}`);
} else {
console.warn(`Unknown value in onChange allocate: ${valueInAllocateList}`);
}
});
// Return the new flags
return {
flags: flagsToAdd,
};
};
export default onChange;