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

Support JS promises #14

Open
lemke-ethan opened this issue Dec 16, 2022 · 4 comments
Open

Support JS promises #14

lemke-ethan opened this issue Dec 16, 2022 · 4 comments
Assignees

Comments

@lemke-ethan
Copy link
Collaborator

lemke-ethan commented Dec 16, 2022

It would be cool if you could pass a Promise to createAsyncRenderer instead of the status object. The resolved promise result should be passed to the completed successfully callback.

@lemke-ethan lemke-ethan self-assigned this Oct 20, 2023
@lemke-ethan
Copy link
Collaborator Author

The renderer expects the consumer to manage the long running process and expects the consumer to either re-create the renderer when the process's status changes or change the status in the arguments reference that is passed to the renderer creator function. To pass the ongoing long running process to the renderer creator function pushes the responsibility of managing its status changes to the renderer.

I think this feature can be added to the renderer but I wonder if it makes sense given the current pattern.

@lemke-ethan
Copy link
Collaborator Author

That being said, a cool pattern may be to do something like this in a React + Redux environment:

function MyData(props: { id: number }) {
  const dispatch = useAppDispatch()
  const dataRenderer = createAsyncRenderer(dispatch(asyncThunks.loadData(id)))

  return dataRenderer(data => (<div>{data}</div>))
}

@lemke-ethan
Copy link
Collaborator Author

Actually, that doesn't make sense because you should not dispatch a thunk like that in the render function (🤦‍♂️).

@lemke-ethan
Copy link
Collaborator Author

maybe something like this would make more sense

function MyData(props: { id: number }) {
  const dispatch = useAppDispatch()
  const loadMyData = useCallback(() => dispatch(asyncThunks.loadData(id)), [dispatch])
  const dataRenderer = useCreateAsyncRenderer(loadMyData)

  return dataRenderer(data => (<div>{data}</div>))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant