- Make a component for view logic
- When backend does something, use turbo_stream to re-render the component with new data
- Same thing when broadcasting from a job
Partials just suck with turbo_stream IMO
just cram all the broadcast junk into your view...then you can just refresh it from a job easily
listen for broadcasts in the component when loading
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Really digging this pattern for organizing different 'features' of a model.
Keeps related methods together and makes it easier to find relevant code as the codebase grows. Plus I can separate out test files by feature.
Example: Tasks::DueDate
Tasks originally just had a due_date field. Eventually that grew to also support relative due dates ("10 days from start"). And we wanted a handful of helpers like `due_this_week?` and `overdue?`.
100 lines in a well-name module > 100 lines in the model
We can write a bunch of tests in test/models/tasks/due_date_test that are specific to due date concerns. You don't have to work within a 500+ line mega test.
When navigating the code base, you can fuzzy find "due date" and get see all the context, all in one place