const Pages = { oninit: function(vnode) { this.onbeforeupdate(vnode) }, onbeforeupdate: function(vnode) { this.total = vnode.attrs.total this.currentPage = vnode.attrs.page this.perPage = vnode.attrs.perPage || 10 this.maxPage = this.total / this.perPage + 1 }, view: function(vnode) { if (this.total <= this.perPage) return null return m('pages', [ this.currentPage > 1 ? [ m(m.route.Link, { href: vnode.attrs.base, }, 'First'), m(m.route.Link, { href: vnode.attrs.base + (this.currentPage > 2 ? '?page=' + (this.currentPage - 1) : '' ), }, 'Previous'), ] : m('div'), m('div', 'Page ' + this.currentPage), this.currentPage < this.maxPage ? [ m(m.route.Link, { href: vnode.attrs.base + '?page=' + (this.currentPage + 1), }, 'Next'), m(m.route.Link, { href: vnode.attrs.base + '?page=' + this.maxPage, }, 'Last') ] : m('div'), ]) }, } module.exports = Pages