Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

reactions.gno

1.78 Kb · 42 lines
 1package home
 2
 3import (
 4	"gno.land/p/moul/dynreplacer/v0"
 5	"gno.land/r/moul/reactions/v0"
 6)
 7
 8// This file is the one interactive thing on the page: a :reactions: placeholder
 9// that renders the reaction block from gno.land/r/moul/reactions, keyed on this
10// realm's path.
11//
12// Nothing is stored here. The tallies live in the reactions realm, which is why
13// this realm can be redeployed (and wiped, see the package doc) without losing
14// anyone's reaction, and why adding this cost one placeholder rather than a
15// state machine.
16//
17// The block renders its own txlinks, so a reader clicks an emoji here and lands
18// on the reactions realm's $help form with the page prefilled. This realm has
19// no write path of its own for it and does not want one: the point of the
20// indirection is that the same block behaves identically on every page that
21// embeds it.
22
23// reactionsPlaceholders are the reserved slugs this file answers for. Listed in
24// reservedSlugs (home.gno) so a slot can never take one of these names and
25// shadow the computed value.
26var reactionsPlaceholders = []string{"reactions"}
27
28// registerReactionCallbacks adds the reaction placeholder to r.
29//
30// dynreplacer only invokes a callback whose placeholder actually occurs in the
31// layout, so a layout that does not use :reactions: never calls into the
32// reactions realm at all.
33//
34// RenderBlockFor is used rather than the zero-argument RenderBlock, for the
35// same reason config.TopBlockFor is (see render.gno): the zero-argument form
36// reads the caller off the stack, which would be correct here, but this realm
37// already states its own path as a constant and passing it cannot be wrong.
38func registerReactionCallbacks(r *dynreplacer.Replacer) {
39	r.RegisterCallback(":reactions:", func() string {
40		return reactions.RenderBlockFor(realmPath)
41	})
42}