a small javascript front end framework
mkdir myapp
cd myapp
npm init small-cup@latest
enum DOMType { static dynamic }
type DOM {
node: HTMLNode
children: [DOM]
map: {[String]: DOM}
type: DOMType
root: Boolean
update: () => {}
unload: () => {}
}
type Component {
template: String
onload: (el: HTMLNode, ctx: Object, rootDom: DOM) => undefined | Component
components: {[key: String]: Component}
}
type ElementVNodeData {
tag: String
props: Object
children: undefined | [ChildVNode]
}
type TextVNodeData = String
type VNodeData = ElementVNodeData | TextVNodeData
enum VNodeType { element text }
type VNode {
type: VNodeType
data: VNodeData
}
type ChildVNode = String | VNode
render vnode to root with context
render vnode to root with context when window.onpopstate triggerd
patch or create HTMLNode
<script type="module">
import { render, mount, h } from 'https://unpkg.com/small-cup/index.js'
</script>
npm i small-cup
npm start
MIT