-
Notifications
You must be signed in to change notification settings - Fork 0
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
Comments
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. |
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>))
} |
Actually, that doesn't make sense because you should not dispatch a thunk like that in the render function (🤦♂️). |
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>))
} |
It would be cool if you could pass a
Promise
tocreateAsyncRenderer
instead of the status object. The resolved promise result should be passed to the completed successfully callback.The text was updated successfully, but these errors were encountered: