bitovi/canjs

View on GitHub
demos/can-component/paginate_next.html

Summary

Maintainability
Test Coverage
<body>
<div id="out"></div>
<script src="../../node_modules/steal/steal.js" dev-bundle main="@empty">
import { Component, stache, DefineMap} from "can";

const demoHtml = `Page {{ page() }} <button on:click='next()'>Next</button>`;


const ViewModel = DefineMap.extend({
    offset: {
        default: 0
    },
    limit: {
        default: 20
    },
    next: function(){
        this.offset = this.offset + this.limit;
    },
    page: function(){
        return Math.floor(this.offset / this.limit) + 1;
    }
});

Component.extend({
    tag: "my-paginate",
    ViewModel: ViewModel,
    view: stache(demoHtml)
});

const out = document.getElementById("out");
out.appendChild(stache("<my-paginate/>")({}));
</script>
</body>