Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac: DRY up New, reuse *All methods, delete modules slice #1258

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Jan 9, 2025

The pattern we appear to have for Fx operations (Provide, Invoke, etc.)
take the form:

func (*module) thing(t thing)

func (m *module) thingAll() {
    // perform module-local version of operation
    for _, t := range m.things {
        m.thing(t)
    }

    // recurse into children
    for _, m := range m.modules {
        m.${operation}All()
    }
}

This means that the following two are equivalent:

// 1
for _, m := range app.modules {
    m.thingAll()
}

// 2
app.root.thingAll()

Except (2) is DRYer.

This cleans up New by relying on root-level *All methods
instead of manually iterating over modules.

Making this change also highlighted that 'app.modules'
only ever has one entry: the root module.
So we can delete that field from App as well.

Finally, this also renames:

constructAllCustomLoggers -> installAllEventLoggers
constructCustomLogger     -> installEventLogger
executeInvokes            -> invokeAll
executeInvoke             -> invoke

The pattern we appear to have for Fx operations (Provide, Invoke, etc.)
take the form:

    func (*module) thing(t thing)

    func (m *module) thingAll() {
        // perform module-local version of operation
        for _, t := range m.things {
            m.thing(t)
        }

        // recurse into children
        for _, m := range m.modules {
            m.${operation}All()
        }
    }

This means that the following two are equivalent:

    // 1
    for _, m := range app.modules {
        m.thingAll()
    }

    // 2
    app.root.thingAll()

Except (2) is DRYer.

This cleans up New by relying on root-level `*All` methods
instead of manually iterating over modules.

Making this change also highlighted that 'app.modules'
only ever has one entry: the root module.
So we can delete that field from App as well.

Finally, this also renames:

    constructAllCustomLoggers -> installAllEventLoggers
    constructCustomLogger     -> installEventLogger
    executeInvokes            -> invokeAll
    executeInvoke             -> invoke
@abhinav
Copy link
Collaborator Author

abhinav commented Jan 9, 2025

This change is part of the following stack:

Change managed by git-spice.

@abhinav abhinav requested review from JacobOaks and sywhang and removed request for JacobOaks January 9, 2025 03:34
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.62%. Comparing base (928af08) to head (0ce947f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1258   +/-   ##
=======================================
  Coverage   98.62%   98.62%           
=======================================
  Files          35       35           
  Lines        3336     3337    +1     
=======================================
+ Hits         3290     3291    +1     
  Misses         39       39           
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abhinav abhinav mentioned this pull request Jan 9, 2025
5 tasks
@abhinav abhinav merged commit 0ad8a04 into master Jan 9, 2025
19 checks passed
@abhinav abhinav deleted the refac-rename branch January 9, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants