From fb53f6aa055db71da86249588ca115c2218f0b8e Mon Sep 17 00:00:00 2001 From: paku Date: Wed, 29 May 2024 10:54:20 +0900 Subject: [PATCH] Delete create-element-hook --- src/element.lisp | 28 ++++++++-------------------- tests/element.lisp | 19 ++----------------- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/element.lisp b/src/element.lisp index 9740380..e4b4958 100644 --- a/src/element.lisp +++ b/src/element.lisp @@ -34,16 +34,14 @@ ;;;; factory (defun create-element (type props &rest children) - (let ((element (make-instance (cond ((functionp type) 'component) - ((eq type :<>) 'fragment) - ((eq type :html) 'html-tag) - ((keywordp type) 'tag) - (t (error "element-type must be either a keyword or a function."))) - :type type - :props props - :children (flatten children)))) - (create-element-hook element) - element)) + (make-instance (cond ((functionp type) 'component) + ((eq type :<>) 'fragment) + ((eq type :html) 'html-tag) + ((keywordp type) 'tag) + (t (error "element-type must be either a keyword or a function."))) + :type type + :props props + :children (flatten children))) (defun flatten (x) (labels ((rec (x acc) @@ -54,16 +52,6 @@ (rec (cdr x) acc)))))) (rec x nil))) -(defmethod create-element-hook ((element element))) - -(defmethod create-element-hook ((element fragment)) - (when (element-props element) - (error "Cannot pass props to fragment."))) - -(defmethod create-element-hook ((element component)) - ;dry-run to validate props - (expand-component element)) - ;;;; methods diff --git a/tests/element.lisp b/tests/element.lisp index ee04fe0..a58e4c7 100644 --- a/tests/element.lisp +++ b/tests/element.lisp @@ -41,11 +41,7 @@ (is (equal (element-props elm) '(:title "foo"))) (is (equal (element-children elm) (list "bar"))) (is (eq (element-type expanded) :div)) - (is (equal (element-children expanded) (list "foo" "bar"))) - (signals error - (create-element #'comp1 - '(:title "foo" :other-key "baz") - "bar")))) + (is (equal (element-children expanded) (list "foo" "bar"))))) (defun comp2 (&rest props) (create-element :div @@ -71,13 +67,6 @@ children (getf props :other-key))) -(defun comp4 (&rest props &key title children) - (create-element :div - nil - title - children - (getf props :other-key))) - (test component-accepting-keyword-args-and-property-list (let* ((elm (create-element #'comp3 '(:title "foo" :other-key "baz") @@ -87,8 +76,4 @@ (is (equal (element-props elm) '(:title "foo" :other-key "baz"))) (is (equal (element-children elm) (list "bar"))) (is (eq (element-type expanded) :div)) - (is (equal (element-children expanded) (list "foo" "bar" "baz"))) - (signals error - (create-element #'comp4 - '(:title "foo" :other-key "baz") - "bar")))) + (is (equal (element-children expanded) (list "foo" "bar" "baz"))))) \ No newline at end of file