-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStateManager.js
122 lines (97 loc) · 2.91 KB
/
StateManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
export default class StateManager {
static instance;
constructor() {
if (StateManager.instance) {
return StateManager.instance;
}
StateManager.instance = this;
/** @type {null|Object} The current unit of work being processed. */
this.nextUnitOfWork = null;
/** @type {null|Object} The current root of the rendered virtual DOM. */
this.currentRoot = null;
/** @type {null|Object} The work-in-progress root that's being built. */
this.wipRoot = null;
this.wipFiber = null;
this.hookIndex = 0;
/** @type {Array} Elements that need to be removed from the DOM. */
this.deletions = [];
/** @type {Array} Hooks associated with the current functional component being processed. */
// this.hooks = [];
/** @type {number} Index of the current hook being processed. */
this.hookIndex = 0;
}
getHookIndex() {
return this.hookIndex;
}
setHookIndex(index) {
this.hookIndex = index;
}
getWipFiber() {
return this.wipFiber;
}
setWipFiber(fiber) {
this.wipFiber = fiber;
}
/**
* getCurrentRoot - Returns the current root of the rendered virtual DOM.
* @returns {Object} The current root of the rendered virtual DOM.
*/
getCurrentRoot() {
return this.currentRoot;
}
/**
* setCurrentRoot - Sets the current root of the rendered virtual DOM.
* @param {Object} root - The current root of the rendered virtual DOM.
*/
setCurrentRoot(root) {
this.currentRoot = root;
}
/**
* getWorkInProgressRoot - Returns the work-in-progress root that's being built.
* @returns {Object} The work-in-progress root that's being built.
*/
getWorkInProgressRoot() {
return this.wipRoot;
}
/**
* setWorkInProgressRoot - Sets the work-in-progress root that's being built.
* @param {Object} root - The work-in-progress root that's being built.
*/
setWorkInProgressRoot(root) {
this.wipRoot = root;
}
/**
* getDeletions - Returns elements that need to be removed from the DOM.
* @returns {Array} Elements that need to be removed from the DOM.
*/
getDeletions() {
return this.deletions;
}
addDeletions(fiber) {
this.deletions.push(fiber);
}
/**
* setDeletions - Sets elements that need to be removed from the DOM.
* @param {Array} deletions - Elements that need to be removed from the DOM.
*/
setDeletions(deletions) {
this.deletions = deletions;
}
clearDeletions() {
this.deletions = [];
}
/**
* getNextUnitOfWork - Returns the current unit of work being processed.
* @returns {Object} The current unit of work being processed.
*/
getNextUnitOfWork() {
return this.nextUnitOfWork;
}
/**
* setNextUnitOfWork - Sets the current unit of work being processed.
* @param {Object} unit - The current unit of work being processed.
*/
setNextUnitOfWork(unit) {
this.nextUnitOfWork = unit;
}
}