(ctx context.Context, atomName string)
| 358 | } |
| 359 | |
| 360 | func UseAtom[T any](ctx context.Context, atomName string) (T, func(T)) { |
| 361 | vc, hookVal := getHookFromCtx(ctx) |
| 362 | if !hookVal.Init { |
| 363 | hookVal.Init = true |
| 364 | closedWaveId := vc.Comp.WaveId |
| 365 | hookVal.UnmountFn = func() { |
| 366 | atom := vc.Root.GetAtom(atomName) |
| 367 | delete(atom.UsedBy, closedWaveId) |
| 368 | } |
| 369 | } |
| 370 | atom := vc.Root.GetAtom(atomName) |
| 371 | atom.UsedBy[vc.Comp.WaveId] = true |
| 372 | atomVal, ok := atom.Val.(T) |
| 373 | if !ok { |
| 374 | panic(fmt.Sprintf("UseAtom %q value type mismatch (expected %T, got %T)", atomName, atomVal, atom.Val)) |
| 375 | } |
| 376 | setVal := func(newVal T) { |
| 377 | atom.Val = newVal |
| 378 | for waveId := range atom.UsedBy { |
| 379 | vc.Root.AddRenderWork(waveId) |
| 380 | } |
| 381 | } |
| 382 | return atomVal, setVal |
| 383 | } |
| 384 | |
| 385 | func UseVDomRef(ctx context.Context) *VDomRef { |
| 386 | vc, hookVal := getHookFromCtx(ctx) |
nothing calls this directly
no test coverage detected