Skip to content

Commit 5e26fea

Browse files
authored
Create generic concept for GmailBindAction to allow extension (#700)
* Add generic for listener * better typing * fix return type * update other methods
1 parent 1deedba commit 5e26fea

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/gmail.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ interface DomObserverConfig {
780780
handler?: Function;
781781
}
782782

783-
interface GmailObserve {
783+
interface GmailObserve<T extends string=never> {
784784
/**
785785
After an observer has been bound through gmail.observe.bind() (via a
786786
call to events gmail.observe.before(), gmail.observe.on(), or
@@ -821,31 +821,31 @@ interface GmailObserve {
821821
Your callback will be fired directly after Gmail's XMLHttpRequest
822822
has been sent off the the Gmail servers.
823823
*/
824-
on(action: GmailBindAction, callback: Function, response_callback?: Function): void;
824+
on(action: GmailBindAction | T, callback: Function, response_callback?: Function): void;
825825
/**
826826
an before event is observed just prior to the gmail xhr request being sent
827827
before events have the ability to modify the xhr request before it is sent
828828
*/
829-
before(action: GmailBindAction, callback: Function): void;
829+
before(action: GmailBindAction | T, callback: Function): void;
830830
/**
831831
an after event is observed when the gmail xhr request returns from the server
832832
with the server response
833833
*/
834834
after(action: "send_message", callback: (url: string, body: string, data: any, response: any, xhr: XMLHttpRequest) => void): void;
835835
after(action: "http_event", callback: (request: HttpEventRequestParams, responseData: any, xhr: XMLHttpRequest) => void): void;
836-
after(action: GmailBindAction, callback: Function): void;
836+
after(action: GmailBindAction | T, callback: Function): void;
837837
/**
838838
Checks if a specified action & type has anything bound to it
839839
If type is null, will check for this action bound on any type
840840
If action is null, will check for any actions bound to a type
841841
*/
842-
bound(action: GmailBindAction, type: GmailBindType): boolean;
842+
bound(action: GmailBindAction | T, type: GmailBindType): boolean;
843843
/**
844844
Clear all callbacks for a specific type (before, on, after, dom) and action
845845
If action is null, all actions will be cleared
846846
If type is null, all types will be cleared
847847
*/
848-
off(action: GmailBindAction, type: GmailBindType): void;
848+
off(action: GmailBindAction | T, type: GmailBindType): void;
849849
/**
850850
Trigger any specified events bound to the passed type
851851
Returns true or false depending if any events were fired
@@ -873,7 +873,7 @@ interface GmailObserve {
873873
trigger the related event and fire off any relevant bound callbacks
874874
This function should return true if a dom observer is found for the specified action
875875
*/
876-
on_dom(action: GmailBindAction, callback: Function): void;
876+
on_dom(action: GmailBindAction | T, callback: Function): boolean;
877877
}
878878

879879

@@ -1030,7 +1030,7 @@ interface GmailCache {
10301030
//
10311031
////////////////////////////////////////////////////////////////////////////////
10321032

1033-
declare class Gmail {
1033+
declare class Gmail<T extends string=never> {
10341034
constructor(localJQuery?: JQueryStatic);
10351035

10361036
version: string;
@@ -1050,7 +1050,7 @@ declare class Gmail {
10501050
use. See source for input params
10511051
*/
10521052
tools: GmailTools;
1053-
observe: GmailObserve;
1053+
observe: GmailObserve<T>;
10541054
helper: GmailHelper;
10551055
chat: GmailChat;
10561056
compose: GmailCompose;

src/gmail.js

+2
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,7 @@ var Gmail = function(localJQuery) {
27132713
else if(action === "compose_cancelled") {
27142714
//console.log("set compose cancelled callback");
27152715
api.tracker.composeCancelledCallback = callback;
2716+
return true;
27162717
}
27172718
else if(action === "load") {
27182719

@@ -2740,6 +2741,7 @@ var Gmail = function(localJQuery) {
27402741
}, delay);
27412742
return true;
27422743
}
2744+
return false;
27432745
};
27442746

27452747
// observes every element inserted into the DOM by Gmail and looks at the classes on those elements,

0 commit comments

Comments
 (0)