Introduce elSpec a convenience function from reactix to thermite

parent 5f84dce1
...@@ -27,7 +27,7 @@ import React.DOM.Props (className, style) ...@@ -27,7 +27,7 @@ import React.DOM.Props (className, style)
import React.SyntheticEvent as E import React.SyntheticEvent as E
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Thermite (PerformAction, Render, Spec, createClass, defaultPerformAction, simpleSpec, modifyState_) import Thermite (Spec)
import URI.Extra.QueryPairs as QP import URI.Extra.QueryPairs as QP
import URI.Query as Q import URI.Query as Q
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
...@@ -188,12 +188,8 @@ treeLoadView setReload p = R.createElement el p [] ...@@ -188,12 +188,8 @@ treeLoadView setReload p = R.createElement el p []
loadedTreeView setReload {tree: loaded, mCurrentRoute} loadedTreeView setReload {tree: loaded, mCurrentRoute}
treeview :: Spec {} Props Void treeview :: Spec {} Props Void
treeview = simpleSpec defaultPerformAction render treeview = R2.elSpec $ R.hooksComponent "TreeView" cpt
where where
render :: Render {} Props Void
render _ props _ _ = [R2.scuff $ R.createElement el props []]
el = R.hooksComponent "TreeView" cpt
cpt {root, mCurrentRoute} _children = do cpt {root, mCurrentRoute} _children = do
-- NOTE: this is a hack to reload the tree view on demand -- NOTE: this is a hack to reload the tree view on demand
setReload <- R.useState' 0 setReload <- R.useState' 0
......
...@@ -17,6 +17,7 @@ import Reactix as R ...@@ -17,6 +17,7 @@ import Reactix as R
import Reactix.DOM.HTML (ElemFactory) import Reactix.DOM.HTML (ElemFactory)
import Reactix.React (createDOMElement) import Reactix.React (createDOMElement)
import Reactix.SyntheticEvent as RE import Reactix.SyntheticEvent as RE
import Thermite (Spec, simpleSpec, Render, defaultPerformAction)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
newtype Point = Point { x :: Number, y :: Number } newtype Point = Point { x :: Number, y :: Number }
...@@ -26,10 +27,18 @@ buff :: ReactElement -> R.Element ...@@ -26,10 +27,18 @@ buff :: ReactElement -> R.Element
buff = unsafeCoerce buff = unsafeCoerce
-- | Turns a Reactix Element into a ReactElement. -- | Turns a Reactix Element into a ReactElement.
-- | scuff (v.) to spoil the gloss or finish of. -- | scuff (v.) to spoil the gloss or finish of.
scuff :: R.Element -> ReactElement scuff :: R.Element -> ReactElement
scuff = unsafeCoerce scuff = unsafeCoerce
elSpec :: forall component props
. R.IsComponent component props (Array R.Element)
=> component -> Spec {} (Record props) Void
elSpec cpt = simpleSpec defaultPerformAction render
where
render :: Render {} (Record props) Void
render _ props _ children = [scuff $ R.createElement cpt props (buff <$> children)]
mousePosition :: RE.SyntheticEvent DE.MouseEvent -> Point mousePosition :: RE.SyntheticEvent DE.MouseEvent -> Point
mousePosition e = Point { x: RE.clientX e, y: RE.clientY e } mousePosition e = Point { x: RE.clientX e, y: RE.clientY e }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment