Skip to content

Commit

Permalink
Eliminate DecisionValue and createDecisionValue() (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrezero authored Jan 24, 2025
1 parent 8fb2d66 commit d5f75b1
Show file tree
Hide file tree
Showing 56 changed files with 58 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ const store = createDecisionStaticStore(decisions);
const { d } = Astro.props
const [, decision] = store.decision<ColorDecision>(d);
const color = decision.value().toString('oklch')
const color = decision.produce().toString('oklch')
---
<div class="my-color-value-viz">{color.value}</div>
<div class="my-color-value-viz">{color}</div>
<style define:vars={{ 'my-color': color }}>
.my-color-value-viz { background-color: var(--my-color) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
Decision,
DecisionContext,
DecisionInputBase,
DecisionValue,
LookupContexts,
ParentValueContext,
} from '../types';
Expand All @@ -14,7 +13,7 @@ export const createStaticStoreDecision = <V = unknown>(
decisionContext: DecisionContext,
inputs: DecisionInputBase[],
): Decision<V> => {
const produce = (context?: LookupContexts | ParentValueContext): DecisionValue<V> => {
const produce = (context?: LookupContexts | ParentValueContext): V => {
const input = inputs[0]; // WIP match context
const modelFactory = getDecisionModelFactory<V>(input.model);
const model = modelFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
DecisionModelFactory,
OklabHueSet,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabHueSetAnchoredModel: DecisionModelFactory<
OklabHueSet,
Expand All @@ -21,9 +20,7 @@ export const createColorOklabHueSetAnchoredModel: DecisionModelFactory<

const series = generateAnchoredSeries(anchor, params, [0, 360]);
const values = series.map(item => createOklabHueValue(valueContext, item));
const value = createOklabHueSet(valueContext, values);

return createDecisionValue(valueContext, value);
return createOklabHueSet(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type DecisionModelFactory,
type OklabHueSet,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabHueSetBoundedModel: DecisionModelFactory<
OklabHueSet,
Expand All @@ -20,9 +19,7 @@ export const createColorOklabHueSetBoundedModel: DecisionModelFactory<

const series = generateBoundedSeries(from, to, params.steps);
const values = series.map(item => createOklabHueValue(valueContext, item));
const value = createOklabHueSet(valueContext, [fromValue, ...values, toValue]);

return createDecisionValue(valueContext, value);
return createOklabHueSet(valueContext, [fromValue, ...values, toValue]);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
DecisionModelFactory,
OklabHueSet,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabHueSetExplicitModel: DecisionModelFactory<
OklabHueSet,
Expand All @@ -14,9 +13,7 @@ export const createColorOklabHueSetExplicitModel: DecisionModelFactory<
produce: (valueContext, params) => {
const values = params.values.map(value => createOklabHueValue(valueContext, value));

const value = createOklabHueSet(valueContext, values);

return createDecisionValue(valueContext, value);
return createOklabHueSet(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
type DecisionModelFactory,
type OklabHueValue,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabHueValueExplicitModel: DecisionModelFactory<
OklabHueValue,
ColorOklabHueValueExplicitInput
> = () => {
return {
produce: (valueContext, params) => {
const value = createOklabHueValue(valueContext, params.value);

return createDecisionValue(valueContext, value);
return createOklabHueValue(valueContext, params.value);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
DecisionModelFactory,
OklabLightnessScale,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabLightnessScaleAnchoredModel: DecisionModelFactory<
OklabLightnessScale,
Expand All @@ -21,9 +20,7 @@ export const createColorOklabLightnessScaleAnchoredModel: DecisionModelFactory<

const series = generateAnchoredSeries(anchor, params, [0, 1]);
const values = series.map(item => createOklabLightnessValue(valueContext, item));
const value = createOklabLightnessScale(valueContext, values);

return createDecisionValue(valueContext, value);
return createOklabLightnessScale(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
type DecisionModelFactory,
type OklabLightnessScale,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabLightnessScaleBoundedModel: DecisionModelFactory<
OklabLightnessScale,
Expand All @@ -24,9 +23,7 @@ export const createColorOklabLightnessScaleBoundedModel: DecisionModelFactory<

const series = generateBoundedSeries(from, to, params.steps);
const values = series.map(item => createOklabLightnessValue(valueContext, item));
const value = createOklabLightnessScale(valueContext, [fromValue, ...values, toValue]);

return createDecisionValue(valueContext, value);
return createOklabLightnessScale(valueContext, [fromValue, ...values, toValue]);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
DecisionModelFactory,
OklabLightnessScale,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabLightnessScaleExplicitModel: DecisionModelFactory<
OklabLightnessScale,
Expand All @@ -16,9 +15,7 @@ export const createColorOklabLightnessScaleExplicitModel: DecisionModelFactory<
createOklabLightnessValue(valueContext, value),
);

const value = createOklabLightnessScale(valueContext, values);

return createDecisionValue(valueContext, value);
return createOklabLightnessScale(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
type DecisionModelFactory,
type OklabLightnessValue,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabLightnessValueExplicitModel: DecisionModelFactory<
OklabLightnessValue,
ColorOklabLightnessValueExplicitInput
> = () => {
return {
produce: (valueContext, params) => {
const value = createOklabLightnessValue(valueContext, params.value);

return createDecisionValue(valueContext, value);
return createOklabLightnessValue(valueContext, params.value);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
DecisionModelFactory,
OklabChromaScale,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabChromaScaleAnchoredModel: DecisionModelFactory<
OklabChromaScale,
Expand All @@ -21,9 +20,7 @@ export const createColorOklabChromaScaleAnchoredModel: DecisionModelFactory<

const series = generateAnchoredSeries(anchor, params, [0, 0.4]);
const values = series.map(item => createOklabChromaValue(valueContext, item));
const value = createOklabChromaScale(valueContext, values);

return createDecisionValue(valueContext, value);
return createOklabChromaScale(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
type DecisionModelFactory,
type OklabChromaScale,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabChromaScaleBoundedModel: DecisionModelFactory<
OklabChromaScale,
Expand All @@ -24,9 +23,7 @@ export const createColorOklabChromaScaleBoundedModel: DecisionModelFactory<

const series = generateBoundedSeries(from, to, params.steps);
const values = series.map(item => createOklabChromaValue(valueContext, item));
const value = createOklabChromaScale(valueContext, [fromValue, ...values, toValue]);

return createDecisionValue(valueContext, value);
return createOklabChromaScale(valueContext, [fromValue, ...values, toValue]);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
DecisionModelFactory,
OklabChromaScale,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabChromaScaleExplicitModel: DecisionModelFactory<
OklabChromaScale,
Expand All @@ -14,9 +13,7 @@ export const createColorOklabChromaScaleExplicitModel: DecisionModelFactory<
produce: (valueContext, params) => {
const values = params.values.map(value => createOklabChromaValue(valueContext, value));

const value = createOklabChromaScale(valueContext, values);

return createDecisionValue(valueContext, value);
return createOklabChromaScale(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
type DecisionModelFactory,
type OklabChromaValue,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorOklabChromaValueExplicitModel: DecisionModelFactory<
OklabChromaValue,
ColorOklabChromaValueExplicitInput
> = () => {
return {
produce: (valueContext, params) => {
const value = createOklabChromaValue(valueContext, params.value);

return createDecisionValue(valueContext, value);
return createOklabChromaValue(valueContext, params.value);
},
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createColorSet, createColorValue, generateAnchoredColorList } from '../../../primitives';
import type { ColorSet, ColorSetAnchoredInput, DecisionModelFactory } from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSetAnchoredModel: DecisionModelFactory<
ColorSet,
Expand All @@ -12,9 +11,7 @@ export const createColorSetAnchoredModel: DecisionModelFactory<

const list = generateAnchoredColorList(anchor, params);
const values = list.map(item => createColorValue(valueContext, item));
const value = createColorSet(valueContext, values);

return createDecisionValue(valueContext, value);
return createColorSet(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createColorSet, createColorValue, generateBoundedColorList } from '../../../primitives';
import type { ColorSet, ColorSetBoundedInput, DecisionModelFactory } from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSetBoundedModel: DecisionModelFactory<
ColorSet,
Expand All @@ -13,9 +12,7 @@ export const createColorSetBoundedModel: DecisionModelFactory<

const list = generateBoundedColorList(fromValue, toValue, params.steps);
const values = list.map(item => createColorValue(valueContext, item));
const value = createColorSet(valueContext, [fromValue, ...values, toValue]);

return createDecisionValue(valueContext, value);
return createColorSet(valueContext, [fromValue, ...values, toValue]);
},
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createColorSet, createColorValue } from '../../../primitives';
import type { ColorSet, ColorSetExplicitInput, DecisionModelFactory } from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSetExplicitModel: DecisionModelFactory<
ColorSet,
Expand All @@ -9,9 +8,7 @@ export const createColorSetExplicitModel: DecisionModelFactory<
return {
produce: (valueContext, params) => {
const values = params.values.map(value => createColorValue(valueContext, value));
const value = createColorSet(valueContext, values);

return createDecisionValue(valueContext, value);
return createColorSet(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
DecisionModelFactory,
SRGBHueSet,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSRGBHueSetAnchoredModel: DecisionModelFactory<
SRGBHueSet,
Expand All @@ -17,9 +16,7 @@ export const createColorSRGBHueSetAnchoredModel: DecisionModelFactory<

const series = generateAnchoredSeries(anchor, params, [0, 360]);
const values = series.map(item => createSRGBHueValue(valueContext, item));
const value = createSRGBHueSet(valueContext, values);

return createDecisionValue(valueContext, value);
return createSRGBHueSet(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type DecisionModelFactory,
type SRGBHueSet,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSRGBHueSetBoundedModel: DecisionModelFactory<
SRGBHueSet,
Expand All @@ -20,9 +19,7 @@ export const createColorSRGBHueSetBoundedModel: DecisionModelFactory<

const series = generateBoundedSeries(from, to, params.steps);
const values = series.map(item => createSRGBHueValue(valueContext, item));
const value = createSRGBHueSet(valueContext, [fromValue, ...values, toValue]);

return createDecisionValue(valueContext, value);
return createSRGBHueSet(valueContext, [fromValue, ...values, toValue]);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
DecisionModelFactory,
SRGBHueSet,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSRGBHueSetExplicitModel: DecisionModelFactory<
SRGBHueSet,
Expand All @@ -14,9 +13,7 @@ export const createColorSRGBHueSetExplicitModel: DecisionModelFactory<
produce: (valueContext, params) => {
const values = params.values.map(value => createSRGBHueValue(valueContext, value));

const value = createSRGBHueSet(valueContext, values);

return createDecisionValue(valueContext, value);
return createSRGBHueSet(valueContext, values);
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
type DecisionModelFactory,
type SRGBHueValue,
} from '../../../types';
import { createDecisionValue } from '../../../values';

export const createColorSRGBHueValueExplicitModel: DecisionModelFactory<
SRGBHueValue,
ColorSRGBHueValueExplicitInput
> = () => {
return {
produce: (valueContext, params) => {
const value = createSRGBHueValue(valueContext, params.value);

return createDecisionValue(valueContext, value);
return createSRGBHueValue(valueContext, params.value);
},
};
};
Loading

0 comments on commit d5f75b1

Please sign in to comment.