Skip to content

Commit 7916de2

Browse files
authored
Update 04-how-setstate-works-part-2.md
1 parent 1267eba commit 7916de2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

04-how-setstate-works-part-2.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ Here we just call `this.setState()` with new value. Let's search `setState` and
2323

2424
Scroll down a little bit, you can see this.
2525

26-
![](media/14993938325168/14993958821872.jpg)
26+
![](http://i.imgur.com/L8PiHmZ.jpg)
2727

2828
Double click it.
2929

30-
![](media/14993938325168/14993960811876.jpg)
30+
![](http://i.imgur.com/ZFbjDqA.jpg)
3131

3232
What's the `updater`?
3333

34-
![](media/14993938325168/14993961540557.jpg)
34+
![](http://i.imgur.com/iiDcaGz.jpg)
3535

3636
It's a parameter of `ReactComponent()`, injected by other classes. We don't know where it's injected(because we don't have an injection method here for searching), but we can search `enqueueSetState` to see who has that method. There is a `SetState` in that method name, so seems it's not a generic method, maybe only used in `setState()`.
3737

38-
![](media/14993938325168/14993967988502.jpg)
38+
![](http://i.imgur.com/zdUUW8J.jpg)
3939

4040
Six matches, first is the calling, second is an abstract definition, next three are real definitions of server render, fiber, and stack. Recall that fiber is the new generation, so we go into the last one.
4141

42-
![](media/14993938325168/14993969091178.jpg)
42+
![](http://i.imgur.com/thLZIrj.jpg)
4343

4444
It pushes partial state(the parameter of `setState()`) into the `_pendingStateQueue` and calls `enqueueUpdate(internalInstance)`.
4545

46-
![](media/14993938325168/14993969856086.jpg)
46+
![](http://i.imgur.com/K6hoNpB.jpg)
4747

4848
Open `ReactUpdates.js` and search `enqueueUpdate`.
4949

50-
![](media/14993938325168/14993970236335.jpg)
50+
![](http://i.imgur.com/vx08OI6.jpg)
5151

5252
These two `if` clauses are more complicated than you think.
5353

@@ -57,7 +57,7 @@ Let's simulate the execution with different `batchingStrategy.isBatchingUpdates`
5757

5858
Now the first `if` is true, so it calls `batchedUpdates()`. Let's read `batchedUpdates()`(Recall it's inside `ReactDefaultBatchingStrategy.js` and injected to `ReactUpdate`).
5959

60-
![](media/14993938325168/14993972972615.jpg)
60+
![](http://i.imgur.com/fXXKnIM.jpg)
6161

6262
Here checks whether inside a batching update again. It's false, so we set it to `true`, then wraps and executes it with a transaction.
6363

@@ -96,11 +96,11 @@ Recall that we are already inside a batching update now, so when we finish the m
9696

9797
A picture is worth a thousand words.
9898

99-
![](media/14993938325168/14994022677463.jpg)
99+
![](http://i.imgur.com/E9hCJYJ.jpg)
100100

101101
Above is the `render()` process with `setState()` in `componentDidMount()`.
102102

103-
![](media/14993938325168/14994022992232.jpg)
103+
![](http://i.imgur.com/xxOuiY7.jpg)
104104

105105
Above is the normal `setState()` process. Normal means not inside some batching update.
106106

0 commit comments

Comments
 (0)