Skip to content

Commit

Permalink
feat(google-maps): update plugin and fix a few issues (danielsogl#1834)
Browse files Browse the repository at this point in the history
* Update index.ts

* Update index.ts

* Add missing features, and bug fix of methods

* update: classname must be in pascal case

* remove: duplicated class definition

* export encode and spherical static classes

* Add comma

* Fix Encoding and Spherical

* Add convenience methods

* Fix decorators for Encoding and Spherical

* Update: getMap() methods return the instance of the wrapper plugin

* Update: getMap() methods return the instance of the wrapper plugin

* Remove `@CordovaInstance` decorators from getMap()

* Update: GoogleMapOptions (all fields are not optional).

* Follow up:  version `2.0.0-beta2-20170719-2226` of cordova-plugin-googlemaps

* Fix: tslint error

* Fix: tslint error

* No more isAvailable() method.

* Bug fix: description is incorrect

* Bug fix: example code was wrong.

* Bug fix: HtmlInfoWindow does not work
danielsogl#1815 (comment)

* Bug fix: HtmlInfoWindow does not work

* Bug fix: HtmlInfoWindow does not work

* Bug fix: HtmlInfoWindow does not work

* Bug fix: HtmlInfoWindow does not work

* It seems the ionViewDidLoad() is enough delayed after platform.ready()

* Bug fix: map.setDiv()

* Bug fix: HtmlInfoWindow does not work

* Bug fix: BaseArrayClass definition is incorrect

* Bug fix: BaseArrayClass constructor is wrong

* Bug fix: Geocoder class does not work

* Bug fix: LatLngBounds constructor is wrong

* update: noNotify option is not declared

* Bug fix: Geocoder.geocode() returns array of GeocoderResult

* Update: clarify acceptable parameters of BaseArrayClass

* Add: AnimateCameraOption.padding is missing

* Revert: BaseClass.empty() method does not have the noNotify option

* Add `destruct` option to the CordovaOption.

- This allows BaseClass.on() is able to pass multiple retuned values from the cordova plugin side to the event lister.

* A semicolon is mixing

* update: event names

* Update: BaseClass.addEventListener(), addEventListenerOnce(), on(), and one()

* Add: destruct option for otherPromise
Change: inside event names (must use the version 2.0.0-beta3-20170808-1950 or higher)

* Build for working group

* Bug fix: map.getCameraTarget() definition is incorrect

* Bug fix: The definition of VisibleRegion interface is incorrect

* Fix: LatLng, LatLngBounds, and PolylineOptions classes
Update: map.getVisibleRegion()

Add: VisibleRegion class

* Bug fix: the definition of map.clear() method is incorrect

* Fix: map.fromLatLngToPoint()

* Ignore the dist directory on the master branch

* Remove the dist folder on the master branch

* fixes and tweaks

* use union types for CameraPosition

fixes issue mentioned on slack by @wf9a5m75

* fix types

* update AnimateCameraOptions interface

* remove AnimateCameraOptions interface

* add MarkerCluster class
  • Loading branch information
wf9a5m75 authored and Buddy Reno committed Aug 28, 2017
1 parent 3db00a5 commit d17bb3e
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 297 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ node_modules/
.idea
.tmp
aot/
dist/
scripts/ionic-native-bower
dist/
40 changes: 39 additions & 1 deletion src/@ionic-native/core/decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'core-js';
import { Plugin, Cordova, CordovaProperty, CordovaCheck, CordovaInstance, InstanceProperty } from './decorators';
import { IonicNativePlugin } from './ionic-native-plugin';
import { ERR_CORDOVA_NOT_AVAILABLE, ERR_PLUGIN_NOT_INSTALLED } from './plugin';
import { Observable } from 'rxjs/Observable';

declare const window: any;

Expand Down Expand Up @@ -47,6 +48,17 @@ class TestPlugin extends IonicNativePlugin {
return new TestObject(TestPlugin.getPlugin().create());
}

@Cordova({
destruct: true
})
destructPromise(): Promise<any> { return; }

@Cordova({
destruct: true,
observable: true
})
destructObservable(): Observable<any> { return; }

}

function definePlugin() {
Expand All @@ -59,7 +71,9 @@ function definePlugin() {
this.ping = (success: Function, error: Function) => success('pong');
this.name = 'John Smith';
return this;
}
},
destructPromise: (success: Function) => success('hello', 'world'),
destructObservable: (success: Function) => success('hello', 'world')
};
}

Expand Down Expand Up @@ -177,6 +191,30 @@ describe('Regular Decorators', () => {

});

describe('CordovaOptions', () => {

describe('destruct', () => {

it('should destruct values returned by a Promise', (done) => {
plugin.destructPromise()
.then((args: any[]) => {
expect(args).toEqual(['hello', 'world']);
done();
});
});

it('should destruct values returned by an Observable', (done) => {
plugin.destructObservable()
.subscribe((args: any[]) => {
expect(args).toEqual(['hello', 'world']);
done();
});
});

});

});

});

describe('Instance Decorators', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/@ionic-native/core/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface PluginConfig {
}

export interface CordovaOptions {
destruct?: boolean;
/**
* Set to true if the wrapped method is a sync function
*/
Expand Down Expand Up @@ -252,7 +253,7 @@ export function Cordova(opts: CordovaOptions = {}) {
*
* Wrap an instance method
*/
export function CordovaInstance(opts: any = {}) {
export function CordovaInstance(opts: CordovaOptions = {}) {
return (target: Object, methodName: string) => {
return {
value: function(...args: any[]) {
Expand Down
50 changes: 44 additions & 6 deletions src/@ionic-native/core/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ function callCordovaPlugin(pluginObj: any, methodName: string, args: any[], opts
function wrapPromise(pluginObj: any, methodName: string, args: any[], opts: any = {}) {
let pluginResult: any, rej: Function;
const p = getPromise((resolve: Function, reject: Function) => {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject);
if (opts.destruct) {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, (...args: any[]) => resolve(args), (...args: any[]) => reject(args));
} else {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject);
}
rej = reject;
});
// Angular throws an error on unhandled rejection, but in this case we have already printed
Expand Down Expand Up @@ -166,7 +170,14 @@ function wrapOtherPromise(pluginObj: any, methodName: string, args: any[], opts:

function wrapObservable(pluginObj: any, methodName: string, args: any[], opts: any = {}) {
return new Observable(observer => {
let pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, observer.next.bind(observer), observer.error.bind(observer));
let pluginResult;

if (opts.destruct) {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, (...args: any[]) => observer.next(args), (...args: any[]) => observer.error(args));
} else {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, observer.next.bind(observer), observer.error.bind(observer));
}

if (pluginResult && pluginResult.error) {
observer.error(pluginResult.error);
observer.complete();
Expand Down Expand Up @@ -266,7 +277,14 @@ export function wrapInstance(pluginObj: any, methodName: string, opts: any = {})
} else if (opts.observable) {

return new Observable(observer => {
let pluginResult = callInstance(pluginObj, methodName, args, opts, observer.next.bind(observer), observer.error.bind(observer));

let pluginResult;

if (opts.destruct) {
pluginResult = callInstance(pluginObj, methodName, args, opts, (...args: any[]) => observer.next(args), (...args: any[]) => observer.error(args));
} else {
pluginResult = callInstance(pluginObj, methodName, args, opts, observer.next.bind(observer), observer.error.bind(observer));
}

if (pluginResult && pluginResult.error) {
observer.error(pluginResult.error);
Expand All @@ -287,9 +305,13 @@ export function wrapInstance(pluginObj: any, methodName: string, opts: any = {})
});

} else if (opts.otherPromise) {

return getPromise((resolve: Function, reject: Function) => {
let result = callInstance(pluginObj, methodName, args, opts, resolve, reject);
let result;
if (opts.destruct) {
result = callInstance(pluginObj, methodName, args, opts, (...args: any[]) => resolve(args), (...args: any[]) => reject(args));
} else {
result = callInstance(pluginObj, methodName, args, opts, resolve, reject);
}
if (result && !!result.then) {
result.then(resolve, reject);
} else {
Expand All @@ -298,8 +320,24 @@ export function wrapInstance(pluginObj: any, methodName: string, opts: any = {})
});

} else {
let pluginResult: any, rej: Function;
const p = getPromise((resolve: Function, reject: Function) => {
if (opts.destruct) {
pluginResult = callInstance(pluginObj, methodName, args, opts, (...args: any[]) => resolve(args), (...args: any[]) => reject(args));
} else {
pluginResult = callInstance(pluginObj, methodName, args, opts, resolve, reject);
}
rej = reject;
});
// Angular throws an error on unhandled rejection, but in this case we have already printed
// a warning that Cordova is undefined or the plugin is uninstalled, so there is no reason
// to error
if (pluginResult && pluginResult.error) {
p.catch(() => { });
typeof rej === 'function' && rej(pluginResult.error);
}
return p;

return getPromise((resolve: Function, reject: Function) => callInstance(pluginObj, methodName, args, opts, resolve, reject));

}
};
Expand Down
Loading

0 comments on commit d17bb3e

Please sign in to comment.