相关疑难解决方法(0)

Elm 0.17:如何订阅兄弟/嵌套组件更改

请参阅完整实施,并在此处提供已接受答案的建议:https://github.com/afcastano/elm-nested-component-communication

================================================== ===============

我有一个父组件有两个孩子.见工作示例

使用Elm Architecture,当左侧孩子的任何计数器发生变化时,如何更新正确的孩子?

目前,我让父组件读取左子模型的嵌套属性并将其设置为正确的子模型,但在我看来,父母不应该对子项的内部结构了解太多.

这些是模型和消息:

type alias MainModel =
  { counterPair : CounterPair
  , totals: Totals
  }

type alias CounterPair =
  {
    greenCounter : Counter
  , redCounter : Counter
  }

type alias Counter =
  {
    value : Int
  , totalClicks : Int  
  }

type alias Totals =
  {
    totalRed : Int
  , totalGreen : Int
  , combinedTotal : Int
  }

type MainMsg
  =  UpdateCounterPair CounterPairMsg
  |  UpdateTotals TotalsMsg


type alias RedVal = Int …
Run Code Online (Sandbox Code Playgroud)

architecture frontend elm

2
推荐指数
1
解决办法
1578
查看次数

标签 统计

architecture ×1

elm ×1

frontend ×1