ash_phoenix icon indicating copy to clipboard operation
ash_phoenix copied to clipboard

`keep_live` access callback result in `subscribe`

Open xanderio opened this issue 1 year ago • 1 comments

Describe the bug

When setting up a keep_live it's currently impossible to access the callback result for setting up any subscriptions.

To Reproduce A minimal set of resource definitions and calls that can reproduce the bug.

socket
|> keep_live(
  :merge_request,
  fn socket ->
    Nxy.Workspace.MergeRequest.get_by_id!(params["id"])
  end,
  subscribe: [
    "merge_request:updated:#{socket.assigns.merge_request.project_id}" # <-- unable to access the project_id here
  ]
)

Expected behavior

subscription should could be a callback that get's the result of the previous callback.

xanderio avatar Dec 15 '23 14:12 xanderio

Makes sense to add this, but I won't have time to do it for quite some time. What we ought to do is call the callback on returned data, and store what we subscribed to. Then, as data updates, we should call the callback again and unsubscribe from any that are not present in the list, and subscribe to anything new. Would this be something you're interested in putting together a PR for? Happy to provide guidance if so.

zachdaniel avatar Dec 15 '23 14:12 zachdaniel