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>
This commit is contained in:
39
reactive/runtime.go
Normal file
39
reactive/runtime.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user