Created
December 6, 2015 11:38
-
-
Save pkamenarsky/259eafb9cc37ce65a59f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
{-| The main module | |
@docs main | |
-} | |
import Html exposing (Html, div, button, text) | |
import Html.Attributes as Html exposing (style) | |
import Html.Events exposing (onClick) | |
import StartApp as StartApp | |
import Task | |
import Effects as Fx exposing (Effects, Never) | |
-- THIS IS THE COMPONENT ------------------------------------------------------- | |
type DatepickerAction = NoOp | Press | |
type alias DatepickerModel = { isPressed : Bool } | |
emptyDatepickerModel = { isPressed = False } | |
datepickerInit : (DatepickerModel, Effects DatepickerAction) | |
datepickerInit = (emptyDatepickerModel, Fx.none) | |
datepickerView : DatepickerModel -> Signal.Address DatepickerAction -> Html | |
datepickerView model address = div | |
[ style [("width", "100px"), ("height", "100px"), ("backgroundColor", "#ccc")] | |
, onClick address Press ] | |
[ Html.text <| toString model.isPressed ] | |
datepickerUpdate : DatepickerAction -> DatepickerModel -> (DatepickerModel, Effects DatepickerAction) | |
datepickerUpdate action model = case action of | |
NoOp -> ( model, Fx.none ) | |
Press -> ( { model | isPressed = True }, Fx.none ) | |
-- THIS IS AUTOGENERATED ------------------------------------------------------- | |
componentsMailbox : Signal.Mailbox ComponentActions | |
componentsMailbox = Signal.mailbox NoOpAction | |
componentAddressFor = Signal.forwardTo componentsMailbox.address | |
type alias Components = { datepicker : DatepickerModel } | |
type ComponentActions = NoOpAction | ComponentDatepickerAction DatepickerAction | |
initComponents : (Components, Effects ComponentActions) | |
initComponents = let (datepickerModel, datepickerFx) = datepickerInit in | |
( { datepicker = datepickerModel | |
} | |
, Fx.batch | |
[ Fx.map ComponentDatepickerAction datepickerFx | |
] | |
) | |
updateComponents : ComponentActions -> Components -> (Components, Effects ComponentActions) | |
updateComponents action model = case action of | |
ComponentDatepickerAction action' -> let (model', fx') = datepickerUpdate action' model.datepicker | |
in ({model | datepicker = model'}, Fx.map ComponentDatepickerAction fx') | |
NoOpAction -> (model, Fx.none) | |
-- MAIN ------------------------------------------------------------------------ | |
port tasks : Signal (Task.Task Never ()) | |
port tasks = app.tasks | |
app : StartApp.App Model | |
app = StartApp.start { view = view, update = update, init = init, inputs = {- THIS NEEDS TO BE ADDED -} [Signal.map C componentsMailbox.signal] } | |
{-| Main -} | |
main : Signal Html | |
main = app.html | |
init : (Model, Effects Action) | |
init = let (cm, fx) = initComponents in | |
( | |
{ counter = 0 | |
{- THIS NEEDS TO BE ADDED -} | |
, components = cm | |
} , Fx.map C fx | |
) | |
type alias Model = { counter : Int, components : Components } | |
view : Signal.Address Action -> Model -> Html | |
view address model = | |
div [] | |
[ button [ onClick address Decrement ] [ text "-" ] | |
, div [] [ text (toString model) ] | |
, datepickerView model.components.datepicker (componentAddressFor ComponentDatepickerAction) | |
, button [ onClick address Increment ] [ text "+" ] | |
] | |
type Action = Increment | Decrement {- THIS NEEDS TO BE ADDED -} | C ComponentActions | |
update : Action -> Model -> (Model, Effects Action) | |
update action model = | |
case action of | |
Increment -> ( { model | counter = model.counter + 1 }, Fx.none ) | |
Decrement -> ( { model | counter = model.counter - 1 }, Fx.none ) | |
-- THIS NEEDS TO BE ADDED ------------------------------------------------------ | |
C action' -> let (model', fx') = updateComponents action' model.components | |
in ({model | components = model'}, Fx.map C fx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment