/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal * @author Alexander Rose */ /** A mutable value reference. */ interface ValueRef { ref: T; } declare namespace ValueRef { function create(ref: T): ValueRef; function set(ref: ValueRef, value: T): ValueRef; } /** * An immutable value box that also holds a version of the attribute. * Optionally includes automatically propadated "metadata". */ type ValueBox = { /** Unique identifier in the range 0 to 0x7FFFFFFF */ readonly id: number; readonly version: number; readonly metadata: D; readonly value: T; }; declare namespace ValueBox { function create(value: T, metadata?: D): ValueBox; /** The box.metadata is carried over from the old box */ function withValue(box: ValueBox, value: T): ValueBox; } /** An immutable box stored inside a mutable cell. */ type ValueCell = ValueRef>; declare namespace ValueCell { function create(value: T, metadata?: D): ValueCell; /** The box.metadata is carried over from the old box */ function update(cell: ValueCell, value: T): ValueCell; function set(cell: ValueCell, box: ValueBox): ValueCell; /** Updates the cell if the value is has changed, comparing by reference */ function updateIfChanged(cell: ValueCell, value: T): ValueCell; } export { ValueRef, ValueBox, ValueCell };