feat(core): add methodName to Cordova Decorator (#3558)

closes #3557
This commit is contained in:
Hans Krywalsky 2020-11-19 08:38:39 +01:00 committed by GitHub
parent f71b65d6a7
commit 46853b4212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -168,6 +168,7 @@ A decorator to wrap the main plugin class, and any other classes that will use `
Checks if the plugin and the method are available before executing. By default, the decorator will wrap the callbacks of the function and return a Promise. This decorator takes the following configuration options:
- **observable**: set to true to return an Observable
- **methodName**: an optional name of the cordova plugins method name (if different from wrappers method name)
- **clearFunction**: an optional name of a method to clear the observable we returned
- **clearWithArgs**: This can be used if clearFunction is set. Set this to true to call the clearFunction with the same arguments used in the initial function.
- **sync**: set to true if the method should return the value as-is without wrapping with Observable/Promise

View File

@ -54,7 +54,7 @@ function getMethodBlock(method: ts.MethodDeclaration, decoratorName: string, dec
default:
return ts.createCall(ts.createIdentifier(decoratorMethod), undefined, [
ts.createThis(),
ts.createLiteral((method.name as any).text),
ts.createLiteral(decoratorArgs?.methodName || (method.name as any).text),
convertValueToLiteral(decoratorArgs),
ts.createIdentifier('arguments'),
]);

View File

@ -33,6 +33,11 @@ export interface PluginConfig {
export interface CordovaOptions {
destruct?: boolean;
/**
* If the method-name of the cordova plugin is different from the wrappers one, it can be defined here
*/
methodName?: string;
/**
* Set to true if the wrapped method is a sync function
*/