Skip to content

Commit

Permalink
fix(cordova-property): fixes static properties of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Dec 6, 2016
1 parent ea53a19 commit 7ae6e10
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,31 +407,27 @@ export function CordovaInstance(opts: any = {}) {
*
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
export function CordovaProperty(target: Function, key: string) {
let exists: Function = function(): boolean {
if (!window.cordova) {
cordovaWarn(this.name, null);
return false;
}
let pluginInstance = getPlugin(this.pluginRef);
export function CordovaProperty(target: any, key: string) {
const exists = () => {
let pluginInstance = getPlugin(target.pluginRef);
if (!pluginInstance) {
pluginWarn(this, key);
pluginWarn(target, key);
return false;
}
return true;
};

Object.defineProperty(target, key, {
get: function() {
if (exists) {
return this.pluginRef[key];
get: () => {
if (exists()) {
return getPlugin(target.pluginRef)[key];
} else {
return {};
}
},
set: function(value) {
if (exists) {
this.pluginRef[key] = value;
set: (value) => {
if (exists()) {
getPlugin(target.pluginRef)[key] = value;
}
}
});
Expand Down

0 comments on commit 7ae6e10

Please sign in to comment.