We wrote previously about how much we enjoyed using LiveView with LiveSvelte. Since then, we've open sourced a lot of LiveView/LiveSvelte code. I thought it would be a good time to share the design patterns that have emerged with this stack so far. I'll focus primarily on how we write our forms.
Each Ecto model in our system corresponds (roughly) to a Form module. While that can be a LiveComponent, we'll make that a LiveView where possible.
In mount/3, we setup our initial state. Like most apps, creates happen at /databases while edits happen at /databases/:id. That means we bootstrap initial state based on if the form is for a create or an update:
We always set account_id manually on structs vs via changesets (users should never be able to modify). Hence why we initialize PostgresDatabase with its account_id.
Under the hood, the database form is actually managing two entities, a PostgresDatabase and a PostgresReplicationSlot. So, put_changesets/2 manages two changesets. We just need to switch between changeset functions based on is_edit?: