Rename kind to type
This commit is contained in:
parent
803b9add14
commit
42a0828f89
2 changed files with 13 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
|||
(defpackage #:hsx/element
|
||||
(:use #:cl)
|
||||
(:export #:element-kind
|
||||
(:export #:element-type
|
||||
#:element-props
|
||||
#:element-children
|
||||
#:create-element
|
||||
|
@ -8,9 +8,9 @@
|
|||
(in-package #:hsx/element)
|
||||
|
||||
(defclass element ()
|
||||
((kind
|
||||
:reader element-kind
|
||||
:initarg :kind)
|
||||
((type
|
||||
:reader element-type
|
||||
:initarg :type)
|
||||
(props
|
||||
:reader element-props
|
||||
:initarg :props)
|
||||
|
@ -18,18 +18,18 @@
|
|||
:reader element-children
|
||||
:initarg :children)))
|
||||
|
||||
(defun create-element (kind props &rest children)
|
||||
(defun create-element (type props &rest children)
|
||||
(make-instance 'element
|
||||
:kind kind
|
||||
:type type
|
||||
:props props
|
||||
:children (flatten children)))
|
||||
|
||||
(defmethod expand ((elm element))
|
||||
(with-accessors ((kind element-kind)
|
||||
(with-accessors ((type element-type)
|
||||
(props element-props)
|
||||
(children element-children)) elm
|
||||
(if (functionp kind)
|
||||
(apply kind (append props
|
||||
(if (functionp type)
|
||||
(apply type (append props
|
||||
(and children
|
||||
(list :children children))))
|
||||
elm)))
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
nil
|
||||
"Hello,"
|
||||
inner)))
|
||||
(is (string= (element-kind inner) "span"))
|
||||
(is (string= (element-type inner) "span"))
|
||||
(is (equal (element-props inner) `(:class "red")))
|
||||
(is (equal (element-children inner) (list "World!")))
|
||||
(is (string= (element-kind outer) "p"))
|
||||
(is (string= (element-type outer) "p"))
|
||||
(is (null (element-props outer)))
|
||||
(is (equal (element-children outer) (list "Hello," inner)))))
|
||||
|
||||
|
@ -44,10 +44,10 @@
|
|||
(outer (create-element #'comp
|
||||
'(:variant "red")
|
||||
inner)))
|
||||
(is (eql (element-kind outer) #'comp))
|
||||
(is (eql (element-type outer) #'comp))
|
||||
(is (equal (element-props outer) `(:variant "red")))
|
||||
(is (equal (element-children outer) (list inner)))
|
||||
(let ((expanded-elm (expand outer)))
|
||||
(is (string= (element-kind expanded-elm) "p"))
|
||||
(is (string= (element-type expanded-elm) "p"))
|
||||
(is (equal (element-props expanded-elm) `(:class "red")))
|
||||
(is (equal (element-children expanded-elm) (list "Hello," inner)))))))
|
||||
|
|
Loading…
Reference in a new issue