types API

types

package

API reference for the types package.

T
type

Int

Int is an integer signal.

types/types.go:15-15
type Int state.Signal[int]
T
type

String

String is a string signal.

types/types.go:17-17
type String state.Signal[string]
T
type

Bool

Bool is a boolean signal.

types/types.go:19-19
type Bool state.Signal[bool]
T
type

Float

Float is a float64 signal.

types/types.go:21-21
type Float state.Signal[float64]
T
type

Any

Any is an untyped signal.

types/types.go:23-23
type Any state.Signal[any]
T
type

Store

Store aliases the state store.

types/types.go:25-25
type Store state.Store
T
type

View

View aliases an HTML component.

types/types.go:27-27
type View core.HTMLComponent
T
type

Comp

Comp aliases the component interface.

types/types.go:29-29
type Comp core.Component
S
struct

Slice

Slice is a slice signal.

types/types.go:33-35
type Slice struct
F
function

NewSlice

NewSlice creates a slice signal.

Parameters

v
...[]T

Returns

*Slice[T]
types/types.go:38-44
func NewSlice[T any](v ...[]T) *Slice[T]

{
	var initial []T
	if len(v) > 0 {
		initial = v[0]
	}
	return &Slice[T]{Signal: state.NewSignal(initial)}
}
S
struct

Map

Map is a map signal.

types/types.go:47-49
type Map struct
F
function

NewMap

NewMap creates a map signal.

Parameters

v
...map[K]V

Returns

*Map[K,
V]
types/types.go:52-58
func NewMap[K comparable, V any](v ...map[K]V) *Map[K, V]

{
	var initial map[K]V
	if len(v) > 0 {
		initial = v[0]
	}
	return &Map[K, V]{Signal: state.NewSignal(initial)}
}
S
struct

HInt

HInt is a host-backed integer signal.

types/types.go:61-63
type HInt struct
S
struct

HString

HString is a host-backed string signal.

types/types.go:66-68
type HString struct
S
struct

HBool

HBool is a host-backed boolean signal.

types/types.go:71-73
type HBool struct
S
struct

HFloat

HFloat is a host-backed float signal.

types/types.go:76-78
type HFloat struct
S
struct

HAny

HAny is a host-backed untyped signal.

types/types.go:81-83
type HAny struct
S
struct

HSlice

HSlice is a host-backed slice signal.

types/types.go:86-88
type HSlice struct
S
struct

HMap

HMap is a host-backed map signal.

types/types.go:91-93
type HMap struct
S
struct

Ref

Ref stores a DOM reference.

types/types.go:96-98
type Ref struct

Methods

Set
Method

Set updates the referenced node.

Parameters

func (*Ref) Set(v js.Value)
{ r.node = v }
Get
Method

Get returns the referenced node.

Returns

func (*Ref) Get() js.Value
{ return r.node }
IsNil
Method

IsNil reports whether no node is referenced.

Returns

bool
func (*Ref) IsNil() bool
{ return r.node.IsNull() || r.node.IsUndefined() }

Fields

Name Type Description
node js.Value
F
function

NewRef

NewRef creates an empty DOM reference.

Returns

types/types.go:101-103
func NewRef() *Ref

{
	return &Ref{node: js.Null()}
}
S
struct

Prop

Prop stores a component property.

types/types.go:115-117
type Prop struct

Fields

Name Type Description
value T
F
function

NewProp

NewProp creates a component property.

Parameters

v
T

Returns

*Prop[T]
types/types.go:120-122
func NewProp[T any](v T) *Prop[T]

{
	return &Prop[T]{value: v}
}
F
function

NewInt

NewInt creates an integer signal.

Parameters

v
int

Returns

types/types.go:131-131
func NewInt(v int) *Int

{ return state.NewSignal(v) }
F
function

NewString

NewString creates a string signal.

Parameters

v
string

Returns

types/types.go:134-134
func NewString(v string) *String

{ return state.NewSignal(v) }
F
function

NewBool

NewBool creates a boolean signal.

Parameters

v
bool

Returns

types/types.go:137-137
func NewBool(v bool) *Bool

{ return state.NewSignal(v) }
F
function

NewFloat

NewFloat creates a float signal.

Parameters

v
float64

Returns

types/types.go:140-140
func NewFloat(v float64) *Float

{ return state.NewSignal(v) }
F
function

NewAny

NewAny creates an untyped signal.

Parameters

v
any

Returns

types/types.go:143-143
func NewAny(v any) *Any

{ return state.NewSignal(v) }
S
struct

Inject

Inject marks a dependency injection field.

types/types.go:146-148
type Inject struct

Fields

Name Type Description
Value T
S
struct

History

History records store snapshots for undo and redo.

types/types.go:151-156
type History struct

Methods

Bind
Method

Bind attaches a store to the history.

Parameters

func (*History) Bind(s *state.Store)
{
	h.store = s
}
Undo
Method

Undo restores the previous snapshot.

func (*History) Undo()
{
	if h.store == nil || h.cursor <= 0 {
		return
	}
	h.cursor--
	snap := h.entries[h.cursor]
	for k, v := range snap {
		h.store.Set(k, v)
	}
}
Redo
Method

Redo restores the next snapshot.

func (*History) Redo()
{
	if h.store == nil || h.cursor >= len(h.entries)-1 {
		return
	}
	h.cursor++
	snap := h.entries[h.cursor]
	for k, v := range snap {
		h.store.Set(k, v)
	}
}
Snapshot
Method

Snapshot records the current store state.

func (*History) Snapshot()
{
	if h.store == nil {
		return
	}
	snap := h.store.Snapshot()
	if snap == nil {
		snap = map[string]any{}
	}
	if h.cursor < len(h.entries)-1 {
		h.entries = h.entries[:h.cursor+1]
	}
	h.entries = append(h.entries, snap)
	if len(h.entries) > h.max {
		h.entries = h.entries[len(h.entries)-h.max:]
	}
	h.cursor = len(h.entries) - 1
}
Undo
Method

Undo performs no work outside WASM.

func (*History) Undo()
{}
Redo
Method

Redo performs no work outside WASM.

func (*History) Redo()
{}
Snapshot
Method

Snapshot performs no work outside WASM.

func (*History) Snapshot()
{}

Fields

Name Type Description
store *state.Store
max int
cursor int
entries []map[string]any
F
function

NewHistory

NewHistory creates a bounded store history.

Parameters

limit
int

Returns

types/types.go:159-161
func NewHistory(limit int) *History

{
	return &History{max: limit, entries: make([]map[string]any, 0)}
}
I
interface

Viewer

Viewer exposes a component view.

types/types.go:212-214
type Viewer interface

Methods

View
Method

Returns

*View
func View(...)
S
struct

signalStub

types/types_stub.go:12-19
type signalStub struct

Fields

Name Type Description
value T
onChangeMu sync.Mutex
onChange []func(T)
ch chan T
chCreated bool
S
struct

Subscription

Subscription represents a cancellable listener.

types/types_stub.go:115-118
type Subscription struct

Methods

Stop
Method

Stop removes the listener.

func (*Subscription) Stop()
{ s.once.Do(s.cancel) }

Fields

Name Type Description
cancel func()
once sync.Once
T
type

Int

Int is an integer signal.

types/types_stub.go:125-125
type Int signalStub[int]
T
type

String

String is a string signal.

types/types_stub.go:127-127
type String signalStub[string]
T
type

Bool

Bool is a boolean signal.

types/types_stub.go:129-129
type Bool signalStub[bool]
T
type

Float

Float is a float64 signal.

types/types_stub.go:131-131
type Float signalStub[float64]
T
type

Any

Any is an untyped signal.

types/types_stub.go:133-133
type Any signalStub[any]
T
type

Store

Store aliases the non-WASM store placeholder.

types/types_stub.go:135-135
type Store core.Component
T
type

View

View aliases the non-WASM component view.

types/types_stub.go:137-137
type View core.HTMLComponent
T
type

Comp

Comp aliases the non-WASM component interface.

types/types_stub.go:139-139
type Comp core.Component
S
struct

Slice

Slice is a slice signal.

types/types_stub.go:143-145
type Slice struct
S
struct

Map

Map is a map signal.

types/types_stub.go:148-150
type Map struct
S
struct

HInt

HInt is a host-backed integer signal placeholder.

types/types_stub.go:153-155
type HInt struct
S
struct

HString

HString is a host-backed string signal placeholder.

types/types_stub.go:158-160
type HString struct
S
struct

HBool

HBool is a host-backed boolean signal placeholder.

types/types_stub.go:163-165
type HBool struct
S
struct

HFloat

HFloat is a host-backed float signal placeholder.

types/types_stub.go:168-170
type HFloat struct
S
struct

HAny

HAny is a host-backed untyped signal placeholder.

types/types_stub.go:173-175
type HAny struct
S
struct

HSlice

HSlice is a host-backed slice signal placeholder.

types/types_stub.go:178-180
type HSlice struct
S
struct

HMap

HMap is a host-backed map signal placeholder.

types/types_stub.go:183-185
type HMap struct
S
struct

Ref

Ref is a DOM reference placeholder.

types/types_stub.go:188-188
type Ref struct

Methods

Set
Method

Set updates the referenced node.

Parameters

func (*Ref) Set(v js.Value)
{ r.node = v }
Get
Method

Get returns the referenced node.

Returns

func (*Ref) Get() js.Value
{ return r.node }
IsNil
Method

IsNil reports whether no node is referenced.

Returns

bool
func (*Ref) IsNil() bool
{ return r.node.IsNull() || r.node.IsUndefined() }
S
struct

Prop

Prop stores a component property.

types/types_stub.go:191-193
type Prop struct

Fields

Name Type Description
value T
S
struct

Inject

Inject marks a dependency injection field.

types/types_stub.go:202-204
type Inject struct

Fields

Name Type Description
Value T
S
struct

History

History is a non-WASM history placeholder.

types/types_stub.go:207-209
type History struct

Methods

Bind
Method

Bind attaches a store to the history.

Parameters

func (*History) Bind(s *state.Store)
{
	h.store = s
}
Undo
Method

Undo restores the previous snapshot.

func (*History) Undo()
{
	if h.store == nil || h.cursor <= 0 {
		return
	}
	h.cursor--
	snap := h.entries[h.cursor]
	for k, v := range snap {
		h.store.Set(k, v)
	}
}
Redo
Method

Redo restores the next snapshot.

func (*History) Redo()
{
	if h.store == nil || h.cursor >= len(h.entries)-1 {
		return
	}
	h.cursor++
	snap := h.entries[h.cursor]
	for k, v := range snap {
		h.store.Set(k, v)
	}
}
Snapshot
Method

Snapshot records the current store state.

func (*History) Snapshot()
{
	if h.store == nil {
		return
	}
	snap := h.store.Snapshot()
	if snap == nil {
		snap = map[string]any{}
	}
	if h.cursor < len(h.entries)-1 {
		h.entries = h.entries[:h.cursor+1]
	}
	h.entries = append(h.entries, snap)
	if len(h.entries) > h.max {
		h.entries = h.entries[len(h.entries)-h.max:]
	}
	h.cursor = len(h.entries) - 1
}
Undo
Method

Undo performs no work outside WASM.

func (*History) Undo()
{}
Redo
Method

Redo performs no work outside WASM.

func (*History) Redo()
{}
Snapshot
Method

Snapshot performs no work outside WASM.

func (*History) Snapshot()
{}

Fields

Name Type Description
max int
F
function

NewHistory

NewHistory creates a history placeholder.

Parameters

limit
int

Returns

types/types_stub.go:212-212
func NewHistory(limit int) *History

{ return &History{max: limit} }
F
function

NewInt

NewInt creates an integer signal.

Parameters

v
int

Returns

types/types_stub.go:224-224
func NewInt(v int) *Int

{ return &signalStub[int]{value: v} }
F
function

NewString

NewString creates a string signal.

Parameters

v
string

Returns

types/types_stub.go:227-227
func NewString(v string) *String

{ return &signalStub[string]{value: v} }
F
function

NewBool

NewBool creates a boolean signal.

Parameters

v
bool

Returns

types/types_stub.go:230-230
func NewBool(v bool) *Bool

{ return &signalStub[bool]{value: v} }
F
function

NewFloat

NewFloat creates a float signal.

Parameters

v
float64

Returns

types/types_stub.go:233-233
func NewFloat(v float64) *Float

{ return &signalStub[float64]{value: v} }
F
function

NewAny

NewAny creates an untyped signal.

Parameters

v
any

Returns

types/types_stub.go:236-236
func NewAny(v any) *Any

{ return &signalStub[any]{value: v} }
F
function

NewSlice

NewSlice creates a slice signal.

Parameters

v
...[]T

Returns

*Slice[T]
types/types_stub.go:239-245
func NewSlice[T any](v ...[]T) *Slice[T]

{
	var initial []T
	if len(v) > 0 {
		initial = v[0]
	}
	return &Slice[T]{signalStub: &signalStub[[]T]{value: initial}}
}
F
function

NewMap

NewMap creates a map signal.

Parameters

v
...map[K]V

Returns

*Map[K,
V]
types/types_stub.go:248-254
func NewMap[K comparable, V any](v ...map[K]V) *Map[K, V]

{
	var initial map[K]V
	if len(v) > 0 {
		initial = v[0]
	}
	return &Map[K, V]{signalStub: &signalStub[map[K]V]{value: initial}}
}
F
function

NewRef

NewRef creates a DOM reference placeholder.

Returns

types/types_stub.go:257-257
func NewRef() *Ref

{ return &Ref{} }
F
function

NewProp

NewProp creates a component property.

Parameters

v
T

Returns

*Prop[T]
types/types_stub.go:260-260
func NewProp[T any](v T) *Prop[T]

{ return &Prop[T]{value: v} }
I
interface

Viewer

Viewer exposes a component view.

types/types_stub.go:263-265
type Viewer interface

Methods

View
Method

Returns

*View
func View(...)
F
function

TestTypedSignals

Parameters

types/types_test.go:5-22
func TestTypedSignals(t *testing.T)

{
	count := NewInt(1)
	if count.Get() != 1 || count.Read() != 1 {
		t.Fatalf("unexpected initial int signal value")
	}

	var seen int
	sub := count.OnChange(func(v int) { seen = v })
	count.Set(2)
	if seen != 2 {
		t.Fatalf("expected OnChange value 2, got %d", seen)
	}
	sub.Stop()
	count.Set(3)
	if seen != 2 {
		t.Fatalf("expected stopped subscription to remain 2, got %d", seen)
	}
}
F
function

TestSignalChannelAndHostConversion

Parameters

types/types_test.go:24-39
func TestSignalChannelAndHostConversion(t *testing.T)

{
	count := NewInt(0)
	ch := count.Channel()
	count.SetFromHost(float64(7))
	if count.Get() != 7 {
		t.Fatalf("expected host float64 converted to int 7, got %d", count.Get())
	}
	select {
	case got := <-ch:
		if got != 7 {
			t.Fatalf("expected channel value 7, got %d", got)
		}
	default:
		t.Fatalf("expected channel update")
	}
}
F
function

TestCollectionsPropsAndInject

Parameters

types/types_test.go:41-63
func TestCollectionsPropsAndInject(t *testing.T)

{
	items := NewSlice([]string{"a"})
	items.Set(append(items.Get(), "b"))
	if got := items.Get(); len(got) != 2 || got[1] != "b" {
		t.Fatalf("unexpected slice value: %v", got)
	}

	m := NewMap(map[string]int{"a": 1})
	if m.Get()["a"] != 1 {
		t.Fatalf("unexpected map value: %v", m.Get())
	}

	prop := NewProp("old")
	prop.Set("new")
	if prop.Get() != "new" {
		t.Fatalf("unexpected prop value: %s", prop.Get())
	}

	inject := Inject[int]{Value: 42}
	if inject.Value != 42 {
		t.Fatalf("unexpected inject value: %d", inject.Value)
	}
}