在react的 react-dom-client.development.js 中有这样一段代码 ,如下
thenableState = thenable;
thenableState.status = "pending";
thenableState.then(
function (fulfilledValue) {
if ("pending" === thenable.status) {
var fulfilledThenable = thenable;
fulfilledThenable.status = "fulfilled";
fulfilledThenable.value = fulfilledValue;
}
},
function (error) {
if ("pending" === thenable.status) {
var rejectedThenable = thenable;
rejectedThenable.status = "rejected";
rejectedThenable.reason = error;
}
}
);
}
switch (thenable.status) {
case "fulfilled":
return thenable.value;
case "rejected":
throw (
((thenableState = thenable.reason),
checkIfUseWrappedInAsyncCatch(thenableState),
thenableState)
);
}
问题: 由于 then函数的异步性, 前面已经将status设置为了pending, 为啥后文还要对 status进行switch? switch中的status不必然是pending吗?
thenableState.status和thenable.status,这俩不一样哦