mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-04-25 04:16:09 +08:00
Update DEVELOPER.md
This commit is contained in:
parent
58370afdf0
commit
787a027e3f
18
DEVELOPER.md
18
DEVELOPER.md
@ -15,18 +15,14 @@ Let's take a look at the existing plugin wrapper for Geolocation to see what goe
|
|||||||
export class Geolocation {
|
export class Geolocation {
|
||||||
|
|
||||||
@Cordova()
|
@Cordova()
|
||||||
static getCurrentPosition(options: GeolocationOptions){
|
static getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition> { return }
|
||||||
return new Promise<Geoposition>((res, rej) => {});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cordova({
|
@Cordova({
|
||||||
callbackOrder: 'reverse',
|
callbackOrder: 'reverse',
|
||||||
observable: true,
|
observable: true,
|
||||||
clearFunction: 'clearWatch'
|
clearFunction: 'clearWatch'
|
||||||
})
|
})
|
||||||
static watchPosition(options: GeolocationOptions){
|
static watchPosition(options?: GeolocationOptions): Observable<Geoposition> { return }
|
||||||
return new Observable<Geoposition>(observer => {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -68,11 +64,11 @@ Let's take a look at `getCurrentPosition` first.
|
|||||||
|
|
||||||
```
|
```
|
||||||
@Cordova()
|
@Cordova()
|
||||||
static getCurrentPosition(options: GeolocationOptions){
|
static getCurrentPosition(options: GeolocationOptions): Promise<Geoposition> { return }
|
||||||
return new Promise<Geoposition>((res, rej) => {});
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
It's just a stub. The `return` is only there to keep the TypeScript type-checker from complaining since we indicate the `getCurrentPosition` returns a `Promise<Geoposition>`.
|
||||||
|
|
||||||
By default, the `@Cordova` decorator wraps the plugin callbacks in a Promise that resolves when the success callback is called and rejects when the error callback is called. It also ensures that Cordova and the underlying plugin are available, and prints helpful diagnostics if they aren't.
|
By default, the `@Cordova` decorator wraps the plugin callbacks in a Promise that resolves when the success callback is called and rejects when the error callback is called. It also ensures that Cordova and the underlying plugin are available, and prints helpful diagnostics if they aren't.
|
||||||
|
|
||||||
You'll also notice that it is a static method. That's because the plugin class is just a utility class to call the underlying Cordova plugin methods, it's not an instance and has no state.
|
You'll also notice that it is a static method. That's because the plugin class is just a utility class to call the underlying Cordova plugin methods, it's not an instance and has no state.
|
||||||
@ -85,9 +81,7 @@ Next, let's look at the `watchPosition` method.
|
|||||||
observable: true,
|
observable: true,
|
||||||
clearFunction: 'clearWatch'
|
clearFunction: 'clearWatch'
|
||||||
})
|
})
|
||||||
static watchPosition(options: GeolocationOptions){
|
static watchPosition(options: GeolocationOptions): Observable<Geoposition> { return }
|
||||||
return new Observable<Geoposition>(observer => {});
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `@Cordova` decorator has a few more options now.
|
The `@Cordova` decorator has a few more options now.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user