refactoring

This commit is contained in:
Max Lynch
2015-11-29 19:54:45 -06:00
parent 9d54bfcd0b
commit dfef6dcfe8
42 changed files with 719 additions and 185 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
export declare class ActionSheet {
static show: any;
static hide: any;
static show(options: any): void;
static hide(options: any): void;
}
+12 -12
View File
@@ -10,18 +10,18 @@ var plugin_1 = require('./plugin');
var ActionSheet = (function () {
function ActionSheet() {
}
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], ActionSheet, "show");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], ActionSheet, "hide");
ActionSheet.show = function (options) { };
;
ActionSheet.hide = function (options) { };
;
Object.defineProperty(ActionSheet, "show",
__decorate([
plugin_1.Cordova()
], ActionSheet, "show", Object.getOwnPropertyDescriptor(ActionSheet, "show")));
Object.defineProperty(ActionSheet, "hide",
__decorate([
plugin_1.Cordova()
], ActionSheet, "hide", Object.getOwnPropertyDescriptor(ActionSheet, "hide")));
ActionSheet = __decorate([
plugin_1.Plugin({
name: 'ActionSheet',
+7
View File
@@ -0,0 +1,7 @@
export declare class BLE {
static scan(services: any[], seconds: number): void;
static startScan: any;
static stopScan: any;
static connect: any;
static disconnect: any;
}
+55
View File
@@ -0,0 +1,55 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var BLE = (function () {
function BLE() {
}
BLE.scan = function (services, seconds) { };
Object.defineProperty(BLE, "scan",
__decorate([
plugin_1.Cordova({
successIndex: 2,
errIndex: 3
})
], BLE, "scan", Object.getOwnPropertyDescriptor(BLE, "scan")));
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], BLE, "startScan");
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], BLE, "stopScan");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], BLE, "connect");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], BLE, "disconnect");
BLE = __decorate([
plugin_1.Plugin({
name: 'BluetoothLowEnergy',
plugin: 'cordova-plugin-ble-central',
pluginRef: 'ble',
pluginRepo: 'https://github.com/don/cordova-plugin-ble-central'
})
], BLE);
return BLE;
})();
exports.BLE = BLE;
+2 -2
View File
@@ -1,4 +1,4 @@
export declare class Camera {
static getPicture: any;
static cleanup: any;
static getPicture(options: any): void;
static cleanup(): void;
}
+15 -12
View File
@@ -10,18 +10,21 @@ var plugin_1 = require('./plugin');
var Camera = (function () {
function Camera() {
}
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Camera, "getPicture");
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Camera, "cleanup");
Camera.getPicture = function (options) { };
;
Camera.cleanup = function () { };
;
Object.defineProperty(Camera, "getPicture",
__decorate([
plugin_1.Cordova({
// Not sure why this plugin has the success/err come first...
callbackOrder: 'reverse'
})
], Camera, "getPicture", Object.getOwnPropertyDescriptor(Camera, "getPicture")));
Object.defineProperty(Camera, "cleanup",
__decorate([
plugin_1.Cordova()
], Camera, "cleanup", Object.getOwnPropertyDescriptor(Camera, "cleanup")));
Camera = __decorate([
plugin_1.Plugin({
name: 'Camera',
+2
View File
@@ -0,0 +1,2 @@
export declare class File {
}
+22
View File
@@ -0,0 +1,22 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var File = (function () {
function File() {
}
File = __decorate([
plugin_1.Plugin({
name: 'File',
plugin: 'cordova-plugin-file',
pluginRef: 'cordova.file'
})
], File);
return File;
})();
exports.File = File;
+3
View File
@@ -0,0 +1,3 @@
export declare class Device {
static getCurrentPosition: any;
}
+25
View File
@@ -0,0 +1,25 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var Device = (function () {
function Device() {
}
__decorate([
plugin_1.Cordova()
], Device, "getCurrentPosition");
Device = __decorate([
plugin_1.Plugin({
name: 'Geolocation',
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation'
})
], Device);
return Device;
})();
exports.Device = Device;
+13 -1
View File
@@ -3,6 +3,18 @@ export declare const isInstalled: (pluginRef: string) => boolean;
export declare const pluginWarn: (pluginName: string, method: string, plugin: string) => void;
export declare const cordovaWarn: (pluginName: string, method: string) => void;
export declare const wrap: (pluginObj: any, methodName: any, opts?: any) => (...args: any[]) => any;
/**
* Class decorator specifying Plugin metadata. Required for all plugins.
*/
export declare function Plugin(config: any): (cls: any) => any;
export declare function Cordova(opts?: any): (obj: any, methodName: any) => void;
/**
* Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
* and the required plugin are installed.
*/
export declare function Cordova(opts?: any): (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
value: (...args: any[]) => any;
};
/**
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
export declare function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any>;
+36 -8
View File
@@ -38,12 +38,24 @@ exports.wrap = function (pluginObj, methodName, opts) {
});
return;
}
if (typeof opts.successIndex !== 'undefined') {
args[opts.successIndex] = resolve;
// Try to figure out where the success/error callbacks need to be bound
// to our promise resolve/reject handlers.
// If the plugin method expects myMethod(success, err, options)
if (opts.callbackOrder == 'reverse') {
args[0] = resolve;
args[1] = reject;
}
if (typeof opts.errorIndex !== 'undefined') {
else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
// If we've specified a success/error index
args[opts.successIndex] = resolve;
args[opts.errorIndex] = reject;
}
else {
// Otherwise, let's tack them on to the end of the argument list
// which is 90% of cases
args.push(resolve);
args.push(reject);
}
var pluginInstance = exports.getPlugin(pluginObj.pluginRef);
if (!pluginInstance) {
exports.pluginWarn(pluginObj.name, methodName, pluginObj.name);
@@ -56,6 +68,9 @@ exports.wrap = function (pluginObj, methodName, opts) {
});
};
};
/**
* Class decorator specifying Plugin metadata. Required for all plugins.
*/
function Plugin(config) {
return function (cls) {
// Add these fields to the class
@@ -66,16 +81,29 @@ function Plugin(config) {
};
}
exports.Plugin = Plugin;
/**
* Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
* and the required plugin are installed.
*/
function Cordova(opts) {
if (opts === void 0) { opts = {}; }
return function (obj, methodName) {
if (opts.promise) {
console.log('TODO: Promise');
}
obj[methodName] = exports.wrap(obj, methodName, opts).bind(obj);
return function (target, methodName, descriptor) {
var originalMethod = descriptor.value;
return {
value: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return exports.wrap(this, methodName, opts)();
}
};
};
}
exports.Cordova = Cordova;
/**
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
function RequiresPlugin(target, key, descriptor) {
var originalMethod = descriptor.value;
descriptor.value = function () {
+9 -9
View File
@@ -1,11 +1,11 @@
export declare class StatusBar {
static overlaysWebView: any;
static styleDefault: any;
static styleLightContent: any;
static styleBlackTranslucent: any;
static styleBlackOpaque: any;
static backgroundColorByName: any;
static backgroundColorByHexString: any;
static hide: any;
static show: any;
static overlaysWebView(doOverlay: boolean): void;
static styleDefault(): void;
static styleLightContent(): void;
static styleBlackTranslucent(): void;
static styleBlackOpaque(): void;
static backgroundColorByName(colorName: string): void;
static backgroundColorByHexString(hexString: string): void;
static hide(): void;
static show(): void;
}
+54 -27
View File
@@ -10,33 +10,60 @@ var plugin_1 = require('./plugin');
var StatusBar = (function () {
function StatusBar() {
}
__decorate([
plugin_1.Cordova()
], StatusBar, "overlaysWebView");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleDefault");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleLightContent");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackTranslucent");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackOpaque");
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByName");
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByHexString");
__decorate([
plugin_1.Cordova()
], StatusBar, "hide");
__decorate([
plugin_1.Cordova()
], StatusBar, "show");
StatusBar.overlaysWebView = function (doOverlay) { };
;
StatusBar.styleDefault = function () { };
;
StatusBar.styleLightContent = function () { };
;
StatusBar.styleBlackTranslucent = function () { };
;
StatusBar.styleBlackOpaque = function () { };
;
StatusBar.backgroundColorByName = function (colorName) { };
;
StatusBar.backgroundColorByHexString = function (hexString) { };
;
StatusBar.hide = function () { };
;
StatusBar.show = function () { };
;
Object.defineProperty(StatusBar, "overlaysWebView",
__decorate([
plugin_1.Cordova()
], StatusBar, "overlaysWebView", Object.getOwnPropertyDescriptor(StatusBar, "overlaysWebView")));
Object.defineProperty(StatusBar, "styleDefault",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleDefault", Object.getOwnPropertyDescriptor(StatusBar, "styleDefault")));
Object.defineProperty(StatusBar, "styleLightContent",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleLightContent", Object.getOwnPropertyDescriptor(StatusBar, "styleLightContent")));
Object.defineProperty(StatusBar, "styleBlackTranslucent",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackTranslucent", Object.getOwnPropertyDescriptor(StatusBar, "styleBlackTranslucent")));
Object.defineProperty(StatusBar, "styleBlackOpaque",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackOpaque", Object.getOwnPropertyDescriptor(StatusBar, "styleBlackOpaque")));
Object.defineProperty(StatusBar, "backgroundColorByName",
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByName", Object.getOwnPropertyDescriptor(StatusBar, "backgroundColorByName")));
Object.defineProperty(StatusBar, "backgroundColorByHexString",
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByHexString", Object.getOwnPropertyDescriptor(StatusBar, "backgroundColorByHexString")));
Object.defineProperty(StatusBar, "hide",
__decorate([
plugin_1.Cordova()
], StatusBar, "hide", Object.getOwnPropertyDescriptor(StatusBar, "hide")));
Object.defineProperty(StatusBar, "show",
__decorate([
plugin_1.Cordova()
], StatusBar, "show", Object.getOwnPropertyDescriptor(StatusBar, "show")));
StatusBar = __decorate([
plugin_1.Plugin({
name: 'StatusBar',
+2 -2
View File
@@ -1,4 +1,4 @@
export declare class Toast {
static hide: any;
static showWithOptions: any;
static hide(): void;
static showWithOptions(options: any): void;
}
+18 -12
View File
@@ -10,18 +10,24 @@ var plugin_1 = require('./plugin');
var Toast = (function () {
function Toast() {
}
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Toast, "hide");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], Toast, "showWithOptions");
Toast.hide = function () { };
;
Toast.showWithOptions = function (options) { };
;
Object.defineProperty(Toast, "hide",
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Toast, "hide", Object.getOwnPropertyDescriptor(Toast, "hide")));
Object.defineProperty(Toast, "showWithOptions",
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], Toast, "showWithOptions", Object.getOwnPropertyDescriptor(Toast, "showWithOptions")));
Toast = __decorate([
plugin_1.Plugin({
name: 'Toast',