简体   繁体   中英

purescript halogen: Append IProp to HTML

Is there a way to append IProp 's to HTML ?

Here's an example of what i'm trying to do:

foo :: forall p i. H.HTML p i -> H.HTML p i
foo myElement = 
  addProp (HP.id_ "SomeId") myElement

Where addProp takes myElement , gives it the Id (or any other arbitrary property) and returns back this new element that is basically the same but has that new property added to it?

Or in other words, does this function addProp exist in some fashion?

It doesn't exist no, as if it were to do so, it'd bypass the typechecking of valid properties that can be set on a given element, plus it'd let you say nonsensical things like addProp on a HH.text value.

It's not impossible to write though, as the property checking stuff isn't an intrinsic part of the HTML representation - it's a layer on top that refines it. HTML is just made up of normal data types, so you can pattern match on HTML values to manipulate as needs be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM