-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #100, setState called after unmount on Safari
- Loading branch information
Showing
3 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default class MediaQueryList { | ||
constructor(targetWindow, query, listener) { | ||
const nativeMediaQueryList = targetWindow.matchMedia(query); | ||
this.active = true; | ||
// Safari doesn't clear up listener with removeListener | ||
// when the listener is already waiting in the event queue. | ||
// Having an active flag to make sure the listener is not called | ||
// after we removeListener. | ||
this.cancellableListener = (...args) => this.active && listener(...args); | ||
nativeMediaQueryList.addListener(this.cancellableListener); | ||
} | ||
|
||
cancel() { | ||
this.active = false; | ||
this.nativeMediaQueryList.removeListener(this.cancellableListener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters