Delete create-element-hook
This commit is contained in:
parent
cc4b3e19c6
commit
fb53f6aa05
2 changed files with 10 additions and 37 deletions
|
@ -34,16 +34,14 @@
|
||||||
;;;; factory
|
;;;; factory
|
||||||
|
|
||||||
(defun create-element (type props &rest children)
|
(defun create-element (type props &rest children)
|
||||||
(let ((element (make-instance (cond ((functionp type) 'component)
|
(make-instance (cond ((functionp type) 'component)
|
||||||
((eq type :<>) 'fragment)
|
((eq type :<>) 'fragment)
|
||||||
((eq type :html) 'html-tag)
|
((eq type :html) 'html-tag)
|
||||||
((keywordp type) 'tag)
|
((keywordp type) 'tag)
|
||||||
(t (error "element-type must be either a keyword or a function.")))
|
(t (error "element-type must be either a keyword or a function.")))
|
||||||
:type type
|
:type type
|
||||||
:props props
|
:props props
|
||||||
:children (flatten children))))
|
:children (flatten children)))
|
||||||
(create-element-hook element)
|
|
||||||
element))
|
|
||||||
|
|
||||||
(defun flatten (x)
|
(defun flatten (x)
|
||||||
(labels ((rec (x acc)
|
(labels ((rec (x acc)
|
||||||
|
@ -54,16 +52,6 @@
|
||||||
(rec (cdr x) acc))))))
|
(rec (cdr x) acc))))))
|
||||||
(rec x nil)))
|
(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
|
;;;; methods
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,7 @@
|
||||||
(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")))
|
||||||
(is (eq (element-type expanded) :div))
|
(is (eq (element-type expanded) :div))
|
||||||
(is (equal (element-children expanded) (list "foo" "bar")))
|
(is (equal (element-children expanded) (list "foo" "bar")))))
|
||||||
(signals error
|
|
||||||
(create-element #'comp1
|
|
||||||
'(:title "foo" :other-key "baz")
|
|
||||||
"bar"))))
|
|
||||||
|
|
||||||
(defun comp2 (&rest props)
|
(defun comp2 (&rest props)
|
||||||
(create-element :div
|
(create-element :div
|
||||||
|
@ -71,13 +67,6 @@
|
||||||
children
|
children
|
||||||
(getf props :other-key)))
|
(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
|
(test component-accepting-keyword-args-and-property-list
|
||||||
(let* ((elm (create-element #'comp3
|
(let* ((elm (create-element #'comp3
|
||||||
'(:title "foo" :other-key "baz")
|
'(:title "foo" :other-key "baz")
|
||||||
|
@ -87,8 +76,4 @@
|
||||||
(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")))
|
||||||
(is (eq (element-type expanded) :div))
|
(is (eq (element-type expanded) :div))
|
||||||
(is (equal (element-children expanded) (list "foo" "bar" "baz")))
|
(is (equal (element-children expanded) (list "foo" "bar" "baz")))))
|
||||||
(signals error
|
|
||||||
(create-element #'comp4
|
|
||||||
'(:title "foo" :other-key "baz")
|
|
||||||
"bar"))))
|
|
Loading…
Reference in a new issue