All Projects → yoshuawuyts → choo-component-preview

yoshuawuyts / choo-component-preview

Licence: Apache-2.0 license
Preview for what choo's component API will look like

Programming Languages

javascript
184084 projects - #8 most used programming language

choo-component-preview

npm version build status downloads js-standard-style

Choo component API preview. See discussion for more information.

Usage

var choo = require('choo')

var app = choo()
app.use(require('choo-component-preview')())
app.mount('body')
var Component = require('nanocomponent')
var html = require('choo/html')

module.exports = class Article extends Component {
  constructor (name, state, emit) {
    super(name)
    this.state = state
    this.emit = emit
  }

  createElement (article) {
    return html`
      <article>
        <h2>${article.title}</h2>
        <p>${article.body}</p>
      </article>
    `
  }

  update () {
    return false
  }
}
var Article = require('./components/article')
var Header = require('./components/header')
var Footer = require('./components/footer')

module.exports = function (state, emit) {
  return html`
    <body>
      ${state.cache(Header, 'header').render()}
      ${state.articles.map(article => {
        return state.cache(Article, article.id).render(article)
      })}
      ${state.cache(Footer, 'footer').render()}
    </body>
  `
}

Installation

$ npm install choo-component-preview

License

Apache-2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].