1.0.1 • Published 8 years ago

vdelement v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

vdelement

Build Status Coverage Status

Base Element for use with virtual-dom.

This was originally taken from https://github.com/moose-team/friends/blob/master/lib/elements/base-element.js and modified for efficiency.

Requires Node.js v4+.

Install

$ npm install --save vdelement

Example

const inherits = require('util').inherits
const Element = require('vdelement')
const h = require('virtual-dom/h')

module.exports = Sidebar

function Sidebar(app) {
  Element.call(this, app)
}
inherits(Sidebar, Element)

Element.prototype.handleLink = function handleLink(e, link) {
  // do something with the link
  e.preventDefault()
  this.send('openUrl', link.href)
}

Element.prototype.render = function render(links) {
  const logs = links.map((link) => {
    return h('li', [
      h('a', {
        href: link.href
      , onclick: (e) => {
          this.handleLink(e, link)
        }
      }, link.name)
    ])
  })

  return [
    h('ul', logs)
  ]
}

Test

$ npm test

Author

Evan Lucas

License

MIT (See LICENSE for more info)