1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var ReactTypeOfWork = require('./ReactTypeOfWork');
|
13 | var ClassComponent = ReactTypeOfWork.ClassComponent,
|
14 | HostContainer = ReactTypeOfWork.HostContainer,
|
15 | HostComponent = ReactTypeOfWork.HostComponent;
|
16 |
|
17 | var _require = require('./ReactFiberUpdateQueue'),
|
18 | callCallbacks = _require.callCallbacks;
|
19 |
|
20 | module.exports = function (config) {
|
21 | var updateContainer = config.updateContainer;
|
22 | var commitUpdate = config.commitUpdate;
|
23 |
|
24 | function commitWork(current, finishedWork) {
|
25 | switch (finishedWork.tag) {
|
26 | case ClassComponent:
|
27 | {
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | if (finishedWork.alternate) {
|
33 | finishedWork.alternate.updateQueue = null;
|
34 | }
|
35 | if (finishedWork.callbackList) {
|
36 | var callbackList = finishedWork.callbackList;
|
37 |
|
38 | finishedWork.callbackList = null;
|
39 | callCallbacks(callbackList, finishedWork.stateNode);
|
40 | }
|
41 |
|
42 | return;
|
43 | }
|
44 | case HostContainer:
|
45 | {
|
46 |
|
47 | var children = finishedWork.output;
|
48 | var root = finishedWork.stateNode;
|
49 | var containerInfo = root.containerInfo;
|
50 | updateContainer(containerInfo, children);
|
51 | return;
|
52 | }
|
53 | case HostComponent:
|
54 | {
|
55 | if (finishedWork.stateNode == null || !current) {
|
56 | throw new Error('This should only be done during updates.');
|
57 | }
|
58 |
|
59 | var child = finishedWork.child;
|
60 | var _children = child && !child.sibling ? child.output : child;
|
61 | var newProps = finishedWork.memoizedProps;
|
62 | var oldProps = current.memoizedProps;
|
63 | var instance = finishedWork.stateNode;
|
64 | commitUpdate(instance, oldProps, newProps, _children);
|
65 | return;
|
66 | }
|
67 | default:
|
68 | throw new Error('This unit of work tag should not have side-effects.');
|
69 | }
|
70 | }
|
71 |
|
72 | return {
|
73 | commitWork: commitWork
|
74 | };
|
75 | }; |
\ | No newline at end of file |