MCPcopy Create free account
hub / github.com/NV404/gova / getOrCreateState

Function getOrCreateState

scope.go:147–158  ·  view source on GitHub ↗

getOrCreateState retrieves existing state by key, or creates it with the initial value.

(s *Scope, key string, initial T)

Source from the content-addressed store, hash-verified

145
146// getOrCreateState retrieves existing state by key, or creates it with the initial value.
147func getOrCreateState[T any](s *Scope, key string, initial T) *StateValue[T] {
148 s.mu.Lock()
149 defer s.mu.Unlock()
150
151 if existing, ok := s.states[key]; ok {
152 return existing.(*StateValue[T])
153 }
154
155 st := newState(initial, s.onStateChange)
156 s.states[key] = st
157 return st
158}
159
160// getOrCreateRef retrieves existing ref by key, or creates it with the initial value.
161func getOrCreateRef[T any](s *Scope, key string, initial T) *RefValue[T] {

Callers 15

StateFunction · 0.85
StateKeyFunction · 0.85
TestStateGetSetFunction · 0.85
TestFormatSignalFunction · 0.85
TestDerivedSignalFunction · 0.85
TestTextFieldViewNodeFunction · 0.85
TestListCreatesChildrenFunction · 0.85
TestDerivedListFunction · 0.85
TestFormViewNodeFunction · 0.85

Calls 1

newStateFunction · 0.85

Tested by 15

TestStateGetSetFunction · 0.68
TestFormatSignalFunction · 0.68
TestDerivedSignalFunction · 0.68
TestTextFieldViewNodeFunction · 0.68
TestListCreatesChildrenFunction · 0.68
TestDerivedListFunction · 0.68
TestFormViewNodeFunction · 0.68
TestNavigationPushPopFunction · 0.68