GX4015: on:topic has no gx.Topic or no action
The argument of on:topic is not a gx.Topic, its handler is not an action, or one element has two on:topic directives.
Cause
The directive on:topic runs an action when server code publishes a topic key. The key is a server value. A loader makes it with gx.TopicKey and gives it to the component as a prop of type gx.Topic. The page carries a signed token of the key, so a viewer cannot listen to a key that the server did not give it.
Gx reports GX4015 in three cases:
- The argument of
on:topicdoes not have the typegx.Topic. A plain string has no signature. - The handler is not one route literal. Each page runs its own action, with the session of its viewer.
- One element has two
on:topicdirectives. An element listens to one topic.
Example
package route
import "github.com/alternayte/gx"
type Fresh struct {
gx.Route `POST /orders/fresh`
}package orders
import "app/orders/route"
props {
Key string
}
<ul id="orders" on:topic(p.Key)={route.Fresh{}}></ul>package orders
import (
"github.com/alternayte/gx"
"app/orders/route"
)
var fresh = gx.Action(func(c *gx.Ctx, in route.Fresh) error {
return nil
})
var Routes = gx.Collect(fresh)gx check reports:
orders/List.gx:9:26: GX4015: the argument of on:topic is not a gx.Topic: it has the type stringFix
- Change the type of the prop to
gx.Topic:props { Orders gx.Topic }. - In the loader of the page, make the value:
gx.TopicKey(c, "orders:"+userID). - Write the directive with the prop:
on:topic(p.Orders)={route.Fresh{}}. - For a second topic, put the second
on:topicon a child element.