{% extends "base.html" %}

{% block title %}Mithril{% endblock %}

{% block body %}
<main id="mit" class="documentation">
</main>
<script>
    var root = document.getElementById('mit')
    var count = 0
    var timer = 10000; // 10 seconds

    var rend = {
        view: function() {
            return m('section', [
                m('h1', 'Mithril'),
                m('p', 'You got ' + count + ' data(s)'),
                m('button', {
                    class: 'pseudo',
                    onclick: getdata
                }, 'Click')
            ])
        }
    }

    var getdata = function() {
        m.request({
            list: [],
            method: 'GET',
            url: '/api/posts',
            withCredentials: true
        })
        .then(function(get) {
            getdata.list = get
            count = getdata.list.count
        })
    }

    m.mount(root, rend)

    setInterval(getdata, timer);
</script>
{% endblock %}
