package main

import (
	"src/bindings"

	"github.com/vugu/vugu"
)

type Root struct {
	Word string `vugu:"data"`
	Err  error  `vugu:"data"`
	bindings.App
}

func (r *Root) Init(ctx vugu.InitCtx) {
	go func() {
		ctx.EventEnv().Lock()
		defer ctx.EventEnv().UnlockRender()

		for {
			ready, err := r.Ready()
			if err != nil {
				r.Err = err
				break
			}
			if ready {
				r.Word, err = r.Provide()
				if err != nil {
					r.Err = err
				}
				break
			}
		}
	}()
}