|
@@ -143,7 +143,7 @@ class Navigator {
|
143
|
143
|
|
144
|
144
|
setOnNavigatorEvent(callback) {
|
145
|
145
|
if (this.navigatorEventHandlers.length > 0) {
|
146
|
|
- throw 'setOnNavigatorEvent can not be used after addOnNavigatorEvent has been called';
|
|
146
|
+ throw new Error('setOnNavigatorEvent can not be used after addOnNavigatorEvent has been called');
|
147
|
147
|
}
|
148
|
148
|
this.navigatorEventHandler = callback;
|
149
|
149
|
this._registerNavigatorEvent();
|
|
@@ -151,12 +151,15 @@ class Navigator {
|
151
|
151
|
|
152
|
152
|
addOnNavigatorEvent(callback) {
|
153
|
153
|
if (this.navigatorEventHandler) {
|
154
|
|
- throw 'addOnNavigatorEvent can not be used after setOnNavigatorEvent has been called';
|
|
154
|
+ throw new Error('addOnNavigatorEvent can not be used after setOnNavigatorEvent has been called');
|
155
|
155
|
}
|
156
|
156
|
if (this.navigatorEventHandlers.indexOf(callback) === -1) {
|
157
|
157
|
this.navigatorEventHandlers.push(callback);
|
158
|
158
|
}
|
159
|
159
|
this._registerNavigatorEvent();
|
|
160
|
+
|
|
161
|
+ return () => this._removeOnNavigatorEvent(callback)
|
|
162
|
+
|
160
|
163
|
}
|
161
|
164
|
|
162
|
165
|
_registerNavigatorEvent() {
|
|
@@ -167,7 +170,7 @@ class Navigator {
|
167
|
170
|
}
|
168
|
171
|
}
|
169
|
172
|
|
170
|
|
- removeOnNavigatorEvent(callback) {
|
|
173
|
+ _removeOnNavigatorEvent(callback) {
|
171
|
174
|
const index = this.navigatorEventHandlers.indexOf(callback);
|
172
|
175
|
if (index !== -1) {
|
173
|
176
|
this.navigatorEventHandlers.splice(index, 1);
|