MCPcopy Index your code
hub / github.com/dyo/dyo

github.com/dyo/dyo @v2.0.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.8 ↗ · + Follow
235 symbols 412 edges 39 files 1 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Dyo

Dyo

A JavaScript library for building user interfaces.

Coverage Size Licence NPM

Installation

  • Use a Direct Download: <script src=dyo.js></script>
  • Use a CDN: <script src=unpkg.com/dyo></script>
  • Use NPM: npm install dyo --save

Documentation

Documentation can be find on the website.

See the Getting Started page for a quick overview.

The documentation is divided into several sections:

You can improve it by sending pull requests to this repository.

Examples

Several examples can be found on the website. Here's one to get started:

import {h, render} from 'dyo'

function Example (props) {
    return h('h1', {}, 'Hello ', props.name)
}

render(h(Example, {name: 'World'}), 'body')

This will render a heading element with the text content "Hello World" into the specified target(the body element).

Comparison

The library is much alike React, so it's only natural that a comparison of the differences is in order; Which if successful might manage to highlight why it exists.

Re-parenting

The Portal component supports string selectors as targets. This presents an array of different possibilities with regards to isomorphic target references.


function Example (props) {
    return h(Portal, {target: 'main'}, 'Hello')
}

render(h(Example), 'body')

In addition to this – re-parenting is baked into portals. That is when a portals container is changed, instead of unmounting its contents and re-mounting them to the newly designated container we can instead move its contents without replaying destruction unmount operations that may discard valuable interface and component state.

In co-ordination with custom renderers, portals afford the opportunity to create atomic branch specific custom renderers. Imagine isolated declarative canvas renderers within a document renderer.

Promises

Promises(or thenables) are first class values. This affords authors the ability to render promises, directly await promises within effects and events, and delay unmounting.

render(props => Promise.resolve('Hello'), 'body')

function Example (props) {
    useEffect(async () => {
        // out of band updates in here
        // are also batched
        return async () => {
            // delays unmount until the animation
            // has completed
            return props.current.animate({}).finished
        }
    })
}

Callbacks

In an async world, public interfaces like render are not guaranteed to complete synchronously if a subtree happens to have async dependencies within it. A consequence of this will see more use cases for the optional callback arguments that this function accepts – in much the same way authors are afforded the ability to await on this central routine.

await render(props => Promise.resolve('Hello'), 'body')
Resources

In addition to other hooks, a resource allocation hook that can be used to fetch and cache resources.

function Example (props) {
    const resource = useResource(props => fetch('https://reqres.in/api/users'))
    return h('pre', {}, JSON.stringify(resource))
}
Async Server Rendering

Server side rendering supports the plethora of async primitives supported.

import {http} from 'http'
import {h, render, useResource} from 'dyo'

function Example (props) {
    const resource = useResource(props => fetch('https://reqres.in/api/users'))
    return h('pre', {}, JSON.stringify(resource))
}

http.createServer((request, response) => {
    return render(h('html', {}, h(Example)), response)
}).listen(8080)

License

Dyo is MIT licensed.

Extension points exported contracts — how you extend this code

Interface (Interface)
(no doc)
typings/index.d.ts
Attributes (Interface)
(no doc)
typings/index.d.ts
Handler (Interface)
(no doc)
typings/index.d.ts
Exception (Interface)
(no doc)
typings/index.d.ts
Component (Interface)
(no doc)
typings/index.d.ts

Core symbols most depended-on inside this repo

render
called by 450
src/Render.js
memo
called by 31
src/Component.js
lazy
called by 16
src/Suspense.js
dispatch
called by 15
src/Hook.js
callback
called by 11
src/Hook.js
update
called by 7
src/Reconcile.js
resolve
called by 5
src/Schedule.js
compare
called by 4
src/Hook.js

Shape

Function 214
Interface 18
Class 2
Method 1

Languages

TypeScript100%

Modules by API surface

src/Interface.js23 symbols
src/Utility.js21 symbols
src/Element.js20 symbols
typings/index.d.ts18 symbols
src/Schedule.js17 symbols
src/Hook.js16 symbols
src/Children.js13 symbols
src/Component.js12 symbols
src/Exception.js11 symbols
src/Commit.js11 symbols
script/setup.js10 symbols
src/Suspense.js9 symbols

For agents

$ claude mcp add dyo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact