Skip to content

Support for a "list" function with mutable elements? #10

@werner291

Description

@werner291

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions