项目作者: nearform

项目描述 :
Simple data fetching plugin for Choo with server-side rendering support
高级语言: JavaScript
项目地址: git://github.com/nearform/choo-data.git
创建时间: 2018-04-05T18:37:54Z
项目社区:https://github.com/nearform/choo-data

开源协议:

下载


choo-data

Simple data fetching plugin for Choo with SSR (server-side rendering) support.

Requires choo-async.

Usage -
Install -
License: MIT

stability
standard

Usage

  1. const choo = require('choo')
  2. const data = require('choo-data')
  3. const async = require('choo-async')
  4. const html = require('choo-async/html')
  5. const app = async(choo())
  6. app.use(data())
  7. app.route('/', view)
  8. app.mount('body')
  9. async function view (state, emit) {
  10. const post = await app.data.load('post', getData, 1)
  11. return html`
  12. <body>
  13. ${post
  14. ? html`<p>${post.title}</p>`
  15. : html`<p>Loading...</p>`
  16. }
  17. </body>
  18. `
  19. }
  20. async function getData (id) {
  21. const response = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
  22. return response.json()
  23. }

See examples for more

Install

  1. npm install choo-data

License

MIT