mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-07 08:50:22 +08:00
fix(frontend): 修复前端审计问题并补充回归测试
This commit is contained in:
19
frontend/src/utils/stableObjectKey.ts
Normal file
19
frontend/src/utils/stableObjectKey.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
let globalStableObjectKeySeed = 0
|
||||
|
||||
/**
|
||||
* 为对象实例生成稳定 key(基于 WeakMap,不污染业务对象)
|
||||
*/
|
||||
export function createStableObjectKeyResolver<T extends object>(prefix = 'item') {
|
||||
const keyMap = new WeakMap<T, string>()
|
||||
|
||||
return (item: T): string => {
|
||||
const cached = keyMap.get(item)
|
||||
if (cached) {
|
||||
return cached
|
||||
}
|
||||
|
||||
const key = `${prefix}-${++globalStableObjectKeySeed}`
|
||||
keyMap.set(item, key)
|
||||
return key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user