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.
Sebastian Markbage committed
Oct 22, 2016 at 18:35 UTC
2e040fc2c1457deb60f9baabac9307621d4e6c1a
2 files changed
+13
src/renderers/shared/fiber/ReactFiberClassComponent.js
+2
@@ -23,6 +23,7 @@ var {
23
addCallbackToQueue,
24
mergeUpdateQueue,
25
} = require('ReactFiberUpdateQueue');
26
+var { isMounted } = require('ReactFiberTreeReflection');
27
var ReactInstanceMap = require('ReactInstanceMap');
28
29
module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : PriorityLevel) => void) {
@@ -39,6 +40,7 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori
40
41
// Class component state updater
42
const updater = {
43
+ isMounted,
44
enqueueSetState(instance, partialState) {
45
const fiber = ReactInstanceMap.get(instance);
46
const updateQueue = fiber.updateQueue ?
src/renderers/shared/fiber/ReactFiberTreeReflection.js
+11
@@ -23,6 +23,17 @@ var {
23
HostText,
24
} = require('ReactTypeOfWork');
25
26
+exports.isMounted = function(component : ReactComponent<any, any, any>) : boolean {
27
+ var parent : ?Fiber = ReactInstanceMap.get(component);
28
+ if (!parent) {
29
+ return false;
30
+ }
31
+ // TODO: This doesn't deal with the case where it has completed but not yet
32
+ // committed. It also doesn't deal with unmounts since they currently don't
33
+ // clean up the item in the ReactInstanceMap.
34
+ return true;
35
+};
36
+
37
exports.findCurrentHostFiber = function(component : ReactComponent<any, any, any>) : Fiber | null {
38
var parent : ?Fiber = ReactInstanceMap.get(component);
39
if (!parent) {