| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8e1f42f commit a2c3041
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,7 +180,7 @@ class ReactGraph | |||
| 180 | 180 | ||
| 181 | 181 | LinkCache linkCache_; | |
| 182 | 182 | ||
| 183 | - bool isTransactionActive_ = false; | ||
| 183 | + int transactionLevel_ = 0; | ||
| 184 | 184 | bool allowLinkedTransactionMerging_ = false; | |
| 185 | 185 | }; | |
| 186 | 186 | ||
@@ -195,17 +195,17 @@ void ReactGraph::PushInput(NodeId nodeId, F&& inputCallback) | |||
| 195 | 195 | ||
| 196 | 196 | changedInputs_.push_back(nodeId); | |
| 197 | 197 | ||
| 198 | - if (!isTransactionActive_) | ||
| 198 | + if (transactionLevel_ == 0) | ||
| 199 | 199 | Propagate(); | |
| 200 | 200 | } | |
| 201 | 201 | ||
| 202 | 202 | template <typename F> | |
| 203 | 203 | void ReactGraph::DoTransaction(F&& transactionCallback) | |
| 204 | 204 | { | |
| 205 | 205 | // Transaction callback may add multiple inputs. | |
| 206 | - isTransactionActive_ = true; | ||
| 206 | + ++transactionLevel_; | ||
| 207 | 207 | std::forward<F>(transactionCallback)(); | |
| 208 | - isTransactionActive_ = false; | ||
| 208 | + --transactionLevel_; | ||
| 209 | 209 | ||
| 210 | 210 | Propagate(); | |
| 211 | 211 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,9 @@ void ReactGraph::Propagate() | |||
| 72 | 72 | auto& node = nodeData_[nodeId]; | |
| 73 | 73 | auto* nodePtr = node.nodePtr; | |
| 74 | 74 | ||
| 75 | - if (nodePtr->Update(0u) == UpdateResult::changed) | ||
| 75 | + UpdateResult res = nodePtr->Update(0u); | ||
| 76 | + | ||
| 77 | + if (res == UpdateResult::changed) | ||
| 76 | 78 | { | |
| 77 | 79 | changedNodes_.push_back(nodePtr); | |
| 78 | 80 | ScheduleSuccessors(node); | |
@@ -87,10 +89,12 @@ void ReactGraph::Propagate() | |||
| 87 | 89 | auto& node = nodeData_[nodeId]; | |
| 88 | 90 | auto* nodePtr = node.nodePtr; | |
| 89 | 91 | ||
| 92 | + // A predecessor of this node has shifted to a lower level? | ||
| 90 | 93 | if (node.level < node.newLevel) | |
| 91 | 94 | { | |
| 92 | - // Re-schedule this node | ||
| 95 | + // Re-schedule this node. | ||
| 93 | 96 | node.level = node.newLevel; | |
| 97 | + | ||
| 94 | 98 | RecalculateSuccessorLevels(node); | |
| 95 | 99 | scheduledNodes_.Push(nodeId, node.level); | |
| 96 | 100 | continue; | |
@@ -103,7 +107,18 @@ void ReactGraph::Propagate() | |||
| 103 | 107 | continue; | |
| 104 | 108 | } | |
| 105 | 109 | ||
| 106 | - if (nodePtr->Update(0u) == UpdateResult::changed) | ||
| 110 | + UpdateResult res = nodePtr->Update(0u); | ||
| 111 | + | ||
| 112 | + // Topology changed? | ||
| 113 | + if (res == UpdateResult::shifted) | ||
| 114 | + { | ||
| 115 | + // Re-schedule this node. | ||
| 116 | + RecalculateSuccessorLevels(node); | ||
| 117 | + scheduledNodes_.Push(nodeId, node.level); | ||
| 118 | + continue; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + if (res == UpdateResult::changed) | ||
| 107 | 122 | { | |
| 108 | 123 | changedNodes_.push_back(nodePtr); | |
| 109 | 124 | ScheduleSuccessors(node); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments