/healthcheck
: always return 200/colors
: return 5 random colors from random available color spaces
- Color
{
"type": "RGB" | "HSL",
"components": string[] // "{value}{unit}" -> "30" or "50%"
}
You'll only need to touch model/color/color.ts
(and test) to extend color space
- Add new color space type to
AvailableColorKeys
, this will then add literal type toAvailableColorKey
type
export const AvailableColorKeys = ['RGB', 'HSL', 'BRGB'] as const
export type AvailableColorKey = typeof AvailableColorKeys[number]
// Now 'RGB' | 'HSL' | 'BRGB'
- Add new color class extending
Color
with staticgetRandomColor()
method
export class BRGB extends Color {
constructor(...colorValues: [ColorValue, ColorValue, ColorValue]) {
super(
'BRGB',
{ unit: ColorUnit.Literal, value: colorValues[0] },
{ unit: ColorUnit.Literal, value: colorValues[1] },
{ unit: ColorUnit.Literal, value: colorValues[2] },
)
}
static getRandomColor() {
return new BRGB(
getRandomNumber(0, 9999),
getRandomNumber(0, 9999),
getRandomNumber(0, 9999),
)
}
}
- Add your class to
AvailableColors
export const AvailableColors = [RGB, HSL, BGRB]
- Implement some test for this new Color, then "BOOM" API part is done.
DC#1: RGB and HSL has different representation in terms of Unit (RGB as literal, HSL with saturation and lightness as percentage)
Solution: Design Color component in the model as {unit: ColorUnit, value: ColorValue}
, and use presenter to combined unit
and value
into one for ease of use in the front end side
Solution: Storing color component as a list extends compatibilty to color space with any number of color components
- Redundant hard-coded minimum and maximum possible value of each component, might be able to lift it out or reuse it somehow.
static
random color getter is not shared amoung the subclasses, eachgetRandomeColor
is its own static method, withAvailableColors
as a bridge.