fix(cordova-property): fixes static properties of classes

This commit is contained in:
Ibby 2016-12-06 07:32:45 -05:00 committed by Ibrahim Hadeed
parent ea53a1923a
commit 7ae6e10375

View File

@ -407,31 +407,27 @@ export function CordovaInstance(opts: any = {}) {
* *
* Before calling the original method, ensure Cordova and the plugin are installed. * Before calling the original method, ensure Cordova and the plugin are installed.
*/ */
export function CordovaProperty(target: Function, key: string) { export function CordovaProperty(target: any, key: string) {
let exists: Function = function(): boolean { const exists = () => {
if (!window.cordova) { let pluginInstance = getPlugin(target.pluginRef);
cordovaWarn(this.name, null);
return false;
}
let pluginInstance = getPlugin(this.pluginRef);
if (!pluginInstance) { if (!pluginInstance) {
pluginWarn(this, key); pluginWarn(target, key);
return false; return false;
} }
return true; return true;
}; };
Object.defineProperty(target, key, { Object.defineProperty(target, key, {
get: function() { get: () => {
if (exists) { if (exists()) {
return this.pluginRef[key]; return getPlugin(target.pluginRef)[key];
} else { } else {
return {}; return {};
} }
}, },
set: function(value) { set: (value) => {
if (exists) { if (exists()) {
this.pluginRef[key] = value; getPlugin(target.pluginRef)[key] = value;
} }
} }
}); });