阶段七:完成 React Feature 化与前置重构收口

This commit is contained in:
Christ committed 2026-08-17 20:29:34 +08:00
1 parent 375e84d663
commit 1a228dc35c
305 files changed
+14179 -5431

No files matched your search

@@ -0,0 +1,12 @@
import { expect, test, vi } from 'vitest';
import { commitIfLatest } from './latestRequest';
test('stale account responses cannot replace the latest rules', /* 当前回调处理用户交互或异步状态变化。 */ () => {
// commit 提交版本。
const commit = vi.fn();
expect(commitIfLatest(1, 2, 'a', 'b', ['account-a'], commit)).toBe(false);
expect(commit).not.toHaveBeenCalled();
expect(commitIfLatest(2, 2, 'a', 'b', ['account-a'], commit)).toBe(false);
expect(commitIfLatest(2, 2, 'b', 'b', ['account-b'], commit)).toBe(true);
expect(commit).toHaveBeenCalledWith(['account-b']);
});
+13
View File
@@ -0,0 +1,13 @@
// commitIfLatest 仅在请求仍为最新时提交结果。
export const commitIfLatest = <T>(
requestID: number,
currentRequestID: number,
requestKey: string,
currentKey: string,
value: T,
commit: (value: T) => void,
): boolean => {
if (requestID !== currentRequestID || requestKey !== currentKey) return false;
commit(value);
return true;
};