Skip to content

Commit

Permalink
Refactor legacy update queue
Browse files Browse the repository at this point in the history
Refactors legacy update queue to incoporate rebasing fix. Uses nearly
the same approach as the hook update queue but has to handle a few
other cases.
  • Loading branch information
acdlite committed Dec 3, 2019
1 parent f3659c5 commit 1cc8f85
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('createSubscription', () => {

it('should still work if unsubscription is managed incorrectly', async () => {
const Subscription = createSubscription({
getCurrentValue: source => undefined,
getCurrentValue: source => source.value,
subscribe: (source, callback) => {
source.then(callback);
// (Can't unsubscribe from a Promise)
Expand All @@ -174,8 +174,19 @@ describe('createSubscription', () => {
}

let resolveA, resolveB;
const promiseA = new Promise(resolve => (resolveA = resolve));
const promiseB = new Promise(resolve => (resolveB = resolve));
const promiseA = new Promise(resolve => {
resolveA = v => {
resolve(v);
promiseA.value = v;
};
});
const promiseB = new Promise(
resolve =>
(resolveB = v => {
resolve(v);
promiseB.value = v;
}),
);

// Subscribe first to Promise A then Promise B
ReactNoop.render(<Subscription source={promiseA}>{render}</Subscription>);
Expand Down
35 changes: 24 additions & 11 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,20 +1142,33 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {

function logUpdateQueue(updateQueue: UpdateQueue<mixed>, depth) {
log(' '.repeat(depth + 1) + 'QUEUED UPDATES');
const firstUpdate = updateQueue.firstUpdate;
if (!firstUpdate) {
const last = updateQueue.baseQueue;
if (last === null) {
return;
}
const first = last.next;
let update = first;
if (update !== null) {
do {
log(
' '.repeat(depth + 1) + '~',
'[' + update.expirationTime + ']',
);
} while (update !== null && update !== first);
}

log(
' '.repeat(depth + 1) + '~',
'[' + firstUpdate.expirationTime + ']',
);
while (firstUpdate.next) {
log(
' '.repeat(depth + 1) + '~',
'[' + firstUpdate.expirationTime + ']',
);
const lastPending = updateQueue.shared.pending;
if (lastPending !== null) {
const firstPending = lastPending.next;
let pendingUpdate = firstPending;
if (pendingUpdate !== null) {
do {
log(
' '.repeat(depth + 1) + '~',
'[' + pendingUpdate.expirationTime + ']',
);
} while (pendingUpdate !== null && pendingUpdate !== firstPending);
}
}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,11 +1301,7 @@ function dispatchAction<S, A>(
// This is the first update. Create a circular list.
update.next = update;
} else {
const first = pending.next;
if (first !== null) {
// Still circular.
update.next = first;
}
update.next = pending.next;
pending.next = update;
}
queue.pending = update;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ export function checkForWrongSuspensePriorityInDEV(sourceFiber: Fiber) {
// has triggered any high priority updates
const updateQueue = current.updateQueue;
if (updateQueue !== null) {
let update = updateQueue.firstUpdate;
let update = updateQueue.baseQueue;
while (update !== null) {
const priorityLevel = update.priority;
if (
Expand Down
Loading

0 comments on commit 1cc8f85

Please sign in to comment.