代码之家  ›  专栏  ›  技术社区  ›  sof

为什么不标记stateful属性lazy?

elm
  •  1
  • sof  · 技术社区  · 7 年前

    我们可以利用 Html.Lazy.lazy 精确标记 stateful element ,但不是像 Attribute.lazy 可以标记 stateful attribute . 这背后的理性是什么?

    type alias Model =
        { text : String, color : String }
    
    
    view model =
        div [ style "color" model.color ] 
            [ lazy text model.text ]
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   sof    7 年前

    阅读后 Elm lazy guide 再一次,我发现这是我自己对 Html.Lazy 真的很管用。下面显示如何标记模型,包括 stateful attribute .

    type alias Model =
        { txt : String, color : String }
    
    
    viewStateful txt color =
        div [ style "color" color ]
            [ text txt ]
    
    
    view model =
        lazy2 viewStateful model.txt model.color
    
    推荐文章