1
0
Fork 0

fix(resolve): moves labels rule check to broader scope

This commit is contained in:
BZ Libby 2020-08-15 17:24:16 -05:00 committed by BZ Libby
parent 6a55a7534a
commit 65b0de5cee
3 changed files with 41 additions and 31 deletions

View File

@ -23,7 +23,6 @@
| Interface | Description |
| --- | --- |
| [FlagLabel](./cautious-journey.flaglabel.md) | Individual labels: the equivalent of a checkbox. |
| [Remote](./cautious-journey.remote.md) | Basic functions which every remote API must provide. |
| [RemoteOptions](./cautious-journey.remoteoptions.md) | |
| [ResolveInput](./cautious-journey.resolveinput.md) | Collected inputs for a resolver run. |
@ -33,3 +32,9 @@
| [StateValue](./cautious-journey.statevalue.md) | One of many values for a particular state. |
| [SyncOptions](./cautious-journey.syncoptions.md) | |
## Type Aliases
| Type Alias | Description |
| --- | --- |
| [FlagLabel](./cautious-journey.flaglabel.md) | Individual labels: the equivalent of a checkbox. |

View File

@ -21,7 +21,7 @@ export interface ChangeSet {
/**
* Common fields for all labels.
*/
export interface BaseLabel {
export interface BaseLabel extends ChangeSet {
/**
* Label name.
*/
@ -46,9 +46,7 @@ export interface BaseLabel {
/**
* Individual labels: the equivalent of a checkbox.
*/
export interface FlagLabel extends BaseLabel, ChangeSet {
requires: Array<LabelRef>;
}
export type FlagLabel = BaseLabel;
/**
* The transition between two state values.

View File

@ -1,4 +1,4 @@
import { FlagLabel, getValueName, prioritySort, StateLabel } from './labels';
import { FlagLabel, getValueName, prioritySort, StateLabel, BaseLabel } from './labels';
/**
* How a label changed.
@ -63,43 +63,50 @@ export function resolveLabels(options: ResolveInput): ResolveResult {
const changes: Array<ChangeRecord> = [];
const errors: Array<ErrorRecord> = [];
const sortedFlags = prioritySort(options.flags);
for (const flag of sortedFlags) {
const { name } = flag;
if (activeLabels.has(name)) {
let removed = false;
for (const requiredLabel of flag.requires) {
function checkLabelRules(label: BaseLabel) {
let isRemoved = false;
if (activeLabels.has(label.name)) {
for (const requiredLabel of label.requires) {
if (!activeLabels.has(requiredLabel.name)) {
activeLabels.delete(name);
removed = true;
activeLabels.delete(label.name);
isRemoved = true;
}
}
if (removed) {
break;
}
for (const addedLabel of flag.adds) {
activeLabels.add(addedLabel.name);
}
for (const removedLabel of flag.removes) {
activeLabels.delete(removedLabel.name);
}
}
if (isRemoved) {
return;
}
for (const addedLabel of label.adds) {
activeLabels.add(addedLabel.name);
}
for (const removedLabel of label.removes) {
activeLabels.delete(removedLabel.name);
}
}
const sortedFlags = prioritySort(options.flags);
for (const flag of sortedFlags) {
checkLabelRules(flag);
}
const sortedStates = prioritySort(options.states);
for (const state of sortedStates) {
let firstActive = true;
const sortedValues = prioritySort(state.values);
for (const value of sortedValues) {
const name = getValueName(state, value);
if (activeLabels.has(name)) {
// TODO: check higher-priority values
// TODO: check removes
// TODO: check requires
// TODO: check becomes
if (firstActive) {
// TODO: check requires
// TODO: check adds
// TODO: check removes
// TODO: check becomes
firstActive = false;
} else {
// removes all other values for this state and breaks?
}
}
}
}