You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ja...@apache.org on 2019/03/04 14:32:05 UTC

[cordova-plugin-battery-status] branch master updated: feat: update typings (#72)

This is an automated email from the ASF dual-hosted git repository.

janpio pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-battery-status.git


The following commit(s) were added to refs/heads/master by this push:
     new 41d35b7  feat: update typings (#72)
41d35b7 is described below

commit 41d35b743081df52869705f7e665d83b2d50fb6f
Author: Tim Brust <ra...@gmx.de>
AuthorDate: Mon Mar 4 15:31:59 2019 +0100

    feat: update typings (#72)
    
    this is part of https://github.com/apache/cordova/issues/39
    
    <!--
    Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines:
    
    http://cordova.apache.org/contribute/contribute_guidelines.html
    
    Thanks!
    -->
    
    ### Platforms affected
    
    n/a - development with TypeScript
    
    ### Motivation and Context
    <!-- Why is this change required? What problem does it solve? -->
    <!-- If it fixes an open issue, please link to the issue here. -->
    
    updates typings as discussed in apache/cordova#39
    
    
    ### Description
    
    Updates type definition header, simplifies event types and correctly format the TSDoc.
    
    ### Testing
    
    Manual testing via development in VSCode.
    
    ### Checklist
    
    - [ ] I've run the tests to see all new and existing tests pass
    - [ ] I added automated test coverage as appropriate for this change
    - [ ] Commit is prefixed with `(platform)` if this change only applies to one platform (e.g. `(android)`)
    - [ ] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct [keyword to close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/))
    - [ ] I've updated the documentation if necessary
---
 README.md        |   2 +-
 types/index.d.ts | 133 +++++++++++--------------------------------------------
 2 files changed, 28 insertions(+), 107 deletions(-)

diff --git a/README.md b/README.md
index f8f9eda..e534833 100644
--- a/README.md
+++ b/README.md
@@ -108,5 +108,5 @@ Fires when the battery charge percentage reaches the critical charge threshold.
 - Browser (Chrome, Firefox, Opera)
 
 
-[w3c_spec]: http://www.w3.org/TR/2011/WD-battery-status-20110915/
+[w3c_spec]: https://www.w3.org/TR/battery-status/
 [status_object]: #status-object
diff --git a/types/index.d.ts b/types/index.d.ts
index 9baedc8..6612fc8 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -1,10 +1,10 @@
-// Type definitions for Apache Cordova BatteryStatus plugin
+// Type definitions for cordova-plugin-battery-status 2.0
 // Project: https://github.com/apache/cordova-plugin-battery-status
 // Definitions by: Microsoft Open Technologies Inc <http://msopentech.com>
+//                 Tim Brust <https://github.com/timbru31>
 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-// 
-// Copyright (c) Microsoft Open Technologies Inc
-// Licensed under the MIT license. 
+
+type batteryEvent = 'batterystatus' | 'batterycritical' | 'batterylow';
 
 interface Window {
     onbatterystatus: (type: BatteryStatusEvent) => void;
@@ -12,114 +12,35 @@ interface Window {
     onbatterylow: (type: BatteryStatusEvent) => void;
     /**
      * Adds a listener for an event from the BatteryStatus plugin.
-     * @param type      the event to listen for
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param listener  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    addEventListener(type: "batterystatus", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
-    /**
-     * Adds a listener for an event from the BatteryStatus plugin.
-     * @param type      the event to listen for
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param listener  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    addEventListener(type: "batterycritical", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
-    /**
-     * Adds a listener for an event from the BatteryStatus plugin.
-     * @param type      the event to listen for
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param listener  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    addEventListener(type: "batterylow", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
-    /**
-     * Adds a listener for an event from the BatteryStatus plugin.
-     * @param type      the event to listen for
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param listener  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    addEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
+     * @param type       - The event to listen for.
+     * 
+     *                     `batterystatus`: event fires when the percentage of battery charge changes by at least 1 percent, or if the device is plugged in or unplugged.
+     * 
+     *                     `batterycritical`: event fires when the percentage of battery charge has reached the critical battery threshold. The value is device-specific.
+     * 
+     *                     `batterylow`: event fires when the percentage of battery charge has reached the low battery threshold, device-specific value.
+     * @param listener   - The function that executes when the event fires. The function is passed an BatteryStatusEvent object as a parameter.
+     * @param useCapture - A Boolean indicating whether events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
+     */
+    addEventListener(type: batteryEvent, listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
     /**
      * Removes a listener for an event from the BatteryStatus plugin.
-     * @param type      The event to stop listening for.
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param callback  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    removeEventListener(type: "batterystatus", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
-    /**
-     * Removes a listener for an event from the BatteryStatus plugin.
-     * @param type      The event to stop listening for.
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param callback  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    removeEventListener(type: "batterycritical", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
-    /**
-     * Removes a listener for an event from the BatteryStatus plugin.
-     * @param type      The event to stop listening for.
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param callback  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    removeEventListener(type: "batterylow", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
-    /**
-     * Removes a listener for an event from the BatteryStatus plugin.
-     * @param type      The event to stop listening for.
-     *                  batterystatus: event fires when the percentage of battery charge
-     *                  changes by at least 1 percent, or if the device is plugged in or unplugged.
-     *                  batterycritical: event fires when the percentage of battery charge has reached
-     *                  the critical battery threshold. The value is device-specific.
-     *                  batterylow: event fires when the percentage of battery charge has
-     *                  reached the low battery threshold, device-specific value.
-     * @param callback  the function that executes when the event fires. The function is
-     *                  passed an BatteryStatusEvent object as a parameter.
-     */
-    removeEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
+     * @param Atype      - The event to stop listening for.
+     * 
+     *                     `batterystatus`: event fires when the percentage of battery charge changes by at least 1 percent, or if the device is plugged in or unplugged.
+     *                    
+     *                     `batterycritical`: event fires when the percentage of battery charge has reached the critical battery threshold. The value is device-specific.
+     *                    
+     *                     `batterylow`: event fires when the percentage of battery charge has reached the low battery threshold, device-specific value.
+     * @param callback   - The function that executes when the event fires. The function is passed an BatteryStatusEvent object as a parameter.
+     * @param useCapture - A Boolean indicating whether events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
+     */
+    removeEventListener(type: batteryEvent, listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
 }
 
-/** Object, that passed into battery event listener */
 interface BatteryStatusEvent extends Event {
 	/* The percentage of battery charge (0-100). */
     level: number;
 	/* A boolean that indicates whether the device is plugged in. */
     isPlugged: boolean;
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org