------------------------------------------------------------------------------------------ -- vide/wrap.lua ------------------------------------------------------------------------------------------ if not game then script = (require :: any) "test/wrap-require" end local graph = require(script.Parent.graph) type State = graph.State type MaybeState = graph.MaybeState local create = graph.create local get = graph.get local set = graph.set local wrapped = graph.wrapped local throw = require(script.Parent.throw) local flags = require(script.Parent.flags) type Setter = (value: MaybeState | (MaybeState) -> MaybeState, force: boolean?) -> T local function wrap(value: MaybeState?): (State, Setter) local state = create(if wrapped(value) then get(value :: State) else value :: T) local function setter(vi: MaybeState | (MaybeState) -> MaybeState, force: boolean?): T if type(vi) == "function" then vi = vi(get(state)) end local v = if wrapped(vi) then get(vi :: State) else vi :: T if v ~= state.cache or force then set(state, v) elseif flags.strict and type(v) == "table" then throw("attempt to set same table object") end return v end return state, setter end return wrap