Closed gsouf closed 8 years ago
You are right, this way of providing callbacks is not supported. But you can provide the callback as a separate argument, like this:
var data = { foo: 'foo' };
var callback = function() { ... };
application.remote.test(data, callback);
In this case the callback is preserved and can be invoked from the other side.
But if an argument is not a function, but an object, it is serialized, and all the functions are thrown away.
Would it work for you, if you provide the callback as a separate argument? Or do you think that the callbacks should be extracted from the objects for some reason?
Thank for your attention,
I could put the callback in the function arguments, but there are several events I have to deal with, that means some callbacks that can be possiblely passed to the function. And that can grows as the application grows and the function signature would become very complex. The second easy way would be to use an object returned by the function, with some callback setter, but as you state in the doc, remote function dont return anything.
I probably can workarround it, but that would be awesome if I could use functions as config values in an object !
Do you think that can be safely supported by jailed ?
Do you think that can be safely supported by jailed ?
This sounds like possible, but far too complex and over-designed. Currently I have a feeling that your case can be solved in a clean way using the existing capabilities of jailed. Then I would maybe update the docs somehow to explain such a case.
Returned values are ignored due to the fact that exported methods are invoked asynchronously. But you can give a callback which will process the result as an argument, this should be pretty similar, as long as you need to pass the data as a result.
Next there are two more options:
Would it work?
Well, that will make things more complex to write and to use but I can deal with it! Once documented that would be ok.
Thank you!
When I put a callback in a config object, it got deleted from the object.
Example:
When I jail this script:
It outputs
[Function]
it's okNow with this file
It outputs
{ foo: 'foo' }
bar is not exported