⚙️ JSONNET RUNE DIFFICULTY: Archmage Behavioral

The Memento of Jsonnet

Capturing and restoring an object's internal state.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Time Capsule
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local Originator(state) = {
  currentState: state,
  save():: state,
  restore(memento):: Originator(memento)
};

local State1 = Originator({ hp: 100, level: 1 });
local Memento = State1.save();
local State2 = State1 { currentState: { hp: 50, level: 2 } };

{
  current: State2.currentState,
  restored: State2.restore(Memento).currentState
}

Immutable data means every snapshot is naturally a Memento. By preserving prior states in variables, time-travel across configuration timelines becomes trivial.

Runic Tags: #behavioral #memento #jsonnet