0.5.2 • Published 4 years ago

mvc-tsx v0.5.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

MVC-TSX (alpha version)

CI status

With MVC-TSX you can write imperative code for creating reactive applications.

import React from "react";
import * as ReactDOM from "react-dom";
import {Model, View, Controller, on, event} from "mvc-tsx";

// define Model
class LoginModel extends Model {
    login: string = "";
    password: string = "";
}

// define View
class LoginView extends View<LoginModel> {
    
    // declare interactive elements
    static ui = {
        loginInput: ".Login--loginInput",
        passInput: ".Login--passInput",
        // ctrl + click on key "loginButton"
        // can jump to method onClickLogin
        loginButton: ".Login--loginBtn"
    };

    template(loginModel: LoginModel) {
        return (<div className="Login">
            <input className="Login--loginInput"/>
            <input className="Login--passInput"/>
            <button className="Login--loginBtn"></button>
        </div>);
    }

}

// define Controller
@forView(LoginView)
class LoginController extends Controller<LoginModel> {

    @on("change", LoginView.ui.loginInput)
    onChangeLogin( @event("target", "value") inputValue: string ) {
        this.model.set({
            login: inputValue
        });
    }

    @on("change", LoginView.ui.passInput)
    onChangePassword( @event("target", "value") inputValue: string ) {
        this.model.set({
            password: inputValue
        });
    }

    @on("click", LoginView.ui.loginButton)
    onClickLogin() {
        const {login, password} = this.model;
        // do login ...
    }
}

// and render
const loginModel = new LoginModel();

ReactDOM.render(
    <LoginView model={loginModel}/>,
    document.getElementById("root")
);

Downloads

minify + React + EventEmitter + MVC

React + EventEmitter + MVC

minify + MVC

MVC

Examples

clock
counter
cart
TodoMVC
drag and drop

0.5.2

4 years ago

0.5.1

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.4

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago