chore(): optimize CordovaProperty

closes #954
This commit is contained in:
Ibby 2017-01-10 20:45:11 -05:00
parent 028a568515
commit 67adb23a14

View File

@ -407,9 +407,9 @@ 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: any, key: string) { export function CordovaProperty(target: any, key: string) {
const pluginInstance = getPlugin(target.pluginRef);
const exists = () => { const exists = () => {
let pluginInstance = getPlugin(target.pluginRef); if (!pluginInstance || pluginInstance[key] === 'undefined') {
if (!pluginInstance) {
pluginWarn(target, key); pluginWarn(target, key);
return false; return false;
} }
@ -419,14 +419,14 @@ export function CordovaProperty(target: any, key: string) {
Object.defineProperty(target, key, { Object.defineProperty(target, key, {
get: () => { get: () => {
if (exists()) { if (exists()) {
return getPlugin(target.pluginRef)[key]; return pluginInstance[key];
} else { } else {
return {}; return null;
} }
}, },
set: (value) => { set: (value) => {
if (exists()) { if (exists()) {
getPlugin(target.pluginRef)[key] = value; pluginInstance[key] = value;
} }
} }
}); });