GithubHelp home page GithubHelp logo

use callback in object about jailed HOT 4 CLOSED

gsouf avatar gsouf commented on August 24, 2024
use callback in object

from jailed.

Comments (4)

asvd avatar asvd commented on August 24, 2024

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?

from jailed.

gsouf avatar gsouf commented on August 24, 2024

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 ?

from jailed.

asvd avatar asvd commented on August 24, 2024

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:

  • Instead of invoking the given callback, you can provide a string identifier for an event happened, and handle it respectively on the other side;
  • You can export all possible event type handlers during the initialization, so that instead of invoking the provided callback, application would invoke the respective method exported from the plugin side.

Would it work?

from jailed.

gsouf avatar gsouf commented on August 24, 2024

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!

from jailed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.