在写代码时遇到的一些困惑
// move.ts
export const banishedZoneCase = (
builder: ActionReducerMapBuilder<DuelState>
) => {
builder.addCase(fetchBanishedZoneMeta.pending, (state, action) => {
// Meta结果没返回之前先更新`ID`
const controler = action.meta.arg.controler;
const sequence = action.meta.arg.sequence;
const code = action.meta.arg.code;
const newExclusion = {
occupant: { id: code, data: {}, text: {} },
location: {
controler,
location: ygopro.CardZone.REMOVED,
sequence,
},
idleInteractivities: [],
counters: {},
};
if (judgeSelf(controler, state)) {
extendState(state.meBanishedZone, newExclusion);
} else {
extendState(state.opBanishedZone, newExclusion);
}
});
builder.addCase(fetchBanishedZoneMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const sequence = action.payload.sequence;
const meta = action.payload.meta;
if (judgeSelf(controler, state)) {
extendMeta(state.meBanishedZone, meta, sequence);
} else {
extendMeta(state.opBanishedZone, meta, sequence);
}
});
};
在这里fetchBanishedZoneMeta
首先是在除外的末端增加了一张卡(pending
之中的extendState
),然后在fulfilled
之中更新了sequence
位置的卡的meta
。
我有疑问的点是,这两张卡是一定是同一张卡吗?因为按照逻辑来讲,这肯定是同一张卡的插入与更新。我的猜想是目前因为sequence
每次都恰巧是最末位置,所以并不会造成插入和更新不是同一张卡的情况。
那么,将这些操作全部统一成插入到sequence
位置是可以的吗?将sequence
和队列的idx
完全挂钩是可行的吗?
除此之外,因为我看到有 shuffle hands 的操作,会不会出现队列不是按照sequence来排列的情况呢?