1
說我有一些模型,動作設置和更新功能如下:的startApp的模型和效果在榆樹
type alias Model = Int
type Action = Succ
update : Action
-> Model
-> (Model, Effects Action)
update action model =
case action of
Succ ->
(model+1
, Effects.task <| Task.succeed Succ
)
這顯然會旋轉無限循環進入地獄,但我需要知道關鍵細節:請問任務引發的動作是否看到model+1
版本(例如這個任務會激發「下一個」模型),還是將並行運行到當前模型版本,model
?實質上,將StartApp
存儲在之前的元組左邊的模型中,運行效果以獲得新的Action?
我之所以問這個,是我從這個簡單的反跳。我已經寫獲取日誌:http://lpaste.net/160866
當我使用這個模塊,我專門在模型中設定debounceBounce = True
當我火花循環:
type alias AppModel =
{ appDebouncer : DebounceModel
}
type AppAction
= DebounceAction DebounceAction
| Finished
| Start
updateAppAction : AppAction
-> AppModel
-> (AppModel, Effects AppAction)
updateAppAction action model =
case action of
DebounceAction a ->
let (newDebounce, eff) =
updateDebounce Finished a model.appDebounce
in ({ model | appDebounce = newDebounce }
, Effects.tick (handleContinue DebounceAction) eff
)
Start ->
({ model | appDebounce =
let debouncer = model.appDebounce
in { debouncer | debounceBounce = True }
}
, Effects.tick (DebounceAction << Tick)
)
-- ...
我發現我的機器上很多日誌,這些日誌特別顯示,在環路初始模型不有debounceBounce = True
集。這是否有明確的理由?
在這一行中,這個2元組有一個無用的第二個參數:https://github.com/evancz/start-app/blob/master/src/StartApp.elm#L100 爲什麼那裏竟然存在? '效果'只是把它整合到IO中嗎? –
該元組中的Effects值被丟棄,因爲它正在被(將會變成)[行116]中的'tasks'端口處理(https://github.com/evancz/start-app/blob/master/src /StartApp.elm#L116)。 –