mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Implement isMounted for Fiber
This is the naive implementation that doesn't cover the case where it has completed but not yet committed. It also doesn't deal with unmounts since they currently don't clean up the item in the ReactInstanceMap.
This commit is contained in:
@@ -23,6 +23,7 @@ var {
|
||||
addCallbackToQueue,
|
||||
mergeUpdateQueue,
|
||||
} = require('ReactFiberUpdateQueue');
|
||||
var { isMounted } = require('ReactFiberTreeReflection');
|
||||
var ReactInstanceMap = require('ReactInstanceMap');
|
||||
|
||||
module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : PriorityLevel) => void) {
|
||||
@@ -39,6 +40,7 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori
|
||||
|
||||
// Class component state updater
|
||||
const updater = {
|
||||
isMounted,
|
||||
enqueueSetState(instance, partialState) {
|
||||
const fiber = ReactInstanceMap.get(instance);
|
||||
const updateQueue = fiber.updateQueue ?
|
||||
|
||||
@@ -23,6 +23,17 @@ var {
|
||||
HostText,
|
||||
} = require('ReactTypeOfWork');
|
||||
|
||||
exports.isMounted = function(component : ReactComponent<any, any, any>) : boolean {
|
||||
var parent : ?Fiber = ReactInstanceMap.get(component);
|
||||
if (!parent) {
|
||||
return false;
|
||||
}
|
||||
// TODO: This doesn't deal with the case where it has completed but not yet
|
||||
// committed. It also doesn't deal with unmounts since they currently don't
|
||||
// clean up the item in the ReactInstanceMap.
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.findCurrentHostFiber = function(component : ReactComponent<any, any, any>) : Fiber | null {
|
||||
var parent : ?Fiber = ReactInstanceMap.get(component);
|
||||
if (!parent) {
|
||||
|
||||
Reference in New Issue
Block a user