Sending :ecto_watch
as the first element in message tuples
#21
cheerfulstoic
started this conversation in
Ideas
Replies: 1 comment
-
Just realizing that, of course, structs have keys, so it would need to be something like: def handle_info(%{schema: MyApp.Accounts.User, update_type: :inserted, data: %{id: id}}, socket) do
# or...
def handle_info(%EctoWatch.Event{schema: MyApp.Accounts.User, update_type: :inserted, data: %{id: id}}, socket) do But having keys feels like too much suddenly 😅 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Brought up in #19
The idea being that messages would have
:ecto_watch
as the first element:I'm not necessarily opposed, but I did think about this and avoid it on purpose when creating
ecto_watch
. My thinking was that the library should be taking the place of something that you might have written yourself and just send the basic details about about record insert/update/delete. Since you have to subscribe to the messages and because the PubSub topic isecto_watch
-specific, it seemed fine to do this 🤔Another possibility is to use a struct like:
I often think of structs as just a fancy way of tagging data in the same way that you might do
{:tag, data}
. Since a struct is really just a map with an extra "hidden" keyI also like that because a developer wouldn't be required to match on the struct, they could normally do this:
... but if for some reason it conflicted with other messages that they might send then they could be more specific to look for the struct.
@frerich + anybody else?
Beta Was this translation helpful? Give feedback.
All reactions