forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ReactNative] introduce mountSafeCallback
Summary: `mountSafeCallback` simply wraps a callback in an `isMounted()` check to prevent crashes when old callbacks are called on unmounted components. @public Test Plan: Added logging and made sure callbacks were getting called through `mountSafeCallback` and that things worked (e.g. photo viewer rotation etc).
- Loading branch information
Showing
2 changed files
with
35 additions
and
4 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,23 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule mountSafeCallback | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
var mountSafeCallback = function(context: ReactComponent, callback: ?Function): any { | ||
return function() { | ||
if (!callback || !context.isMounted()) { | ||
return; | ||
} | ||
return callback.apply(context, arguments); | ||
}; | ||
}; | ||
|
||
module.exports = mountSafeCallback; |