#Reflex State Library Issue - Observers

1 messages · Page 1 of 1 (latest)

zinc basalt
#

I have this code (irrelevant code removed)

--[[
    Selects the active door map from the current state

    @param state - The current state
]]
local function selectDoorList(state: DoorState.DoorState)
    return table.clone(state.activeDoors)
end

--[[
    Builds the selector for a door with the given ID from
    the map

    @param id - The ID of the door being selected from the map
]]
local function getDoorId(door: DoorState.Door, index: string): string
    return door:GetAttribute("GUID") :: string
end

--[[
    Builds the selector for a door's open state by ID

    @param id - The ID of the door to create the selector for
]]
local function selectOpenStateById(id: string)
    return function(state: DoorState.DoorState)
        return state.openStates[id]
    end
end

DoorState:observe(selectDoorList, getDoorId, function(door: DoorState.Door, id: string)

I used the Reflex docs to try and understand observing so I could make functionality per door.

It only works if I clone the list from the state in selectDoorsList. I thought this was because maybe there's an issue with checking if the table changes, and cloning it makes it a different table, thus it can detect a change.

Am I supposed to clone it? The docs just show returning the state, not cloning it, but it doesn't work that way.

Anyone who's used Reflex before know the issue?