yoho-mvc.js 818 Bytes
'use strict';

const $ = require('yoho-jquery');

class View {
    constructor(ele) {
        this.$base = $(ele);
    }

    on(event, target, fn) {
        if (typeof target === 'function') {
            fn = target;
            target = null;
        }

        if (this.$base) {
            if (target) {
                this.$base.on(event, target, fn);
            } else {
                this.$base.on(event, fn);
            }
        }
    }

    emit(event, ...data) {
        this.$base.trigger(event, data);
    }

}

class Controller {
    constructor() {

    }

}

function http(options) {
    let ajax = $.ajax(options);

    ajax.then = ajax.done.bind(ajax);
    ajax.catch = ajax.fail.bind(ajax);
    ajax.finally = ajax.always.bind(ajax);
    return ajax;
}

export {
    View, Controller, http
};