UNPKG

5.64 kBTypeScriptView Raw
1declare namespace google.maps {
2 namespace event {
3 /**
4 * Cross browser event handler registration. This listener is removed by
5 * calling removeListener(handle) for the handle that is returned by this
6 * function.
7 */
8 function addDomListener(
9 instance: object,
10 eventName: string,
11 handler: (event: Event) => void,
12 capture?: boolean,
13 ): MapsEventListener;
14
15 /**
16 * Wrapper around addDomListener that removes the listener after the first
17 * event.
18 */
19 function addDomListenerOnce(
20 instance: object,
21 eventName: string,
22 handler: (event: Event) => void,
23 capture?: boolean,
24 ): MapsEventListener;
25
26 /**
27 * Adds the given listener function to the given event name for the given
28 * object instance. Returns an identifier for this listener that can be used
29 * with removeListener().
30 */
31 function addListener(instance: object, eventName: string, handler: (...args: any[]) => void): MapsEventListener;
32
33 /**
34 * Like addListener, but the handler removes itself after handling the first
35 * event.
36 */
37 function addListenerOnce(
38 instance: object,
39 eventName: string,
40 handler: (...args: any[]) => void,
41 ): MapsEventListener;
42
43 /**
44 * Removes all listeners for all events for the given instance.
45 */
46 function clearInstanceListeners(instance: object): void;
47
48 /**
49 * Removes all listeners for the given event for the given instance.
50 */
51 function clearListeners(instance: object, eventName: string): void;
52
53 /**
54 * Removes the given listener, which should have been returned by
55 * addListener above. Equivalent to calling listener.remove().
56 */
57 function removeListener(listener: MapsEventListener): void;
58
59 /**
60 * Triggers the given event. All arguments after eventName are passed as
61 * arguments to the listeners.
62 */
63 function trigger(instance: any, eventName: string, ...args: any[]): void;
64 }
65
66 interface MapsEventListener {
67 /**
68 * Removes the listener. Equivalent to calling
69 * google.maps.event.removeListener(listener).
70 */
71 remove(): void;
72 }
73
74 type MVCEventHandler<T extends MVCObject, A extends any[]> = (this: T, ...args: A) => void;
75
76 class MVCObject {
77 /**
78 * The MVCObject constructor is guaranteed to be an empty function, and so
79 * you may inherit from MVCObject by simply writing MySubclass.prototype =
80 * new google.maps.MVCObject();. Unless otherwise noted, this is not true of
81 * other classes in the API, and inheriting from other classes in the API is
82 * not supported.
83 */
84 constructor();
85
86 /**
87 * Adds the given listener function to the given event name. Returns an
88 * identifier for this listener that can be used with
89 * google.maps.event.removeListener.
90 */
91 addListener(eventName: string, handler: MVCEventHandler<this, any[]>): MapsEventListener;
92
93 /** Binds a View to a Model. */
94 bindTo(key: string, target: MVCObject, targetKey?: string, noNotify?: boolean): void;
95
96 changed(key: string): void;
97
98 /** Gets a value. */
99 get(key: string): any;
100
101 /**
102 * Notify all observers of a change on this property. This notifies both
103 * objects that are bound to the object's property as well as the object
104 * that it is bound to.
105 */
106 notify(key: string): void;
107
108 /** Sets a value. */
109 set(key: string, value: any): void;
110
111 /** Sets a collection of key-value pairs. */
112 setValues(values: any): void;
113
114 /**
115 * Removes a binding. Unbinding will set the unbound property to the current
116 * value. The object will not be notified, as the value has not changed.
117 */
118 unbind(key: string): void;
119
120 /** Removes all bindings. */
121 unbindAll(): void;
122 }
123
124 /** This class extends MVCObject. */
125 class MVCArray<T> extends MVCObject {
126 /** A mutable MVC Array. */
127 constructor(array?: T[]);
128
129 /** Removes all elements from the array. */
130 clear(): void;
131
132 /**
133 * Iterate over each element, calling the provided callback.
134 * The callback is called for each element like: callback(element, index).
135 */
136 forEach(callback: (elem: T, i: number) => void): void;
137
138 /**
139 * Returns a reference to the underlying Array.
140 * Warning: if the Array is mutated, no events will be fired by this object.
141 */
142 getArray(): T[];
143
144 /** Returns the element at the specified index. */
145 getAt(i: number): T;
146
147 /** Returns the number of elements in this array. */
148 getLength(): number;
149
150 /** Inserts an element at the specified index. */
151 insertAt(i: number, elem: T): void;
152
153 /** Removes the last element of the array and returns that element. */
154 pop(): T;
155
156 /**
157 * Adds one element to the end of the array and returns the new length of
158 * the array.
159 */
160 push(elem: T): number;
161
162 /** Removes an element from the specified index. */
163 removeAt(i: number): T;
164
165 /** Sets an element at the specified index. */
166 setAt(i: number, elem: T): void;
167 }
168}