40463772c5
新增 shop-data-selection.ts:店铺数据结果 result_id 选择集(字符串兼容)的 纯切换/批量操作。 TDD: task-112.test.ts 8 用例先 RED 后 GREEN。
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
/** 店铺数据结果批量选择(任务 112):result_id 选择集(字符串兼容)的纯操作。 */
|
|
|
|
export function createShopDataSelection(): Set<string> {
|
|
return new Set<string>()
|
|
}
|
|
|
|
function validKey(key: string): boolean {
|
|
return typeof key === 'string' && key.length > 0
|
|
}
|
|
|
|
export function toggleShopDataSelection(selection: Set<string>, resultId: string): Set<string> {
|
|
const next = new Set(selection)
|
|
if (!validKey(resultId)) return next
|
|
if (next.has(resultId)) next.delete(resultId)
|
|
else next.add(resultId)
|
|
return next
|
|
}
|
|
|
|
export function addShopDataSelection(selection: Set<string>, resultIds: readonly string[]): Set<string> {
|
|
const next = new Set(selection)
|
|
for (const id of resultIds) if (validKey(id)) next.add(id)
|
|
return next
|
|
}
|
|
|
|
export function removeShopDataSelection(selection: Set<string>, resultIds: readonly string[]): Set<string> {
|
|
const next = new Set(selection)
|
|
for (const id of resultIds) next.delete(id)
|
|
return next
|
|
}
|
|
|
|
export function countShopDataSelection(selection: Set<string>): number {
|
|
return selection.size
|
|
}
|