vigor

package module
v0.0.0-...-d107f78 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 1 Imported by: 0

README

vigor

This package is a highly experimental interpretation and implementation of SolidJS tenets in Golang for use in building reactive web interfaces powered by Web Assembly (WASM).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateEffect

func CreateEffect(fn func(), deps ...GetterFn)

CreateEffect calls the given `fn` when any of the given `deps` change.

func CreateSignal

func CreateSignal(value any) (GetterFn, SetterFn)

CreateSignal returns a "getter" and "setter" functions with the given initial value. This implementation is a translation/interpretation of the JavaScript example code from https://www.solidjs.com/guides/reactivity#how-it-works.

func NewFnSubscriber

func NewFnSubscriber() *fnSubscriber

NewFnSubscriber returns a new `Subscriber` implementation that calls the callback passed to `SetFn`. This is useful to easily wrap a Go anonymous function as a `Subscriber`.

Types

type GetterFn

type GetterFn func(...Subscriber) any

GetterFn represents functions which return the current value of a Signal. Passing `Subscriber` implementations to them will call those `Subscriber`s whenever the value of the Signal changes.

func CreateMemo

func CreateMemo(fn func() any, deps ...GetterFn) GetterFn

Memo creates a new Signal that depends on the given deps. This can be used for combining other Signals or caching costly calculations.

func NewDerivedSignal

func NewDerivedSignal(upstream GetterFn, fn func(v any) any) GetterFn

NewDerivedSignal creates a *Derived Signal* which allows you wrap a signal with an expression that is updated when the upstream is. This acts like a Signal but does not store any state.

type Logger

type Logger interface {
	Print(v ...any)
	Fatal(v ...any)
}

Logger abstracts the implementation of loggers,

var Log Logger = &defaultLogger{}

Log defines the logger to use in this library. This is by default a no-op logger to reduce binary size. This may be set to `log.Default()` from the Go stdlib to log out.

type SetterFn

type SetterFn func(any)

SetterFn represents functions which set the current value of a Signal. Calling this triggers any `Subscriber`s for the Signal.

type Subscriber

type Subscriber interface {
	// Run executes the callback.
	Run()
}

Subscriber abstracts the implementation of callbacks which may subscribe to Signal changes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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