GX4016: topic key with no Publish, or Publish with no listener
A hint. A constant topic key of gx.TopicKey has no App.Publish call of the same key, or a constant key of App.Publish has no gx.TopicKey call.
Cause
GX4016 is a hint. It does not fail gx check.
A page listens to a topic key that gx.TopicKey makes. Server code tells the page that the data changed with app.Publish(ctx, key). When the module has no Publish call for a key, no page that listens to it ever runs its action. When the module has no gx.TopicKey call for a key, no page listens to the Publish.
Gx compares only constant keys. A key that the code builds, such as "orders:" + userID, can be each key, so it gives no hint for the other side.
Example
package route
import "github.com/alternayte/gx"
type Fresh struct {
gx.Route `POST /orders/fresh`
}package orders
import "app/orders/route"
props {
Orders gx.Topic
}
<ul id="orders" on:topic(p.Orders)={route.Fresh{}}></ul>package orders
import (
"context"
"github.com/alternayte/gx"
"app/orders/route"
)
func Load(c *gx.Ctx) ListProps {
return ListProps{Orders: gx.TopicKey(c, "orders")}
}
func Done(ctx context.Context, app *gx.App) error {
return app.Publish(ctx, "order")
}
var fresh = gx.Action(func(c *gx.Ctx, in route.Fresh) error {
return nil
})
var Routes = gx.Collect(fresh)gx check reports:
orders/orders.go:11:27: GX4016: hint: the topic key "orders" has no Publish: no code calls app.Publish(ctx, "orders"), so its on:topic never runs
orders/orders.go:15:9: GX4016: hint: app.Publish names the topic key "order", and no gx.TopicKey call makes it: no page listens to itFix
- Give the two calls the same key:
app.Publish(ctx, "orders"). - Keep the key in one constant, and use the constant in the two calls.
- Or keep the code as it is. A hint does not fail the check.