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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add example controllers #4550

wants to merge 11 commits into from

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

2 participants