From 8764c628d32e3e0bcb9f819d384df4761dbc060a Mon Sep 17 00:00:00 2001
From: Joris
Date: Tue, 8 Apr 2025 09:17:33 +0200
Subject: Allow using null
---
 src/rx.ts | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
(limited to 'src')
diff --git a/src/rx.ts b/src/rx.ts
index 48db4fd..9884de8 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -5,6 +5,7 @@
 export type Html
   = false
   | undefined
+  | null
   | string
   | number
   | Tag
@@ -68,6 +69,7 @@ interface Attributes {
 
 type AttributeValue
   = undefined
+  | null
   | string
   | number
   | boolean
@@ -93,7 +95,7 @@ export function h(
   x?: Attributes | Html,
   ...children: Array
 ): Tag {
-  if (x === undefined || x === false) {
+  if (x === undefined || x == null || x === false) {
     return {
       type: 'Tag',
       tagName,
@@ -411,7 +413,7 @@ function rxRun(
 }
 
 function isRx(x: any): x is Rx {
-  return x !== undefined && x.type !== undefined && (x.type === "Var" || x.type === "Map" || x.type === "FlatMap" || x.type === 'Sequence' || x.type === 'Pure')
+  return x != null && x.type !== undefined && (x.type === "Var" || x.type === "Map" || x.type === "FlatMap" || x.type === 'Sequence' || x.type === 'Pure')
 }
 
 function isPure(x: any): x is Pure {
@@ -646,7 +648,7 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No
       },
       lastAdded: appendRes.lastAdded,
     }
-  } else if (child === undefined || child === false) {
+  } else if (!child) {
     return {
       cancel: voidCancel,
       remove: voidRemove,
@@ -663,31 +665,31 @@ function isSvg(tagName: string): boolean {
 }
 
 function isTag(x: any): x is Tag {
-  return x !== undefined && x.type === "Tag"
+  return x != null && x.type === "Tag"
 }
 
 function isWithState(x: any): x is WithState {
-  return x !== undefined && x.type === "WithState"
+  return x != null && x.type === "WithState"
 }
 
 function isWithState2(x: any): x is WithState2 {
-  return x !== undefined && x.type === "WithState2"
+  return x != null && x.type === "WithState2"
 }
 
 function isWithState3(x: any): x is WithState3 {
-  return x !== undefined && x.type === "WithState3"
+  return x != null && x.type === "WithState3"
 }
 
 function isWithState4(x: any): x is WithState4 {
-  return x !== undefined && x.type === "WithState4"
+  return x != null && x.type === "WithState4"
 }
 
 function isWithState5(x: any): x is WithState5 {
-  return x !== undefined && x.type === "WithState5"
+  return x != null && x.type === "WithState5"
 }
 
 function isWithState6(x: any): x is WithState6 {
-  return x !== undefined && x.type === "WithState6"
+  return x != null && x.type === "WithState6"
 }
 
 function appendNode(base: Element, node: Node, lastAdded?: Node) {
-- 
cgit v1.2.3