From 67adb23a145c8ec615e59e43d420ca7327905b75 Mon Sep 17 00:00:00 2001 From: Ibby Date: Tue, 10 Jan 2017 20:45:11 -0500 Subject: [PATCH] chore(): optimize CordovaProperty closes #954 --- src/plugins/plugin.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index 9aeee810c..48ed726f7 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -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; } @@ -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; } } });