All files / mframejs/binding contextOfObject.ts

100% Statements 8/8
100% Branches 9/9
100% Functions 1/1
100% Lines 8/8

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 3129x           29x   15121x 15121x       15121x             7809x   410x           15121x    
import { Cache } from '../utils/exported';
import { IBindingContext } from '../interface/exported';
/**
 * get context object
 *
 */
export function getCorrectContext(value: any, ctx: IBindingContext): IBindingContext {
 
    const keys = Cache.keyMaps.getCreate(value);
    const key = keys[0];
 
 
    // more then 1, then its array
    let newCtx = ctx;
    let overrideCtx: any;
 
 
    if (typeof key === 'string' && key[0] !== '$') {
        if (newCtx && newCtx.$overrideContext) {
            while (newCtx.$overrideContext) {
                newCtx = newCtx.$overrideContext;
                if (newCtx && newCtx.$context && key in newCtx.$context) {
                    overrideCtx = newCtx;
                }
            }
        }
    }
 
    return overrideCtx || ctx;
}