From 787a027e3fb72cb4780bdb83e5e4eaaae0a9e236 Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Thu, 10 Mar 2016 19:29:05 -0600 Subject: [PATCH] Update DEVELOPER.md --- DEVELOPER.md | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 9aede5f9e..b96e5ad91 100644 --- a/DEVELOPER.md +++ b/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 { @Cordova() - static getCurrentPosition(options: GeolocationOptions){ - return new Promise((res, rej) => {}); - } + static getCurrentPosition(options?: GeolocationOptions): Promise { return } @Cordova({ callbackOrder: 'reverse', observable: true, clearFunction: 'clearWatch' }) - static watchPosition(options: GeolocationOptions){ - return new Observable(observer => {}); - } + static watchPosition(options?: GeolocationOptions): Observable { return } } ``` @@ -68,11 +64,11 @@ Let's take a look at `getCurrentPosition` first. ``` @Cordova() - static getCurrentPosition(options: GeolocationOptions){ - return new Promise((res, rej) => {}); - } + static getCurrentPosition(options: GeolocationOptions): Promise { return } ``` +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`. + 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. @@ -85,9 +81,7 @@ Next, let's look at the `watchPosition` method. observable: true, clearFunction: 'clearWatch' }) - static watchPosition(options: GeolocationOptions){ - return new Observable(observer => {}); - } + static watchPosition(options: GeolocationOptions): Observable { return } ``` The `@Cordova` decorator has a few more options now. @@ -100,4 +94,4 @@ The `@Cordova` decorator has a few more options now. ### 'Wrapping' Up -That's it! The only thing left to do is rigorously document the plugin and it's usage. Take a look at some of the other plugins for good documentation styles. \ No newline at end of file +That's it! The only thing left to do is rigorously document the plugin and it's usage. Take a look at some of the other plugins for good documentation styles.