From 2e040fc2c1457deb60f9baabac9307621d4e6c1a Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Sat, 22 Oct 2016 18:35:07 -0700 Subject: [PATCH] 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. --- .../shared/fiber/ReactFiberClassComponent.js | 2 ++ .../shared/fiber/ReactFiberTreeReflection.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/renderers/shared/fiber/ReactFiberClassComponent.js b/src/renderers/shared/fiber/ReactFiberClassComponent.js index 5e5c18f81e..4a8c27308b 100644 --- a/src/renderers/shared/fiber/ReactFiberClassComponent.js +++ b/src/renderers/shared/fiber/ReactFiberClassComponent.js @@ -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 ? diff --git a/src/renderers/shared/fiber/ReactFiberTreeReflection.js b/src/renderers/shared/fiber/ReactFiberTreeReflection.js index 8fddb2fec1..45e2bebb5b 100644 --- a/src/renderers/shared/fiber/ReactFiberTreeReflection.js +++ b/src/renderers/shared/fiber/ReactFiberTreeReflection.js @@ -23,6 +23,17 @@ var { HostText, } = require('ReactTypeOfWork'); +exports.isMounted = function(component : ReactComponent) : 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) : Fiber | null { var parent : ?Fiber = ReactInstanceMap.get(component); if (!parent) {