goFE

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR = iota
	WARNING
	INFO
	DEBUG
)

Variables

View Source
var ErrCouldNotGetWebsocket = errors.New("could not get websocket")

Functions

func Init

func Init(loggerInit *Logger)

func RenderChildren

func RenderChildren(component Component) string

func SetDocument

func SetDocument(doc *Document)

func UpdateComponentArray

func UpdateComponentArray[T Component, Props any](input *[]T, newLen int, newT func(props *Props) T, newProps []*Props)

UpdateComponentArray provides functionality to control a variable-length collection of components, such as a list of rows in a table, or any other collection of sub-components (children).

Types

type Component

type Component interface {
	Render() string
	GetID() uuid.UUID
	GetChildren() []Component
	InitEventListeners()
}

type Document

type Document struct {
	// contains filtered or unexported fields
}

func GetDocument

func GetDocument() *Document

func NewDocument

func NewDocument(componentTree []Component) *Document

func (*Document) AddEventListener

func (d *Document) AddEventListener(id uuid.UUID, event string, callback js.Func)

func (*Document) Append

func (d *Document) Append(component Component)

func (*Document) GetComponentTree

func (d *Document) GetComponentTree() []Component

func (*Document) Init

func (d *Document) Init()

type Logger added in v0.1.2

type Logger struct {
	Level int
}

Logger in the goFE package is a simple logger that uses println instead of fmt for a small wasm binary size. The level is hierarchical, with the highest level being the most verbose.

func (*Logger) Log added in v0.1.2

func (l *Logger) Log(level int, message string)

type State

type State[T any] struct {
	Value *T
	// contains filtered or unexported fields
}

State is a generic struct that holds a value and a channel

func NewState

func NewState[T any](component Component, value *T) (*State[T], func(*T))

NewState creates a new instance of frontend state. It returns a pointer to the new state, with initial value, and a function to set the state.

func (*State[T]) AddEffect

func (s *State[T]) AddEffect(effect func(value *T))

AddEffect adds an effect to the state. An effect is a function that is called whenever the state changes.

type Websocket added in v0.1.3

type Websocket struct {
	// contains filtered or unexported fields
}

func NewWebsocket added in v0.1.3

func NewWebsocket(url string) (*Websocket, error)

func (*Websocket) Close added in v0.1.3

func (w *Websocket) Close() error

func (*Websocket) MessageChan added in v0.1.3

func (w *Websocket) MessageChan() chan []byte

func (*Websocket) Open added in v0.1.3

func (w *Websocket) Open()

func (*Websocket) Send added in v0.1.3

func (w *Websocket) Send(data interface{})

func (*Websocket) Write added in v0.1.3

func (w *Websocket) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL