The State of Jsonnet
Altering behavior based on internal state.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Phase Shifting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local States = {
started: { status: "running", log: "System is online" },
stopped: { status: "halted", log: "System is offline" }
};
local Context(stateName) = {
state: States[stateName],
render():: "App is " + self.state.status + " | " + self.state.log
};
{
s1: Context("started").render(),
s2: Context("stopped").render()
}
The State pattern morphs behavior based on an injected state key, swapping out entire objects of logic and configuration depending on the current phase of the moon.
Runic Tags:
#behavioral
#state
#jsonnet