Sitelet https://github.com/purescript-concur/purescript-concur-react/issues/25
Skip to content

Question on signal updates: formless "child" signals lose state, others don't #25

Description

@bbarker

Sorry for the barrage of signal questions/issues lately, but I'd say this is my most pressing concern so far.

I have the following outer signal and helper function:

injectLocationFields ::
  Maybe M.InstitutionID ->
  Maybe String ->
  Maybe M.InstitutionType ->
  Maybe String ->
  Maybe M.InstitutionContact ->
  Maybe M.InstitutionSustainability ->
  Maybe (NonEmptyArray M.InstitutionPolicy) ->
  Boolean ->
  Maybe M.Location
injectLocationFields
  (Just institutionID)
  (Just institutionName)
  (Just institutionType)
  superOrganizationName
  (Just institutionContact)
  (Just institutionSustainability)
  (Just institutionPolicies)
  versioning = pure $ {
    institutionID: institutionID
  , institutionName: institutionName
  , institutionType: institutionType
  , superOrganizationName: superOrganizationName
  , institutionContact: institutionContact
  , institutionSustainability: institutionSustainability
  , institutionPolicies: institutionPolicies
  , versioning: versioning
  }
injectLocationFields _ _ _ _ _ _ _ _ = Nothing

accumulateLocation :: Maybe M.Location -> Signal HTML (Maybe M.Location)
accumulateLocation locMay = labelSig' D.h1' "Location" do
  identMay <- accumulateIdent "Identifier"
  instNameMay <- textInput D.span' "Institution Name: "
  display $ D.div' [D.text $ "Testing: " <> (show instNameMay)] -- FIXME: DEBUG
  instTypeMay <- labelSig' D.h3' "Institution Type" $ menuSignal Nothing
  display D.br'
  sOrgMay <- textInput D.span' "Super Organization (optional): "
  icMay <- contactSignalInit
  display $ D.div' [D.text $ "Contact" <> (show icMay)]  -- FIXME: DEBUG
  missionUrlMay <- urlInput D.span' "Mission Statement URL: "
  fundingUrlMay <- urlInput D.span' "Funding Statement URL: "
  sustainMay <- pure $ injectSustainFields missionUrlMay fundingUrlMay
  polsMay <- MF.policySigArray Nothing
  versioning <- labelSig' D.span' "versioning? " $ checkBoxS false
  newLocMay <- pure $ injectLocationFields
    identMay
    instNameMay
    instTypeMay
    sOrgMay
    icMay
    sustainMay
    polsMay
    versioning
  display $ locWidg
  pure newLocMay
  where
    contactSignalInit = MF.contactSignal Nothing
    locWidg :: forall a. Widget HTML a
    locWidg = D.div' [
      D.h3' [D.text "Last submitted location summary for this product:"]
    , D.br'
    , foldMap (\loc -> fold $ MV.spacify $ MV.locElems loc) locMay
    ]

The formless signals in this are contactSignal and policySigArray; contactSignal is simpler and is defined like this:

contactSignal :: Maybe M.InstitutionContact
  -> Signal HTML (Maybe M.InstitutionContact)
contactSignal instContactMay = labelSig' D.h2' "Institution Contact" $
  step instContactMay do
    inputs <- pure $ F.wrapInputFields $ outToInRec instContactMay
    instContact <- D.div' [
      contactForm (initFormState inputs validators)
    , foldMap contactWidg instContactMay
    ]
    pure $ contactSignal $ Just instContact

However, whenever I enter text into a non-formless signal, contactSignal resets and becomes Nothing. All other signals (aside from other formless signals) maintain their values.

An example of a signal that doesn't cause this issue is the textInput and derivative urlInput signals, also called from accumulateLocation:

textInput :: D.El' -> String -> Signal HTML (Maybe String)
textInput tag label = labelSig' tag label $ sig Nothing
  where
    sig :: Maybe String -> Signal HTML (Maybe String)
    sig txtMay = step txtMay do
      newTxt <- D.input [P.unsafeTargetValue <$> P.onChange]
      pure $ sig $ if newTxt == "" then Nothing else Just newTxt

The architecture of these signals seems to be much the same, except under the hood, contactSignal is using a concur-formless widget. Of course, Imay be missing something else important.

Here is the complete code at this commit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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