Some checks failed
CI / build (push) Failing after 36s
WASM reactive UI framework for Go: - reactive/ - Signal[T], Effect, Runtime - ui/ - Button, Text, Input, View, Canvas, SVG components - navigation/ - Router, guards, history management - auth/ - OIDC client for WASM applications - host/ - Static file server Extracted from arcadia as open-source component. Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
740 B
Go
40 lines
740 B
Go
package reactive
|
|
|
|
import "sync"
|
|
|
|
type Runtime struct {
|
|
signalValues []any
|
|
runningEffect *EffectId
|
|
signalSubscribers map[SignalId][]EffectId
|
|
effects []func()
|
|
}
|
|
|
|
var lock = &sync.Mutex{}
|
|
var runtimeInstance *Runtime
|
|
|
|
func GetRuntime() *Runtime {
|
|
if runtimeInstance == nil {
|
|
lock.Lock()
|
|
defer lock.Unlock()
|
|
if runtimeInstance == nil {
|
|
runtimeInstance = newRuntime()
|
|
}
|
|
}
|
|
return runtimeInstance
|
|
}
|
|
|
|
func newRuntime() *Runtime {
|
|
return &Runtime{
|
|
signalValues: []any{},
|
|
signalSubscribers: map[SignalId][]EffectId{},
|
|
effects: []func(){},
|
|
}
|
|
}
|
|
|
|
func runEffect(rt *Runtime, id EffectId) {
|
|
previous := rt.runningEffect
|
|
rt.runningEffect = &id
|
|
rt.effects[id]()
|
|
rt.runningEffect = previous
|
|
}
|