q962
1
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:
-
When the parameters of the js method only have basic data types, just write multiple parameters.
-
Integrate the basic data types into an object as the first parameter.
-
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?
q962
2
I don’t know why such a simple rule is not described in the document.
JS function signature rules:
fun(opt:{arg1: number}): Promise<void>
fun(opt:{arg1: number}): Promise<{n:number}>
fun(opt:{arg1: number}, cb: (n:number)=>void): Promise<CallbackID>
fun(): Promise<void>
fun(): Promise<{n:number}>
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