aboutsummaryrefslogtreecommitdiff
path: root/src/rx.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/rx.ts')
-rw-r--r--src/rx.ts34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/rx.ts b/src/rx.ts
index 5028ec1..ea4f6a4 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -1,14 +1,16 @@
+// Rx 1.0.1
+
// Html
export type Html
- = false
- | undefined
- | string
- | number
- | Tag
- | WithVar<any>
+ = false
+ | undefined
+ | string
+ | number
+ | Tag
+ | WithState<any>
| Array<Html>
- | Rx<Html>
+ | Rx<Html>
interface Tag {
type: 'Tag'
@@ -19,8 +21,8 @@ interface Tag {
onunmount?: (element: Element) => void
}
-interface WithVar<A> {
- type: 'WithVar'
+interface WithState<A> {
+ type: 'WithState'
init: A
getChildren: (v: Var<A>) => Html
}
@@ -40,8 +42,8 @@ type AttributeValue
function isHtml(x: any): x is Html {
return (typeof x === 'string'
|| typeof x === 'number'
- || isTag(x)
- || isWithVar(x)
+ || isTag(x)
+ || isWithState(x)
|| isRx(x)
|| Array.isArray(x))
}
@@ -88,9 +90,9 @@ export function h(
}
}
-export function withVar<A>(init: A, getChildren: (v: Var<A>) => Html): WithVar<A> {
+export function withState<A>(init: A, getChildren: (v: Var<A>) => Html): WithState<A> {
return {
- type: 'WithVar',
+ type: 'WithState',
init,
getChildren
}
@@ -322,7 +324,7 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No
remove: () => element.removeChild(childElement),
lastAdded: childElement,
}
- } else if (isWithVar(child)) {
+ } else if (isWithState(child)) {
const { init, getChildren } = child
const v = state.register(init)
const children = getChildren(v)
@@ -374,8 +376,8 @@ function isTag<A>(x: any): x is Tag {
return x !== undefined && x.type === "Tag"
}
-function isWithVar<A>(x: any): x is WithVar<A> {
- return x !== undefined && x.type === "WithVar"
+function isWithState<A>(x: any): x is WithState<A> {
+ return x !== undefined && x.type === "WithState"
}
function appendNode(base: Element, node: Node, lastAdded?: Node) {