【发布时间】:2015-12-20 11:26:52
【问题描述】:
我正在尝试使用当前日期初始化我的模型。我不想使用本机模块。我正在尝试使用任务和效果来做到这一点。我被我的getCurrentTime 方法困住了。最干净的方法是什么?
import Time exposing ( Time )
import StartApp
import Task
import Effects exposing (Never)
import Html exposing ( Html )
app =
StartApp.start
{ init = init
, view = view
, update = update
, inputs = []}
main =
app.html
port tasks : Signal (Task.Task Never ())
port tasks =
app.tasks
type alias Model =
{ clock : Time}
init : (Model, Effects.Effects Action)
init = ((Model ), Effects.none)
type Action = ShowClock
update : Action -> Model -> (Model, Effects.Effects Action)
update action model =
case action of
ShowClock c ->
({ model | clock = c}, Effects.none)
getCurrentTime : Effects.Effects Action
getCurrentTime =
-- stuck here
|> Task.map ShowClock
|> Effects.task
view : Signal.Address Action -> Model -> Html
view address model =
Signal.map Html.text model.clock
将时间转换为“YYYY-MM-DD”格式的字符串也不错。
【问题讨论】: