Skip to content

Commit

Permalink
Merge pull request #349 from anyproto/go-3508-decouple-approach2
Browse files Browse the repository at this point in the history
GO-3508 Add dependencies tracing
  • Loading branch information
fat-fellow authored Dec 9, 2024
2 parents 6037687 + badb332 commit 7f969a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
32 changes: 21 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ type ComponentStatable interface {
// App is the central part of the application
// It contains and manages all components
type App struct {
parent *App
components []Component
mu sync.RWMutex
startStat Stat
stopStat Stat
deviceState int
versionName string
anySyncVersion string
parent *App
components []Component
mu sync.RWMutex
startStat Stat
stopStat Stat
deviceState int
versionName string
anySyncVersion string
componentListener func(comp Component)
}

// Name returns app name
Expand Down Expand Up @@ -130,9 +131,10 @@ func VersionDescription() string {
// It doesn't call Start on any of the parent's components
func (app *App) ChildApp() *App {
return &App{
parent: app,
deviceState: app.deviceState,
anySyncVersion: app.AnySyncVersion(),
parent: app,
deviceState: app.deviceState,
anySyncVersion: app.AnySyncVersion(),
componentListener: app.componentListener,
}
}

Expand All @@ -159,6 +161,7 @@ func (app *App) Component(name string) Component {
for current != nil {
for _, s := range current.components {
if s.Name() == name {
app.onComponent(s)
return s
}
}
Expand All @@ -184,6 +187,7 @@ func MustComponent[i any](app *App) i {
for current != nil {
for _, s := range current.components {
if v, ok := s.(i); ok {
app.onComponent(s)
return v
}
}
Expand Down Expand Up @@ -384,3 +388,9 @@ func (app *App) AnySyncVersion() string {
})
return app.anySyncVersion
}

func (app *App) onComponent(s Component) {
if app.componentListener != nil {
app.componentListener(s)
}
}
8 changes: 8 additions & 0 deletions app/apptrace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build appdebug
// +build appdebug

package app

func (app *App) SetOnComponentListener(listener func(comp Component)) {
app.componentListener = listener
}

0 comments on commit 7f969a8

Please sign in to comment.