pattern

Server state

Increment on client stays inside the component. Increment on server emits a message to the app, which runs a procedure.

0
8

Page code

// Page
<div class="row">
	<ui.Counter label="Increment on client" />
	<div class="ui-counter">
		<ui.Button label="Increment on server" primary={ true } onclick={ IncrementClicked{} } />
		<strong class="ui-counter-value">{ model.Count }</strong>
	</div>
</div>

// app.gth prelude
type IncrementClicked struct{}

type Procedures interface {
	gothic.RPCService
	Increment(ctx context.Context) (int, error)
}

case IncrementClicked:
	return m, func() gothic.Msg {
		count, err := Increment()
		if err != nil {
			return CountFailed{Message: err.Error()}
		}
		return CountUpdated{Count: count}
	}

// main.go
func (p procedures) Increment(ctx context.Context) (int, error) {
	return p.counter.increment(), nil
}