vdelement

1.0.1 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i vdelement

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • eh
  • evanlucas