How does Plugincall handle js-function-args?

I tried to find the usage of PluginCall in ionic-team/capacitor-google-maps

Looking at the code made me more confused.

I tried to find the answer in Method Types | Capacitor Documentation, but I didn’t find any relevant explanation.

Combining the project code and the description of the document, I guess there are several ways to use it:

  1. When the parameters of the js method only have basic data types, just write multiple parameters.

  2. Integrate the basic data types into an object as the first parameter.

  3. Only one callback function is allowed

3.1 When there are other parameters, use object as the first parameter. The callback function is the second parameter;

In java, use call.get to get the value.


What is the correct way to use it?

I don’t know why such a simple rule is not described in the document.

JS function signature rules:

  1. fun(opt:{arg1: number}): Promise<void>
  2. fun(opt:{arg1: number}): Promise<{n:number}>
  3. fun(opt:{arg1: number}, cb: (n:number)=>void): Promise<CallbackID>
  4. fun(): Promise<void>
  5. fun(): Promise<{n:number}>
  6. fun(cb: (n:number)=>void): Promise<void>

Only one callback function is allowed, either with 2 parameters(or only with 1 parameter) or with a return value Promise<{}>

In java, the call.resolve(obj); function will call the callback function


Exists in Method Types | Capacitor Documentation

export interface MyPlugin {
method1(): Promise<void>;
method2(): Promise<MyData>;
method3(callback: MyPluginCallback): Promise<CallbackID>;
}

The rules have been described in a sloppy manner. Anyway, I don’t understand the meaning of this code