Skip to content

Commit a4629ee

Browse files
fix(vanilla): Use self instead of window for webworker compat
Closes #62
1 parent e883afc commit a4629ee

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/vanilla/baseLocationService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const Evt: typeof CustomEvent = getCustomEventCtor();
1616
/** A base `LocationServices` */
1717
export abstract class BaseLocationServices implements LocationServices, Disposable {
1818
constructor(router: UIRouter, public fireAfterUpdate: boolean) {
19-
this._location = window && window.location;
20-
this._history = window && window.history;
19+
this._location = self && self.location;
20+
this._history = self && self.history;
2121
}
2222

2323
_listener = evt => this._listeners.forEach(cb => cb(evt));

src/vanilla/hashLocationService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { BaseLocationServices } from "./baseLocationService";
1111
export class HashLocationService extends BaseLocationServices {
1212
constructor(router: UIRouter) {
1313
super(router, false);
14-
window.addEventListener('hashchange', this._listener, false);
14+
self.addEventListener('hashchange', this._listener, false);
1515
}
1616

1717
_get() {
@@ -23,7 +23,7 @@ export class HashLocationService extends BaseLocationServices {
2323

2424
dispose (router: UIRouter) {
2525
super.dispose(router);
26-
window.removeEventListener('hashchange', this._listener);
26+
self.removeEventListener('hashchange', this._listener);
2727
}
2828
}
2929

src/vanilla/pushStateLocationService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class PushStateLocationService extends BaseLocationServices {
1919
constructor(router: UIRouter) {
2020
super(router, true);
2121
this._config = router.urlService.config;
22-
window.addEventListener("popstate", this._listener, false);
22+
self.addEventListener("popstate", this._listener, false);
2323
};
2424

2525
_get() {
@@ -42,7 +42,7 @@ export class PushStateLocationService extends BaseLocationServices {
4242

4343
dispose(router: UIRouter) {
4444
super.dispose(router);
45-
window.removeEventListener("popstate", this._listener);
45+
self.removeEventListener("popstate", this._listener);
4646
}
4747
}
4848

0 commit comments

Comments
 (0)