Skip to content

Instantly share code, notes, and snippets.

@xyzdata
Created June 29, 2017 05:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyzdata/4e6265ffcbe92da203cafa092caa77a7 to your computer and use it in GitHub Desktop.
Save xyzdata/4e6265ffcbe92da203cafa092caa77a7 to your computer and use it in GitHub Desktop.
dva & choo & elm

dvajs

https://github.com/dvajs/dva#dva

https://github.com/dvajs/dva/blob/master/README_zh-CN.md

choo

https://github.com/yoshuawuyts/choo

https://choo.io/

✌️

    
let html = require('choo/html'),
    choo = require('choo'),
    app = choo();

app.use(titleStore);
app.route('/', mainView);
app.mount('body');

const mainView = (state, emit) => {
    let update = (e) => {
        emit('update', e.target.value);
    };
    return html `
        <body>
        <h1>Title: ${state.title}</h1>
        <input type="text" value="${state.title}" oninput=${update}>
        </body>
    `;
};

const titleStore = (state, emitter) => {
    state.title = 'Not quite set yet';
    emitter.on('DOMContentLoaded', function () {
        emitter
            .on('update', function (newTitle) {
                state.title = newTitle;
                emitter.emit('render');
            })
    });
};

elm

http://elm-lang.org/

@xyzdata
Copy link
Author

xyzdata commented Jun 29, 2017

let html = require('choo/html'),
    choo = require('choo'),
    app = choo();

app.use(titleStore);
app.route('/', mainView);
app.mount('body');

const mainView = (state, emit) => {
    let update = (e) => {
        emit('update', e.target.value);
    };
    return html `
        <body>
            <h1>Title: ${state.title}</h1>
            <input type="text" value="${state.title}" oninput=${update}>
        </body>
    `;
};

const titleStore = (state, emitter) => {
    state.title = 'Not quite set yet';
    emitter.on('DOMContentLoaded', () => {
        emitter.on('update', (newTitle) => {
            state.title = newTitle;
            emitter.emit('render');
        });
    });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment