All files / mframejs/utils cache.ts

62.07% Statements 18/29
100% Branches 2/2
42.86% Functions 3/7
60.71% Lines 17/28

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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69  29x 29x 29x 29x 29x     29x         296x             29x   29x 29x 29x 29x 29x                                           21848x   162x 162x   162x                              
// cache maps
const templateMap = new Map();
const expressionMap = new Map();
const astMap = new Map();
const splitMap = new Map();
let observerKeys = {};
 
// helper for splitting up expressions strings
const splitter = function (stringValue: string) {
    // splits into array
    // persons.name.cool = ['persons','name','cool'];
    // persons.name[4].cool = ['persons','name','4', 'cool'];
 
    return stringValue.split(/\.|\[([^\]]+)\]\.?/).filter((x) => x ? x : null);
};
 
/**
 * Cache for storing ast, templates etc o speed up misc
 *
 */
export class Cache {
 
    public static templateMap = templateMap;
    public static expressionMap = expressionMap;
    public static astMap = astMap;
    public static splitMap = splitMap;
    public static keyMaps = {
        has(x: any): boolean {
            if (observerKeys[x]) {
 
                return true;
            } else {
 
                return false;
            }
        },
        get(x: any): any[string] {
 
            return observerKeys[x];
        },
        set(x: string): any[string] {
            const y = splitter(x);
            observerKeys[x] = y;
 
            return y;
        },
        getCreate(x: string): any[string] {
            if (observerKeys[x]) {
                return observerKeys[x];
            } else {
                const y = splitter(x);
                observerKeys[x] = y;
 
                return y;
            }
        }
    };
 
    public static clear() {
        templateMap.clear();
        expressionMap.clear();
        astMap.clear();
        splitMap.clear();
        observerKeys = {};
    }
 
 
}