FragmentFragment

Context

Shared reactive value objects consumed by any Handle.

A Context is a shared reactive value object. Any Handle that calls handle:pull(ctx) subscribes to it and re-renders whenever ctx:patch() is called.

Unlike Stores, Contexts have no builder pattern — they are simple value bags with a patch method. They are ideal for shared cross-Handle state that doesn't belong to a specific data source, like which window is currently open.


Fragment methods

Fragment.createContext(defaults)

Creates a new context. defaults is the initial value table; all keys are live and readable directly from ctx._value.

Prop

Type

Example:

WindowContext.luau
local WindowContext = Fragment.createContext({ 
    active = nil :: string?, 
}) 

-- Optional additional methods for the context.
WindowContext._value.open = function(name: string)
    WindowContext:patch({ active = name })
end

return WindowContext

Context methods

ctx:patch(partial)

Merges partial into the context's value table and queues a re-render for all subscribed Handles. Set a key to Fragment.DELETE to remove it from the value table.

Deferred renders

Subscriber re-renders are queued via task.spawn, so multiple patch calls in the same frame do not cause cascading synchronous renders.

Prop

Type

Example:

WindowContext.luau
WindowContext:patch({ active = "Shop" })

-- Remove a key entirely:
WindowContext:patch({ active = Fragment.DELETE })

On this page