0

I am facing issue in taking Int value out of Window.dimensions's return val - Signal Int.

view : Signal.Address Action -> Model -> Html
view address model =
  let wx = Signal.map fst Window.dimensions 
      wy = Signal.map snd Window.dimensions  
  in fromElement <| container wx wy middle <| toElement  100 100 <|
      div []
        [ button [ onClick address Decrement ] [text "-"]
        ]

This line, wx = Signal.map fst Window.dimensions to get window container x-coordinates throws error as,

Type mismatch between the following types on line 30, column 31 to 33:
        Signal.Signal In
        Int
    It is related to the following expression:
        wx
glennsl
  • 28,186
  • 12
  • 57
  • 75

1 Answers1

2

Window.dimensions is a Signal (Int, Int). Mapping over it with fst or snd will give you a Signal Int which you can't just get "the value out of".

Your view shouldn't have Signal in it at all. It should just take some state in and return some Html. If you want to make a container that is the same dimensions as the screen, better to have your view function take the width/height and then map your view function over Window.dimensions. You can use this as an example.

robertjlooby
  • 7,160
  • 2
  • 33
  • 45
  • hey thanks robert.. but my main method code is based on `StartApp.Start` which takes `model, view, and update` arguments. the graphics example given by you is not based on a mvc pattern. I am wondering, even when i use `main = Signal.map` it will listen only to those `Window` signals and not to the user clicks... –  Jul 30 '15 at 12:47
  • If you want to start passing more arguments to your view then it sounds like your program may have outgrown `StartApp` :-P Time to write your own `main`! – robertjlooby Jul 30 '15 at 12:59
  • oops.. that is a bit sarcastic.. anways, my idea is to have an extra `action` as `resize` just like `increment`/`decrement` and trigger the action from `onresize` from inside the view function.... –  Jul 30 '15 at 13:05
  • You could put the screen dimensions in your model and and trigger updates the same way `increment`/`decrement` do, but you'd have to guess at the initial screen dimensions when initializing your model to pass to `StartApp.start`. So if the screen dimensions never changed, the view would never center – robertjlooby Jul 30 '15 at 14:02