Skip to content

Commit

Permalink
chore(): optimize CordovaProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Jan 11, 2017
1 parent 028a568 commit 67adb23
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ export function CordovaInstance(opts: any = {}) {
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
export function CordovaProperty(target: any, key: string) {
const pluginInstance = getPlugin(target.pluginRef);
const exists = () => {
let pluginInstance = getPlugin(target.pluginRef);
if (!pluginInstance) {
if (!pluginInstance || pluginInstance[key] === 'undefined') {
pluginWarn(target, key);
return false;
}
Expand All @@ -419,14 +419,14 @@ export function CordovaProperty(target: any, key: string) {
Object.defineProperty(target, key, {
get: () => {
if (exists()) {
return getPlugin(target.pluginRef)[key];
return pluginInstance[key];
} else {
return {};
return null;
}
},
set: (value) => {
if (exists()) {
getPlugin(target.pluginRef)[key] = value;
pluginInstance[key] = value;
}
}
});
Expand Down

0 comments on commit 67adb23

Please sign in to comment.