Rename to expand component
This commit is contained in:
parent
7a697a1c05
commit
56c51ee0f8
2 changed files with 21 additions and 21 deletions
|
@ -4,7 +4,7 @@
|
||||||
#:element-props
|
#:element-props
|
||||||
#:element-children
|
#:element-children
|
||||||
#:create-element
|
#:create-element
|
||||||
#:expand))
|
#:expand-component))
|
||||||
(in-package #:hsx/element)
|
(in-package #:hsx/element)
|
||||||
|
|
||||||
;;;; class definitions
|
;;;; class definitions
|
||||||
|
@ -61,22 +61,11 @@
|
||||||
|
|
||||||
(defmethod create-element-hook ((elm component-element))
|
(defmethod create-element-hook ((elm component-element))
|
||||||
;dry-run to validate props
|
;dry-run to validate props
|
||||||
(expand elm))
|
(expand-component elm))
|
||||||
|
|
||||||
|
|
||||||
;;;; methods
|
;;;; 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)
|
(defmethod print-object ((elm tag-element) stream)
|
||||||
(with-accessors ((type element-type)
|
(with-accessors ((type element-type)
|
||||||
(props element-props)
|
(props element-props)
|
||||||
|
@ -117,4 +106,15 @@
|
||||||
children))))
|
children))))
|
||||||
|
|
||||||
(defmethod print-object ((elm component-element) stream)
|
(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))))
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
(test tag-element
|
(test tag-element
|
||||||
(let ((elm (create-element "p"
|
(let ((elm (create-element "p"
|
||||||
'(:class "red")
|
'(:class "red")
|
||||||
"Hello,"
|
"Hello,"
|
||||||
"World")))
|
"World")))
|
||||||
(is (string= (element-type elm) "p"))
|
(is (string= (element-type elm) "p"))
|
||||||
(is (equal (element-props elm) '(:class "red")))
|
(is (equal (element-props elm) '(:class "red")))
|
||||||
(is (equal (element-children elm) (list "Hello," "World")))))
|
(is (equal (element-children elm) (list "Hello," "World")))))
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
(let* ((elm (create-element #'comp1
|
(let* ((elm (create-element #'comp1
|
||||||
'(:title "foo")
|
'(:title "foo")
|
||||||
"bar"))
|
"bar"))
|
||||||
(expanded (expand elm)))
|
(expanded (expand-component elm)))
|
||||||
(is (eql (element-type elm) #'comp1))
|
(is (eql (element-type elm) #'comp1))
|
||||||
(is (equal (element-props elm) '(:title "foo")))
|
(is (equal (element-props elm) '(:title "foo")))
|
||||||
(is (equal (element-children elm) (list "bar")))
|
(is (equal (element-children elm) (list "bar")))
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
(let* ((elm (create-element #'comp2
|
(let* ((elm (create-element #'comp2
|
||||||
'(:title "foo")
|
'(:title "foo")
|
||||||
"bar"))
|
"bar"))
|
||||||
(expanded (expand elm)))
|
(expanded (expand-component elm)))
|
||||||
(is (eql (element-type elm) #'comp2))
|
(is (eql (element-type elm) #'comp2))
|
||||||
(is (equal (element-props elm) '(:title "foo")))
|
(is (equal (element-props elm) '(:title "foo")))
|
||||||
(is (equal (element-children elm) (list "bar")))
|
(is (equal (element-children elm) (list "bar")))
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
(let* ((elm (create-element #'comp3
|
(let* ((elm (create-element #'comp3
|
||||||
'(:title "foo" :other-key "baz")
|
'(:title "foo" :other-key "baz")
|
||||||
"bar"))
|
"bar"))
|
||||||
(expanded (expand elm)))
|
(expanded (expand-component elm)))
|
||||||
(is (eql (element-type elm) #'comp3))
|
(is (eql (element-type elm) #'comp3))
|
||||||
(is (equal (element-props elm) '(:title "foo" :other-key "baz")))
|
(is (equal (element-props elm) '(:title "foo" :other-key "baz")))
|
||||||
(is (equal (element-children elm) (list "bar")))
|
(is (equal (element-children elm) (list "bar")))
|
||||||
|
|
Loading…
Reference in a new issue