Skip to content

yoshuawuyts/choo-component-preview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Preview for what choo's component API will look like

Resources

License

Stars

Watchers

Forks

Packages

No packages published