mikesol / purescript-deku

A PureScript web UI framework
https://purescript-deku.surge.sh/
Apache License 2.0
123 stars 12 forks source link

Make dynamic elements context-aware & compositional #34

Closed MonoidMusician closed 1 year ago

MonoidMusician commented 2 years ago

Currently, the dynamic elements like envy, dyn, switcher are not compositional because they insert nodes into their parent without regard to what other children would be there. This means they always end up after the other children:

bussed \p e ->
  D.span_
    [ switcher
          (if _ then text_ "Mysteriously after" else text_ "Obviously before")
          (bang false <|> true <$ e)
    , D.button
        (bang (D.OnClick := p unit))
        [ text_ "Misplace" ]
    ]

(Similar issue with envy $ map instead of switcher, and similar issues with dyn, &c. And it gets worse if D.span_ is replaced with fixed – then it even leaks into the parent of the above bussed node.)

We need to find a way to make them context-aware, probably by tracking how many children come before and after them (dynamically, since it may change with other nodes).

mikesol commented 2 years ago

If we insert an empty element, ie <input type="hidden" value="fooooo"/> every time a dyn is created, then we can grab that element and use it as a reference for all child insert/delete/move operations.

mikesol commented 1 year ago

Fixed now that Domable is a monoid.