refactor(plugin): refreactor to match tslint rules

This commit is contained in:
Ibby Hadeed 2016-07-18 11:39:53 -04:00
parent 0aee6c88ce
commit 5979e9a8b0

View File

@ -22,8 +22,11 @@ export const getPlugin = function(pluginRef: string): any {
*/ */
export const pluginWarn = function(pluginObj: any, method: string) { export const pluginWarn = function(pluginObj: any, method: string) {
let pluginName = pluginObj.name, plugin = pluginObj.plugin; let pluginName = pluginObj.name, plugin = pluginObj.plugin;
if (method) console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.'); if (method) {
else console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed.'); console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
} else {
console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed.');
}
console.warn('Install the ' + pluginName + ' plugin: \'ionic plugin add ' + plugin + '\''); console.warn('Install the ' + pluginName + ' plugin: \'ionic plugin add ' + plugin + '\'');
}; };
@ -33,8 +36,11 @@ export const pluginWarn = function(pluginObj: any, method: string) {
* @param method * @param method
*/ */
export const cordovaWarn = function(pluginName: string, method: string) { export const cordovaWarn = function(pluginName: string, method: string) {
if (method) console.warn('Native: tried calling ' + pluginName + '.' + method + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'); if (method) {
else console.warn('Native: tried accessing the ' + pluginName + ' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'); console.warn('Native: tried calling ' + pluginName + '.' + method + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
} else {
console.warn('Native: tried accessing the ' + pluginName + ' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
}
}; };
function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Function): any { function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Function): any {
// If the plugin method expects myMethod(success, err, options) // If the plugin method expects myMethod(success, err, options)
@ -169,6 +175,11 @@ function wrapInstance(pluginObj: any, methodName: string, opts: any = {}) {
} }
}; };
}); });
} else if (opts.otherPromise) {
return getPromise((resolve, reject) => {
let result = callInstance(pluginObj, methodName, args, opts, resolve, reject);
result.then(resolve, reject);
});
} else { } else {
return getPromise((resolve, reject) => { return getPromise((resolve, reject) => {
callInstance(pluginObj, methodName, args, opts, resolve, reject); callInstance(pluginObj, methodName, args, opts, resolve, reject);
@ -198,22 +209,18 @@ function wrapEventObservable(event: string): Observable<any> {
*/ */
export const wrap = function(pluginObj: any, methodName: string, opts: any = {}) { export const wrap = function(pluginObj: any, methodName: string, opts: any = {}) {
return (...args) => { return (...args) => {
if (opts.sync) {
if (opts.sync)
// Sync doesn't wrap the plugin with a promise or observable, it returns the result as-is // Sync doesn't wrap the plugin with a promise or observable, it returns the result as-is
return callCordovaPlugin(pluginObj, methodName, args, opts); return callCordovaPlugin(pluginObj, methodName, args, opts);
} else if (opts.observable) {
else if (opts.observable)
return wrapObservable(pluginObj, methodName, args, opts); return wrapObservable(pluginObj, methodName, args, opts);
} else if (opts.eventObservable && opts.event) {
else if (opts.eventObservable && opts.event)
return wrapEventObservable(opts.event); return wrapEventObservable(opts.event);
} else if (opts.otherPromise) {
else if (opts.otherPromise)
return wrapOtherPromise(pluginObj, methodName, args, opts); return wrapOtherPromise(pluginObj, methodName, args, opts);
} else {
else
return wrapPromise(pluginObj, methodName, args, opts); return wrapPromise(pluginObj, methodName, args, opts);
}
}; };
}; };