purescript-turbine icon indicating copy to clipboard operation
purescript-turbine copied to clipboard

Support for a "list" function with mutable elements?

Open werner291 opened this issue 5 years ago • 0 comments

Hello!

Please see the following example:

module Main where

import Prelude

import Data.FunctorWithIndex (mapWithIndex)
import Data.String as String
import Data.Tuple (Tuple(..))
import Data.Tuple as Tuple
import Effect (Effect)
import Turbine ((</>))
import Turbine as T
import Turbine.HTML as TH

-- | The entry-point application component, whose primary function it is to switch around
-- | between the login / registration / main activities.
app :: T.Component {} {}
app = T.component \o -> do
    let 
      splitify :: String -> Array (Tuple Int String)
      splitify s = mapWithIndex (\i c -> Tuple i (String.singleton c)) (String.toCodePointArray s)
    (
      (TH.input {} `T.use` (\oo -> {the_string: oo.value}))
        </>
      (TH.ul {} (T.list (show >>> TH.text >>> TH.li {}) (splitify <$> o.the_string) Tuple.fst))
    ) `T.output` {}
    

main :: Effect Unit
main = T.runComponent "#mount" app

Once loaded, try typing in the text field, then editing the typed string. Notice how the list not a proper function of the input behavior.

The current signature of list (especially given the getKey parameter) would suggest that the individual components are updated as the list changes, but this currently only happens when the key itself changes. Especially to newcomers to FRP (like me), this is very confusing.

Proposed solution: Add a new function that provides a Behavior a instead of a a to the coponent generator function.

werner291 avatar Oct 12 '19 14:10 werner291