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

Add example controllers #4550

Merged
merged 16 commits into from
Oct 7, 2024
Merged

Add example controllers #4550

merged 16 commits into from
Oct 7, 2024

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jul 24, 2024

Explanation

This commit adds controllers which are not meant to be published, but instead serve as models to exemplify best practices for writing controllers, fulfilling a long-standing need. The controllers included here are implemented within a complete package which is linted just like other packages, and they ship with working tests which are run just like other tests. This lessens the chance that they will fall out of date in the future.

The two controllers included in this commit are called GasPricesController and PetNamesController, which are roughly based on, but intentionally not drawn from, GasFeeController and AddressBookController. They demonstrate the following best practices:

  • Setting up a common structure for controllers, including creating complete types for the messenger and for state
  • Using the messenger to access data from another controller
  • Using service objects to make HTTP requests
  • Mocking the messenger in tests
  • Creating mock service objects
  • Mocking time in tests

Certainly, more best practices can be demonstrated, but this should be a good first start.

References

Progresses #4504.

Changelog

(No consumer-facing changes in this commit.)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@mcmire mcmire requested a review from a team as a code owner July 24, 2024 04:05
This commit adds controllers which are not meant to be published, but
instead serve as models to exemplify best practices for writing
controllers, fulfilling a long-standing need. The controllers included
here are implemented within a complete package which is linted just like
other packages, and they ship with working tests which are run just like
other tests. This lessens the chance that they will fall out of date in
the future.

The two controllers included in this commit are called
`GasPricesController` and `PetNamesController`, which are roughly based
on, but intentionally not drawn from, `GasFeeController` and
`AddressBookController`. They demonstrate the following best practices:

- Setting up a common structure for controllers, including creating
complete types for the messenger and for state
- Using the messenger to access data from another controller
- Using service objects to make HTTP requests
- Mocking the messenger in tests
- Creating mock service objects
- Mocking time in tests

Certainly, more best practices can be demonstrated, but this should be a
good first start.
@desi desi linked an issue Sep 19, 2024 that may be closed by this pull request
@desi desi requested a review from a team September 26, 2024 19:45
Copy link
Contributor

@MajorLift MajorLift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mikesposito mikesposito merged commit c55c7b4 into main Oct 7, 2024
116 checks passed
@mikesposito mikesposito deleted the add-example-controllers branch October 7, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add guidelines for writing controllers, and add example controller
3 participants