mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-31 18:49:43 +08:00
Update code style
This commit is contained in:
parent
fd87e968f0
commit
b09eb06cb0
@ -1,4 +1,5 @@
|
|||||||
import { callCordovaPlugin, wrapInstance, wrapPromise } from './common';
|
import { callCordovaPlugin, wrapPromise } from './common';
|
||||||
|
|
||||||
declare const window: any;
|
declare const window: any;
|
||||||
|
|
||||||
class MockPlugin {
|
class MockPlugin {
|
||||||
@ -29,11 +30,10 @@ class MockInstancePluginObject {
|
|||||||
|
|
||||||
class MockCordovaPlugin {
|
class MockCordovaPlugin {
|
||||||
static ping = jest.fn((arg: string) => 'pong');
|
static ping = jest.fn((arg: string) => 'pong');
|
||||||
ping = jest.fn((arg: string) => 'pong');
|
|
||||||
|
|
||||||
static pingAsync = jest.fn(
|
static pingAsync = jest.fn(
|
||||||
(arg: string, success: Function, error: Function) => success('pong')
|
(arg: string, success: Function, error: Function) => success('pong')
|
||||||
);
|
);
|
||||||
|
ping = jest.fn((arg: string) => 'pong');
|
||||||
pingAsync = jest.fn((arg: string, success: Function, error: Function) =>
|
pingAsync = jest.fn((arg: string, success: Function, error: Function) =>
|
||||||
success('pong')
|
success('pong')
|
||||||
);
|
);
|
||||||
|
@ -286,7 +286,8 @@ export function setIndex(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const setErrorIndex = () => {
|
const setErrorIndex = () => {
|
||||||
// We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behavior.
|
// We don't want that the reject cb gets spliced into the position of an optional argument that has not been
|
||||||
|
// defined and thus causing non expected behavior.
|
||||||
if (opts.errorIndex > args.length) {
|
if (opts.errorIndex > args.length) {
|
||||||
args[opts.errorIndex] = reject; // insert the reject fn at the correct specific index
|
args[opts.errorIndex] = reject; // insert the reject fn at the correct specific index
|
||||||
} else {
|
} else {
|
||||||
@ -374,12 +375,12 @@ export function pluginWarn(
|
|||||||
if (method) {
|
if (method) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Native: tried calling ' +
|
'Native: tried calling ' +
|
||||||
pluginName +
|
pluginName +
|
||||||
'.' +
|
'.' +
|
||||||
method +
|
method +
|
||||||
', but the ' +
|
', but the ' +
|
||||||
pluginName +
|
pluginName +
|
||||||
' plugin is not installed.'
|
' plugin is not installed.'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
@ -402,16 +403,16 @@ export function cordovaWarn(pluginName: string, method?: string): void {
|
|||||||
if (method) {
|
if (method) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Native: tried calling ' +
|
'Native: tried calling ' +
|
||||||
pluginName +
|
pluginName +
|
||||||
'.' +
|
'.' +
|
||||||
method +
|
method +
|
||||||
', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
|
', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Native: tried accessing the ' +
|
'Native: tried accessing the ' +
|
||||||
pluginName +
|
pluginName +
|
||||||
' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
|
' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,7 +420,7 @@ export function cordovaWarn(pluginName: string, method?: string): void {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export const wrap = function(
|
export const wrap = function (
|
||||||
pluginObj: any,
|
pluginObj: any,
|
||||||
methodName: string,
|
methodName: string,
|
||||||
opts: CordovaOptions = {}
|
opts: CordovaOptions = {}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { checkAvailability, getPlugin } from './common';
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { checkAvailability, getPlugin } from './common';
|
||||||
|
|
||||||
function overrideFunction(pluginObj: any, methodName: string): Observable<any> {
|
function overrideFunction(pluginObj: any, methodName: string): Observable<any> {
|
||||||
return new Observable(observer => {
|
return new Observable(observer => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { CordovaOptions } from './interfaces';
|
|
||||||
import { wrapInstance } from './common';
|
import { wrapInstance } from './common';
|
||||||
|
import { CordovaOptions } from './interfaces';
|
||||||
|
|
||||||
export function cordovaInstance(pluginObj: any, methodName: string, config: CordovaOptions, args: IArguments | Array<any>) {
|
export function cordovaInstance(pluginObj: any, methodName: string, config: CordovaOptions, args: IArguments | Array<any>) {
|
||||||
args = Array.from(args);
|
args = Array.from(args);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { CordovaOptions } from './interfaces';
|
|
||||||
import { wrap } from './common';
|
import { wrap } from './common';
|
||||||
|
import { CordovaOptions } from './interfaces';
|
||||||
|
|
||||||
export function cordova(pluginObj: any, methodName: string, config: CordovaOptions, args: IArguments | Array<any>) {
|
export function cordova(pluginObj: any, methodName: string, config: CordovaOptions, args: IArguments | Array<any>) {
|
||||||
return wrap(pluginObj, methodName, config).apply(this, args);
|
return wrap(pluginObj, methodName, config).apply(this, args);
|
||||||
|
@ -38,7 +38,8 @@ export interface CordovaOptions {
|
|||||||
*/
|
*/
|
||||||
sync?: boolean;
|
sync?: boolean;
|
||||||
/**
|
/**
|
||||||
* Callback order. Set to reverse if the success/error callbacks are the first 2 arguments that the wrapped method takes.
|
* Callback order. Set to reverse if the success/error callbacks are the first 2 arguments that the wrapped method
|
||||||
|
* takes.
|
||||||
*/
|
*/
|
||||||
callbackOrder?: 'reverse';
|
callbackOrder?: 'reverse';
|
||||||
/**
|
/**
|
||||||
@ -70,7 +71,8 @@ export interface CordovaOptions {
|
|||||||
*/
|
*/
|
||||||
clearFunction?: string;
|
clearFunction?: string;
|
||||||
/**
|
/**
|
||||||
* This can be used if clearFunction is set. Set this to true to call the clearFunction with the same arguments used in the initial function.
|
* This can be used if clearFunction is set. Set this to true to call the clearFunction with the same arguments used
|
||||||
|
* in the initial function.
|
||||||
*/
|
*/
|
||||||
clearWithArgs?: boolean;
|
clearWithArgs?: boolean;
|
||||||
/**
|
/**
|
||||||
|
@ -13,8 +13,8 @@ export function initAngular1(plugins: any) {
|
|||||||
const serviceName = '$cordova' + name;
|
const serviceName = '$cordova' + name;
|
||||||
const cls = plugins[name];
|
const cls = plugins[name];
|
||||||
|
|
||||||
(function(serviceName, cls, name) {
|
(function (serviceName, cls, name) {
|
||||||
ngModule.service(serviceName, [function() {
|
ngModule.service(serviceName, [function () {
|
||||||
const funcs = window.angular.copy(cls);
|
const funcs = window.angular.copy(cls);
|
||||||
funcs.__proto__['name'] = name;
|
funcs.__proto__['name'] = name;
|
||||||
return funcs;
|
return funcs;
|
||||||
|
Loading…
Reference in New Issue
Block a user