All files / mframejs/utils connectBehavior.ts

28.57% Statements 4/14
100% Branches 0/0
50% Functions 1/2
28.57% Lines 4/14

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 2929x 29x 29x   29x                                                
import { BindingEngine } from '../binding/exported';
import { Cache } from './cache';
import { ContainerBehavior } from '../container/exported';
 
export function connectBehavior(expressionValue: string, _class: any) {
    if (expressionValue.indexOf('&') !== -1) {
        let x = Cache.expressionMap.get(expressionValue);
        if (!x) {
            const tokens: any = BindingEngine.tokenize(expressionValue);
            x = {};
            x.ast = BindingEngine.generateAST(tokens);
            Cache.expressionMap.set(expressionValue, {
                ast: x.ast,
                tokens: tokens
            });
        }
        const behaviors = BindingEngine.getBehavior((<any>x).ast);
        if (behaviors) {
            behaviors.forEach((behavior: { name: string, args: any[] }) => {
                const x = ContainerBehavior.findBehavior(behavior.name);
                if (x) {
                    let curBehavior = new x(_class, behavior.args);
                    curBehavior = curBehavior;
                }
            });
        }
    }
}