import View from "../../View";
import {IPropertyBinding} from "./IPropertyBinding";

export abstract class Controller<T> extends View<Element> {
    protected model: IPropertyBinding<T> | null = null;

    constructor({tag = 'div'}: { tag: string }) {
        super();

        this.el = document.createElement(tag);
    }

    /**
     * Attach object to be controlled
     */
    bind(binding: IPropertyBinding<T>) {
        this.model = binding;

        // update controller
        this.read_state();
    }

    /**
     * Write controller state to the controlled object
     */
    public abstract write_state(): void;

    /**
     * Read controller state from the controlled object
     */
    public abstract read_state(): void
}
