Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule zui.module·originates fromworld 07158574-5…

dataSource

TTL + gated cached data fetcher. Used by tools that pull live data from the engine at a slower cadence than the UI rebuilds. A closed gate returns the last cached value WITHOUT calling the fetch function; within TTL, the cached value is returned directly. Errors from the fetcher…

byzero-proxy @ DESKTOP-DB3UJOJ·posted 2mo ago
What it does

dataSource

TTL + gated cached data fetcher. Used by tools that pull live data from the engine at a slower cadence than the UI rebuilds. A closed gate returns the last cached value WITHOUT calling the fetch function; within TTL, the cached value is returned directly. Errors from the fetcher are swallowed by default (last value preserved) and surfaced through the optional onError hook.

The module table itself is callable as a shorthand for .create.

Exports

  • M.create(fetchFn: () -> any, opts: Opts?) -> Source — build a new source. Also reachable as M(fetchFn, opts).
  • M.invalidate(key: string) — force a re-fetch on the next read for a registered key.
  • M.reset() — wipe the registry; release retained values.
  • M._seedForTest(key: string, value: any) -> Source? — test hook: install a value without invoking the fetcher.
  • M._peekForTest(key: string) -> Source? — test hook: look up a source by key.

Per-instance methods (on Source):

  • source:read() -> value — read with TTL + gate semantics.
  • source() — callable shorthand, equivalent to source:read().
  • source:invalidate() — clear cached value and timestamp.
  • source.version: number — monotonic counter bumped on every successful fetch.

Types:

  • Opts = { ttl: number?, gate: (() -> boolean)?, key: string?, onError: ((any) -> ())? }
  • Source — instance carrying fetchFn, ttl, gate, onError, key, version, and the internal _value / _t cache slots.

Usage

local DataSource = require("@builtin::modules.zui.dataSource")

local entities = DataSource(function()
    return wld.list()
end, { ttl = 0.2, key = "entities:list" })

local list = entities()                 -- callable shorthand
local same = entities:read()            -- explicit form
DataSource.invalidate("entities:list")  -- force re-fetch

Notes

  • TTL 0 means "always re-fetch"; the cache slot still holds the last value so a closed gate or a fetch error returns it.
  • A closed gate (gate() returns false) skips the fetch entirely and returns the cached value as-is — useful for visibility gating.
  • Fetcher errors are swallowed (cached value preserved) and routed through onError(err) when set.
  • Auto-allocated keys are namespaced under "zui:dataSource:<n>". Explicit keys are preferred so invalidate and the test hooks have a stable handle.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

ZuiDataSource Module TTL + gated cached data fetcher. Used by tools that pull live data from the engine at a slower cadence than the UI rebuilds. Closed gate returns the last cached value WITHOUT calling the fetch function; within TTL, the cached value is returned directly. Errors from the fetcher are swallowed by default (last value preserved) and surfaced through the optional `onError` hook. Surface (instance): local source = Z.dataSource(fetchFn, { ttl = 0.2, -- s; 0 = always re-fetch gate = function() return ... end, -- optional; closed = skip fetch key = "entities:list", -- optional; auto-allocated otherwise onError = function(err) ... end, -- optional }) source:read() -> value source() -> value (callable shorthand) source:invalidate() -> nil source.version -> int (monotonic; bumped on each successful fetch) Surface (module helpers — act on the cross-module registry by key): Z.dataSource.invalidate(key) -> nil Z.dataSource.reset() -> nil Test hooks (prefixed `_`): Z.dataSource._seedForTest(key, value) -> source Z.dataSource._peekForTest(key) -> source | nil Consumers: local DataSource = require("modules.deprecated.zui.dataSource") local src = DataSource(myFetch, { ttl = 0.2 })

__call(self: ?) → void

argtypedescription
self?

autoKey( ) → void

Internal: allocate a unique key when the caller doesn't supply one.

read( ) → void

invalidate( ) → void

Clear the cached value and timestamp so the next `:read()` will re-fetch — even when the gate is currently closed. Invalidate is the documented "force a refresh" entry point; the gate's job is to optimize steady-state cost, not to veto explicit invalidations, so this sets a one-shot `_forceFetch` flag that the next read clears.

examples

source:invalidate()

create(fetchFn: (, opts: ?) →

Create a data source instance wrapping a fetch function with TTL + optional gate. Auto-allocates a key when `opts.key` is omitted.

argtypedescription
fetchFn(The `() -> value` fetcher to call when the cache is cold.
opts?Optional `{ ttl, gate, key, onError }`.

examples

local src = Z.dataSource(myFetch, { ttl = 0.2 })

invalidate(key: string) → void

Force a re-fetch on the next read for a registered key. No-op when the key is unknown.

argtypedescription
keystringThe data source key.

examples

Z.dataSource.invalidate("entities:list")

reset( ) → void

Wipe the registry. Used by destroy() paths to release retained values.

examples

Z.dataSource.reset()

_seedForTest(key: string, value: any) → Source

Test hook: seed a value WITHOUT invoking the fetcher.

argtypedescription
keystringThe data source key.
valueanyThe value to install.

examples

Z.dataSource._seedForTest("entities:list", { 1, 2, 3 })

_peekForTest(key: string) → Source

Test hook: peek at a registered source by key. Returns `nil` when the key is unknown.

argtypedescription
keystringThe data source key.

examples

local src = Z.dataSource._peekForTest("entities:list")
⌬ Types
Opts = {Source = typeof(setmetatable({} :: {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

3items
·
other · born here
▤file
▲ 0↑ born
backing path · modules/deprecated/zui.module/dataSource.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.