[Thali-talk] Confusing over the Cordova variable

Yaron Goland yarong at microsoft.com
Wed Jun 24 20:42:17 EDT 2015


Note: This is to the public alias

Sreejumon asked me a question I thought was worth explaining to the general gathered. The question was - what is this about a Cordova variable in JXCore?

To understand what's going on you have to understand the way JXCore and Cordova work together. This is the architecture:


Cordova Webview <----->Cordova Bridge <----->Cordova Native Plugin
                                                             <-- -->JXCore Plugin for Cordova<-- -->JXCore<-- -->JXCore Native Plugin

So JXCore wrote an API that you can call in the webview. It looks like jxcore('myFunction').call(some, args, callback);
Inside of JXCore you then write something like cordova('myFunction').registerAsync(function (some, args, callback) {});
So the idea is that when the code in the webview calls jxcore('myFunction').call(some, args, callback) this will cause some, args and the callback to be marshalled and sent over (as a string) the Cordova Bridge to the JXCore Plugin for Cordova who will then manifest it inside of JXCore where it will call the function that was registered with cordova('myFunction').registerAsync.
Now this is all pretty straight forward and makes sense, at least to me.
What happens next is what we were talking about.
Because let's say that what you want to do is make a call between JXCore and a JXCore Native Plugin? In that case the way you do it is that in JXCore you call cordova('myNativeFunction').callNative(more, args, callback);
What happens next really depends on what language the native plugin is written in but, for example, with Java on Android there is a file called JXcoreExtension.java and inside of it you will see calls like:
jxcore.RegisterMethod("myNativeFunction", new JXcoreCallback() {
   @Override
   Public void Receiver(ArrayList<Object> params, String callbackId) {
      ...
  }
});
So this is all well and good but it does cause a problem.
Why is callNative on the cordova object?
Look up... see callNative? See how it's defined on the cordova object?
Why?!?!?!
The answer is.... Because. In truth callNative has nothing to do with Cordova. Nada. Zip. Nichevo. Rien.
And this confused folks because it makes it look like you have to use cordova in order to make calls between JXCore and a JXCore native plugin. But of course, that is not true.
So at some point JXCore is going to fix this and move callNative to a different object so everyone isn't so confused.
            Thanks,
                        Yaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist10.pair.net/pipermail/thali-talk/attachments/20150625/51f52684/attachment.html>


More information about the Thali-talk mailing list