@@ -280,10 +280,10 @@ func (c *Context) SyncSignals() {
|
|||||||
}
|
}
|
||||||
updatedSigs := make(map[string]any)
|
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.
|
// We know the types.
|
||||||
sig, _ := val.(*signal) // adjust *Signal to your actual signal type
|
sig, _ := val.(*signal) // adjust *Signal to your actual signal type
|
||||||
id, _ := val.(string)
|
id, _ := key.(string)
|
||||||
if sig.err != nil {
|
if sig.err != nil {
|
||||||
c.app.logWarn(c, "signal out of sync'%s': %v", sig.id, sig.err)
|
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
|
package via
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -84,3 +85,24 @@ func TestConfig(t *testing.T) {
|
|||||||
v.Config(Options{DocumentTitle: "Test"})
|
v.Config(Options{DocumentTitle: "Test"})
|
||||||
assert.Equal(t, "Test", v.cfg.DocumentTitle)
|
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