moderator-toolbox-nxg-for-reddit / modules/shared/proposals/events
modules/shared/proposals/events¶
Functions¶
broadcastProposalsChanged()¶
broadcastProposalsChanged(
subreddit,data):void
Defined in: extension/data/modules/shared/proposals/events.ts:156
Broadcasts a local proposals mutation to every other open Reddit tab via the
toolbox-global bridge. The background re-dispatches it as a TB_PROPOSALS_CHANGED
window event in each tab (excluding this one), where setupProposalsCrossTab
picks it up. Fire-and-forget: a failed send must never reject the mutation that
triggered it, so transport errors are swallowed (logged only).
The post-write data is shipped in the payload so receivers update their cache
directly rather than re-reading the wiki - the same “trust the in-memory post-write
state” stance the writer takes (~190 ms read-after-write lag). The data’s own seq
page version is what lets receivers order concurrent/delayed broadcasts.
Parameters¶
subreddit¶
string
The subreddit whose proposals changed.
data¶
The authoritative proposals data after the mutation.
Returns¶
void
emitProposalsChanged()¶
emitProposalsChanged(
subreddit):void
Defined in: extension/data/modules/shared/proposals/events.ts:52
Notifies all subscribers that a subreddit’s proposals changed.
Parameters¶
subreddit¶
string
The subreddit whose proposals changed.
Returns¶
void
getCachedProposals()¶
getCachedProposals(
subreddit):ProposalsData|undefined
Defined in: extension/data/modules/shared/proposals/events.ts:75
Returns the cached proposals data for a subreddit, or undefined if not cached.
Parameters¶
subreddit¶
string
The subreddit to look up.
Returns¶
ProposalsData | undefined
invalidateProposalsCache()¶
invalidateProposalsCache(
subreddit?):void
Defined in: extension/data/modules/shared/proposals/events.ts:122
Drops a subreddit’s cached proposals (or all of them when no subreddit is given), forcing the next display read to fetch fresh.
Parameters¶
subreddit?¶
string
The subreddit to invalidate, or omit to clear everything.
Returns¶
void
isProposalsCacheFresh()¶
isProposalsCacheFresh(
subreddit,maxAgeMs,now?):boolean
Defined in: extension/data/modules/shared/proposals/events.ts:87
Returns whether a subreddit’s cache exists and is younger than maxAgeMs. Used by
the cross-subreddit fan-out to skip re-fetching subs whose data is still fresh
while refreshing stale ones, so reopening the drawer doesn’t re-scan every wiki.
Parameters¶
subreddit¶
string
The subreddit to check.
maxAgeMs¶
number
Maximum age in milliseconds for the cache to count as fresh.
now?¶
number = ...
Current epoch milliseconds (injectable for tests; defaults to now).
Returns¶
boolean
onProposalsChanged()¶
onProposalsChanged(
listener): () =>void
Defined in: extension/data/modules/shared/proposals/events.ts:44
Subscribes to proposals-changed notifications.
Parameters¶
listener¶
ProposalsListener
Called with the affected subreddit after each mutation.
Returns¶
An unsubscribe function.
() => void
setCachedProposals()¶
setCachedProposals(
subreddit,data):boolean
Defined in: extension/data/modules/shared/proposals/events.ts:108
Stores proposals data in the session cache, monotonically by page version: a
candidate whose seq is strictly lower than what’s already cached is ignored, so no
source - a lagged read, a local commit, or a cross-tab broadcast - can ever roll the
cache (and the UI reading through it) backward. Equal-or-higher seq replaces the
entry and refreshes its freshness time. The post-write in-memory state is
authoritative (we do not re-read immediately, given the ~190 ms read-after-write lag).
Parameters¶
subreddit¶
string
The subreddit to cache.
data¶
The proposals data to store (its seq orders it against the cache).
Returns¶
boolean
Whether the cache changed (false when an older candidate was ignored), so callers can re-render only on a real advance.
setupProposalsCrossTab()¶
setupProposalsCrossTab():
void
Defined in: extension/data/modules/shared/proposals/events.ts:180
Installs the receiver for cross-tab proposals changes. Called once at startup
(after the message bridge is up). On a TB_PROPOSALS_CHANGED event from another
tab it refreshes this tab’s cache from the payload (or invalidates it when the
payload is unusable) and fires emitProposalsChanged so display surfaces
re-render. It deliberately does NOT re-broadcast, so a received change can’t echo
back out and loop between tabs. Idempotent.
Returns¶
void