Rename to expand component

This commit is contained in:
paku 2024-05-27 16:03:23 +09:00
parent 7a697a1c05
commit 56c51ee0f8
2 changed files with 21 additions and 21 deletions

View file

@ -4,7 +4,7 @@
#:element-props
#:element-children
#:create-element
#:expand))
#:expand-component))
(in-package #:hsx/element)
;;;; class definitions
@ -61,22 +61,11 @@
(defmethod create-element-hook ((elm component-element))
;dry-run to validate props
(expand elm))
(expand-component elm))
;;;; methods
(defmethod expand ((elm component-element))
(with-accessors ((type element-type)
(props element-props)
(children element-children)) elm
(apply type (merge-children-into-props props children))))
(defun merge-children-into-props (props children)
(append props
(and children
(list :children children))))
(defmethod print-object ((elm tag-element) stream)
(with-accessors ((type element-type)
(props element-props)
@ -117,4 +106,15 @@
children))))
(defmethod print-object ((elm component-element) stream)
(print-object (expand elm) stream))
(print-object (expand-component elm) stream))
(defmethod expand-component ((elm component-element))
(with-accessors ((type element-type)
(props element-props)
(children element-children)) elm
(apply type (merge-children-into-props props children))))
(defun merge-children-into-props (props children)
(append props
(and children
(list :children children))))

View file

@ -9,9 +9,9 @@
(test tag-element
(let ((elm (create-element "p"
'(:class "red")
"Hello,"
"World")))
'(:class "red")
"Hello,"
"World")))
(is (string= (element-type elm) "p"))
(is (equal (element-props elm) '(:class "red")))
(is (equal (element-children elm) (list "Hello," "World")))))
@ -35,7 +35,7 @@
(let* ((elm (create-element #'comp1
'(:title "foo")
"bar"))
(expanded (expand elm)))
(expanded (expand-component elm)))
(is (eql (element-type elm) #'comp1))
(is (equal (element-props elm) '(:title "foo")))
(is (equal (element-children elm) (list "bar")))
@ -56,7 +56,7 @@
(let* ((elm (create-element #'comp2
'(:title "foo")
"bar"))
(expanded (expand elm)))
(expanded (expand-component elm)))
(is (eql (element-type elm) #'comp2))
(is (equal (element-props elm) '(:title "foo")))
(is (equal (element-children elm) (list "bar")))
@ -81,7 +81,7 @@
(let* ((elm (create-element #'comp3
'(:title "foo" :other-key "baz")
"bar"))
(expanded (expand elm)))
(expanded (expand-component elm)))
(is (eql (element-type elm) #'comp3))
(is (equal (element-props elm) '(:title "foo" :other-key "baz")))
(is (equal (element-children elm) (list "bar")))