mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
refactor(plugin): refreactor to match tslint rules
This commit is contained in:
parent
0aee6c88ce
commit
5979e9a8b0
@ -22,8 +22,11 @@ export const getPlugin = function(pluginRef: string): any {
|
||||
*/
|
||||
export const pluginWarn = function(pluginObj: any, method: string) {
|
||||
let pluginName = pluginObj.name, plugin = pluginObj.plugin;
|
||||
if (method) 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.');
|
||||
if (method) {
|
||||
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 + '\'');
|
||||
};
|
||||
|
||||
@ -33,8 +36,11 @@ export const pluginWarn = function(pluginObj: any, method: string) {
|
||||
* @param method
|
||||
*/
|
||||
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');
|
||||
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');
|
||||
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');
|
||||
} 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 {
|
||||
// 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 {
|
||||
return getPromise((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 = {}) {
|
||||
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
|
||||
return callCordovaPlugin(pluginObj, methodName, args, opts);
|
||||
|
||||
else if (opts.observable)
|
||||
} else if (opts.observable) {
|
||||
return wrapObservable(pluginObj, methodName, args, opts);
|
||||
|
||||
else if (opts.eventObservable && opts.event)
|
||||
} else if (opts.eventObservable && opts.event) {
|
||||
return wrapEventObservable(opts.event);
|
||||
|
||||
else if (opts.otherPromise)
|
||||
} else if (opts.otherPromise) {
|
||||
return wrapOtherPromise(pluginObj, methodName, args, opts);
|
||||
|
||||
else
|
||||
} else {
|
||||
return wrapPromise(pluginObj, methodName, args, opts);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user