mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-02 00:07:23 +08:00
feat(plugin): proxy plugin properties
Rename RequiresPlugin decorator to CordovaProperty and replace getter so we can forward property access to the underlying plugin property.
This commit is contained in:
@@ -170,20 +170,20 @@ export function Cordova(opts:any = {}) {
|
||||
/**
|
||||
* Before calling the original method, ensure Cordova and the plugin are installed.
|
||||
*/
|
||||
export function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>) {
|
||||
let originalMethod = descriptor.value;
|
||||
export function CordovaProperty(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>) {
|
||||
let originalMethod = descriptor.get;
|
||||
|
||||
descriptor.value = function(...args: any[]) {
|
||||
descriptor.get = function(...args: any[]) {
|
||||
// console.log('Calling', this);
|
||||
if(!window.cordova) {
|
||||
cordovaWarn(this.name, null);
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
let pluginInstance = getPlugin(this.pluginRef);
|
||||
if(!pluginInstance) {
|
||||
pluginWarn(this, key);
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
return originalMethod.apply(this, args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user