mirror of
https://github.com/status-im/react-native.git
synced 2025-02-15 10:57:00 +00:00
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).
24 lines
638 B
JavaScript
24 lines
638 B
JavaScript
/**
|
|
* 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;
|