brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
812 stars 102 forks source link

feat: :art: allow onSuccess and onError callbacks on useAssetManager tasks #211

Closed dennemark closed 2 years ago

dennemark commented 2 years ago

related to https://github.com/brianzinn/react-babylonjs/issues/129

allows to assign onError and onSuccess callbacks to tasks via useAssetManager( [ { taskType [...] onSuccess: (task) => { console.log(task.isCompleted) } } ] )

brianzinn commented 2 years ago

Thanks @dennemark . I have not seen that syntax for typings before onSuccess?: MeshAssetTask['onSuccess'] instead of onSuccess?: (task: TextureAssetTask) => void - does that match the call signature over? I suppose I can look in the typings declaration, but curious what that is called or maybe I just need a coffee! 😄

dennemark commented 2 years ago

I forgot the onError callback... added it now. 🙄

onSuccess?: MeshAssetTask['onSuccess'] is the same as onSuccess?: (task: TextureAssetTask) => void It just takes the type of the original function, so it would also adapt to changes. Typescript seems to handle Types a bit similar to objects in this sense, but MeshAssetTask.onSuccess does not work as far as I know. I thought its more convenient than figuring out, the exact function of the original MeshAssetTask :D

brianzinn commented 2 years ago

Thanks @dennemark - I haven't dropped a NPM in a while - still working on the docs. Let me know if you need this out in the wild!

dennemark commented 2 years ago

@brianzinn no rush. Managed to work around it for the current project. But am looking forward to the new version. Synchronising with bjs5 release? ;)

brianzinn commented 2 years ago

That for sure, but redoing the docs. I need to get busy as v5 is imminent... I've already run 5.0 migrations though - actually 5.0 should work on current version - I pushed a bunch of backwards compatibility changes, so it was working at one point in alpha builds at least - then it broke in the betas and then it was working again!! Hope it stays working :) Also, some stuff will work properly in v5 such as gizmos, etc.