@@ -280,10 +280,10 @@ func (c *Context) SyncSignals() {
|
||||
}
|
||||
updatedSigs := make(map[string]any)
|
||||
|
||||
c.signals.Range(func(idAny, val any) bool {
|
||||
c.signals.Range(func(key, val any) bool {
|
||||
// We know the types.
|
||||
sig, _ := val.(*signal) // adjust *Signal to your actual signal type
|
||||
id, _ := val.(string)
|
||||
id, _ := key.(string)
|
||||
if sig.err != nil {
|
||||
c.app.logWarn(c, "signal out of sync'%s': %v", sig.id, sig.err)
|
||||
}
|
||||
|
||||
22
via_test.go
22
via_test.go
@@ -1,6 +1,7 @@
|
||||
package via
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -84,3 +85,24 @@ func TestConfig(t *testing.T) {
|
||||
v.Config(Options{DocumentTitle: "Test"})
|
||||
assert.Equal(t, "Test", v.cfg.DocumentTitle)
|
||||
}
|
||||
|
||||
func TestSyncSignals(t *testing.T) {
|
||||
var ctx *Context
|
||||
var sig *signal
|
||||
v := New()
|
||||
v.Page("/", func(c *Context) {
|
||||
ctx = c
|
||||
sig = c.Signal("initial")
|
||||
c.View(func() h.H { return h.Div() })
|
||||
})
|
||||
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
v.mux.ServeHTTP(w, req)
|
||||
|
||||
sig.SetValue("updated")
|
||||
ctx.SyncSignals()
|
||||
|
||||
patch := <-ctx.patchChan
|
||||
assert.Equal(t, patch.content, fmt.Sprintf(`{"%s":"updated"}`, sig.ID()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user