All files / src/utils keyMap.js

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15      148x 148x       4047x 1174x   4047x      
// 参考 https://juejin.cn/post/6844903843860316167
export default class KeyMap {
    constructor() {
        this.map = new WeakMap();
        this.count = 0
    }
 
    getKey(obj) {
        if (!this.map.has(obj)) {
            this.map.set(obj, this.count++);
        }
        return this.map.get(obj);
    }
}