| 171 | } |
| 172 | |
| 173 | export function flushPostFlushCbs(seen?: CountMap): void { |
| 174 | if (pendingPostFlushCbs.length) { |
| 175 | const deduped = [...new Set(pendingPostFlushCbs)].sort( |
| 176 | (a, b) => getId(a) - getId(b), |
| 177 | ) |
| 178 | pendingPostFlushCbs.length = 0 |
| 179 | |
| 180 | // #1947 already has active queue, nested flushPostFlushCbs call |
| 181 | if (activePostFlushCbs) { |
| 182 | activePostFlushCbs.push(...deduped) |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | activePostFlushCbs = deduped |
| 187 | if (__DEV__) { |
| 188 | seen = seen || new Map() |
| 189 | } |
| 190 | |
| 191 | for ( |
| 192 | postFlushIndex = 0; |
| 193 | postFlushIndex < activePostFlushCbs.length; |
| 194 | postFlushIndex++ |
| 195 | ) { |
| 196 | const cb = activePostFlushCbs[postFlushIndex] |
| 197 | if (__DEV__ && checkRecursiveUpdates(seen!, cb)) { |
| 198 | continue |
| 199 | } |
| 200 | if (cb.flags! & SchedulerJobFlags.ALLOW_RECURSE) { |
| 201 | cb.flags! &= ~SchedulerJobFlags.QUEUED |
| 202 | } |
| 203 | if (!(cb.flags! & SchedulerJobFlags.DISPOSED)) cb() |
| 204 | cb.flags! &= ~SchedulerJobFlags.QUEUED |
| 205 | } |
| 206 | activePostFlushCbs = null |
| 207 | postFlushIndex = 0 |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | const getId = (job: SchedulerJob): number => |
| 212 | job.id == null ? (job.flags! & SchedulerJobFlags.PRE ? -1 : Infinity) : job.id |