Explain why ReactFiber is a POJO instead of constructor
Sebastian Markbage committed
Sep 1, 2016 at 20:56 UTC
cc259a29e35849c0ce056cab1e6a9c9a00faab5a
1 file changed
+13
src/renderers/shared/fiber/ReactFiber.js
+13
@@ -103,6 +103,19 @@ export type Fiber = Instance & {
103
104
};
105
106
+// This is a constructor of a POJO instead of a constructor function for a few
107
+// reasons:
108
+// 1) Nobody should add any instance methods on this. Instance methods can be
109
+// more difficult to predict when they get optimized and they are almost
110
+// never inlined properly in static compilers.
111
+// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
112
+// always know when it is a fiber.
113
+// 3) We can easily go from a createFiber call to calling a constructor if that
114
+// is faster. The opposite is not true.
115
+// 4) We might want to experiment with using numeric keys since they are easier
116
+// to optimize in a non-JIT environment.
117
+// 5) It should be easy to port this to a C struct and keep a C implementation
118
+// compatible.
119
var createFiber = function(tag : TypeOfWork, key : null | string) : Fiber {
120
return {
121