How to use result of server method within client side collection hook?

I’m trying to set up some server and client side before.insert and before.update hooks using matb33:collection-hooks and I need the document to be enhanced with the result of a server side method.

I cannot do it purely on the client due to lack of certain libraries on the client.

I cannot do it purely on the server because I need the result immediately without which the UI flickers and jumps around too much.

The problem is, the server side method being called asynchronously on the client thus leaving me with undefined.

Is there a clean way to run a blocking function that I can use within a client side before.insert / before.update hook to get some result from the server?

1 Like

No, you cannot block on the client.

Just as info: An alternative to collection hooks is to write a Meteor method for inserting and updating.

1 Like

Yep! But I must block on the client somehow :frowning: I’m kind of thinking ajax
and rest now but even the thought of it hurts!

Also this is for a package so I kind of need it to act like a hook to be
transparent. It has to be configurable per collection and not gorce the app
developer to use my way of things.

Do you even need a client side hook? When you just have the server hook, the document update is sent to the client anyway.

Maybe you can have approximation on you client that doesn’t require a server call (if that would improve the UX). Or just a placeholder value or a spinner.

I actually do need the client hook because the package enhances the doc
with some metadata that is otherwise (not even approximately) impossible to
calculate on the client and that metadata is crucial to how and where the
data is displayed.

If I do a server side only hook, the doc flickers and even jumps around in
the page because it is related to some custom sorting. A spinner (or
hiding the doc) is also not viable :frowning:

But thanks, those were very sound suggestions.