feat: refactor maplibre for reactive signals and Via-native API
- Export Signal type (signal → Signal) so subpackages can reference it - Expose viewport signals as public fields (CenterLng, CenterLat, Zoom, Bearing, Pitch) for .Text() display and .Bind() usage - Add signal-backed marker positions (LngSignal/LatSignal) with data-effect reactivity for server push and dragend writeback - Add event system (MapEvent, OnClick, OnLayerClick, OnMouseMove, OnContextMenu) using hidden inputs + action triggers - Add Source interface replacing type-switch, with RawSource escape hatch - Add CameraOptions for FlyTo/EaseTo/JumpTo/FitBounds/Stop - Add Control interface with NavigationControl, ScaleControl, GeolocateControl, FullscreenControl - Expand Options with interaction toggles, MaxBounds, and Extra map - Add effectspike example to validate data-effect with server-pushed signals - Update maplibre example to showcase all new features
This commit is contained in:
26
signal.go
26
signal.go
@@ -9,27 +9,27 @@ import (
|
||||
)
|
||||
|
||||
// Signal represents a value that is reactive in the browser. Signals
|
||||
// are synct with the server right before an action triggers.
|
||||
// are synced with the server right before an action triggers.
|
||||
//
|
||||
// Use Bind() to connect a signal to an input and Text() to display it
|
||||
// reactively on an html element.
|
||||
type signal struct {
|
||||
type Signal struct {
|
||||
id string
|
||||
val any
|
||||
changed bool
|
||||
err error
|
||||
}
|
||||
|
||||
// ID returns the signal ID
|
||||
func (s *signal) ID() string {
|
||||
// ID returns the signal ID.
|
||||
func (s *Signal) ID() string {
|
||||
return s.id
|
||||
}
|
||||
|
||||
// Err returns a signal error or nil if it contains no error.
|
||||
//
|
||||
// It is useful to check for errors after updating signals with
|
||||
// dinamic values.
|
||||
func (s *signal) Err() error {
|
||||
// dynamic values.
|
||||
func (s *Signal) Err() error {
|
||||
return s.err
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (s *signal) Err() error {
|
||||
// Example:
|
||||
//
|
||||
// h.Input(h.Type("number"), mysignal.Bind())
|
||||
func (s *signal) Bind() h.H {
|
||||
func (s *Signal) Bind() h.H {
|
||||
return h.Data("bind", s.id)
|
||||
}
|
||||
|
||||
@@ -48,33 +48,33 @@ func (s *signal) Bind() h.H {
|
||||
// Example:
|
||||
//
|
||||
// h.Div(mysignal.Text())
|
||||
func (s *signal) Text() h.H {
|
||||
func (s *Signal) Text() h.H {
|
||||
return h.Span(h.Data("text", "$"+s.id))
|
||||
}
|
||||
|
||||
// SetValue updates the signal’s value and marks it for synchronization with the browser.
|
||||
// The change will be propagated to the browser using *Context.Sync() or *Context.SyncSignals().
|
||||
func (s *signal) SetValue(v any) {
|
||||
func (s *Signal) SetValue(v any) {
|
||||
s.val = v
|
||||
s.changed = true
|
||||
s.err = nil
|
||||
}
|
||||
|
||||
// String return the signal value as a string.
|
||||
func (s *signal) String() string {
|
||||
// String returns the signal value as a string.
|
||||
func (s *Signal) String() string {
|
||||
return fmt.Sprintf("%v", s.val)
|
||||
}
|
||||
|
||||
// Bool tries to read the signal value as a bool.
|
||||
// Returns the value or false on failure.
|
||||
func (s *signal) Bool() bool {
|
||||
func (s *Signal) Bool() bool {
|
||||
val := strings.ToLower(s.String())
|
||||
return val == "true" || val == "1" || val == "yes" || val == "on"
|
||||
}
|
||||
|
||||
// Int tries to read the signal value as an int.
|
||||
// Returns the value or 0 on failure.
|
||||
func (s *signal) Int() int {
|
||||
func (s *Signal) Int() int {
|
||||
if n, err := strconv.Atoi(s.String()); err == nil {
|
||||
return n
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user