All files / mframejs/attribute modelAttribute.ts

90.91% Statements 10/11
100% Branches 0/0
75% Functions 3/4
90% Lines 9/10

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 5629x   29x             29x                                 19x 185x   19x   19x         19x       19x                              
import { customAttribute } from '../decorator/exported';
import { IAttribute, IListener, IBindingContext } from '../interface/exported';
import { BindingEngine } from '../binding/exported';
 
/**
 * Helper for selects, so it knows where it is
 *
 */
@customAttribute('model.bind')
export class ModelAttribute implements IAttribute {
 
    // build in properties added by our template engine
    public $element: HTMLInputElement;
    public $attribute: Attr;
    public $bindingContext: IBindingContext;
    private value: string | null | undefined;
    private subscribeInternal: IListener;
    private expression: string | null | undefined;
 
 
    /**
     * created
     *
     */
    public created() {
 
        (this.$attribute as any).getContent = () => {
            return this;
        };
        this.expression = this.$attribute.value;
 
        this.subscribeInternal = {
            name: 'modelAttribute:',
            value: this.value,
            call: (newValue: any, oldValue: any) => {
                if (oldValue !== newValue) {
                    this.value = newValue;
                }
            }
        };
        BindingEngine.subscribeClassProperty(this.$bindingContext, this.expression, this.subscribeInternal);
 
    }
 
 
    /**
     * detached
     *
     */
    public detached() {
 
        (this.$attribute as any).getContent = null;
    }
 
}