From 56c51ee0f87dc55a9343d89878ad987c8a518b8c Mon Sep 17 00:00:00 2001 From: paku Date: Mon, 27 May 2024 16:03:23 +0900 Subject: [PATCH] Rename to expand component --- src/element.lisp | 28 ++++++++++++++-------------- tests/element.lisp | 14 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/element.lisp b/src/element.lisp index bd9b120..1ca6492 100644 --- a/src/element.lisp +++ b/src/element.lisp @@ -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)))) diff --git a/tests/element.lisp b/tests/element.lisp index 5c7f0c8..a0b8f7e 100644 --- a/tests/element.lisp +++ b/tests/element.lisp @@ -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"))) @@ -53,10 +53,10 @@ (getf props :children))) (test component-element-with-property-list - (let* ((elm (create-element #'comp2 + (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")))