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
|
(defpackage #:hsx/element
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:export #:element-kind
|
(:export #:element-type
|
||||||
#:element-props
|
#:element-props
|
||||||
#:element-children
|
#:element-children
|
||||||
#:create-element
|
#:create-element
|
||||||
|
@ -8,9 +8,9 @@
|
||||||
(in-package #:hsx/element)
|
(in-package #:hsx/element)
|
||||||
|
|
||||||
(defclass element ()
|
(defclass element ()
|
||||||
((kind
|
((type
|
||||||
:reader element-kind
|
:reader element-type
|
||||||
:initarg :kind)
|
:initarg :type)
|
||||||
(props
|
(props
|
||||||
:reader element-props
|
:reader element-props
|
||||||
:initarg :props)
|
:initarg :props)
|
||||||
|
@ -18,18 +18,18 @@
|
||||||
:reader element-children
|
:reader element-children
|
||||||
:initarg :children)))
|
:initarg :children)))
|
||||||
|
|
||||||
(defun create-element (kind props &rest children)
|
(defun create-element (type props &rest children)
|
||||||
(make-instance 'element
|
(make-instance 'element
|
||||||
:kind kind
|
:type type
|
||||||
:props props
|
:props props
|
||||||
:children (flatten children)))
|
:children (flatten children)))
|
||||||
|
|
||||||
(defmethod expand ((elm element))
|
(defmethod expand ((elm element))
|
||||||
(with-accessors ((kind element-kind)
|
(with-accessors ((type element-type)
|
||||||
(props element-props)
|
(props element-props)
|
||||||
(children element-children)) elm
|
(children element-children)) elm
|
||||||
(if (functionp kind)
|
(if (functionp type)
|
||||||
(apply kind (append props
|
(apply type (append props
|
||||||
(and children
|
(and children
|
||||||
(list :children children))))
|
(list :children children))))
|
||||||
elm)))
|
elm)))
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
nil
|
nil
|
||||||
"Hello,"
|
"Hello,"
|
||||||
inner)))
|
inner)))
|
||||||
(is (string= (element-kind inner) "span"))
|
(is (string= (element-type inner) "span"))
|
||||||
(is (equal (element-props inner) `(:class "red")))
|
(is (equal (element-props inner) `(:class "red")))
|
||||||
(is (equal (element-children inner) (list "World!")))
|
(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 (null (element-props outer)))
|
||||||
(is (equal (element-children outer) (list "Hello," inner)))))
|
(is (equal (element-children outer) (list "Hello," inner)))))
|
||||||
|
|
||||||
|
@ -44,10 +44,10 @@
|
||||||
(outer (create-element #'comp
|
(outer (create-element #'comp
|
||||||
'(:variant "red")
|
'(:variant "red")
|
||||||
inner)))
|
inner)))
|
||||||
(is (eql (element-kind outer) #'comp))
|
(is (eql (element-type outer) #'comp))
|
||||||
(is (equal (element-props outer) `(:variant "red")))
|
(is (equal (element-props outer) `(:variant "red")))
|
||||||
(is (equal (element-children outer) (list inner)))
|
(is (equal (element-children outer) (list inner)))
|
||||||
(let ((expanded-elm (expand outer)))
|
(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-props expanded-elm) `(:class "red")))
|
||||||
(is (equal (element-children expanded-elm) (list "Hello," inner)))))))
|
(is (equal (element-children expanded-elm) (list "Hello," inner)))))))
|
||||||
|
|
Loading…
Reference in a new issue