DIO
![dio.js](https://dio.js.org/assets/images/logo.svg)
A Library For Building User Interfaces.
![Join the chat at https://gitter.im/thysultan/dio.js](https://img.shields.io/badge/chat-gitter-green.svg?style=flat)
Support
- Edge
- IE 9+
- Chrome
- Firefox
- Safari
- Node
Installation
Direct Download
<script src=dio.min.js></script>
CDN
<script src=https://unpkg.com/dio.js></script>
<script src=https://cdn.jsdelivr.net/npm/dio.js></script>
NPM
npm install dio.js --save
Getting started
dio.render(
h('h1', 'Hello, world!'),
document.getElementById('root')
)
The easiest way to get started with DIO is to walk through the Introduction to DIO or the API Documentation.
Features
The following is an overview of the features DIO allows you to make use of.
-
Rendering
- Elements
- Components
- Primitives like strings, numbers, null, undefined
- Fragments like Arrays, Iterables
- and others renderables like Promises and Portals
-
Components
- Functional stateful components
- Class stateful components
-
Events
- Functions or EventListener
- Preserve "this" reference
-
Errors
- Error boundaries through
componentDidCatch
-
setState
- As with a Object
- As with a Promise
- As with an implicit return
-
Lifecycle
- async componentWillUnmount
- async getInitialState
Example
This intentionally overloaded example presents a few features detailed above, namely – error boundaries, an implicit setState return, Promise setState and rendering Promises & Fragments.
class Input {
componentDidCatch ({stack, message, ...error}, {componentStack}) {
return {error: true}
}
async getInitialState() {
return {value: 'Hi!'}
}
async handleInput({target}, props, state) {
return {value: target.value}
}
async render(props, {value, error}, context) {
if (error)
return h('h1', 'Something went wrong!')
return [
h('input', {
value: value,
onInput: this.handleInput
}),
h('p', value)
]
}
}
dio.render(h(Input))
--
Links
- Introduction to DIO
- API Documentation
- REPL