The right way to use makeFunctionReference
I'd like to create a function reference and store it in a array (while outside of the client), and use a client to consume the references and make the fn calls. what's the best way to do this?
4 Replies
@punn can you say more about this, e.g. do you want to store a bunch of Convex function calls and make them later? like
For many cases the function references you want already exist on the
api
object, but if you don't have that api
object for some reason (say it's a different repo and can't make the server code a dependency) then you need to create function references.Hey @punn , check out the
getFunctionName
and makeFunctionReference
functions in the convex
package. They serialize and deserialize function references to/from strings.Yes that's exactly what I want to do.
I'm defining
api.users.list
in one class and consuming it in another. This results in object is not a functionReference
error. However, if I define api.users.list
in the consumer class, it works fine.
fyi, this works across classes/files and simply listing the objects api.users.list
does not.in one class and consuming it in anotherI imagine there's something more going on: Some serialization, perhaps across page reloads or across the server-client boundary - and this breaks the object reference. As long as you're in the same JS execution context, the references (
api.foo.bla
) should work fine when passed around and stored in memory.