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:
Sebastian Markbage
2016-10-22 18:35:07 -07:00
parent 298d0c3e05
commit 2e040fc2c1
2 changed files with 13 additions and 0 deletions
@@ -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) {