Help me understand Window.dimensions

83 views
Skip to first unread message

Birowsky

unread,
Jan 12, 2016, 7:09:26 PM1/12/16
to Elm Discuss
When i use Window.dimensions like this:

main = Signal.map show Window.dimensions


I instantly get (1381,812) which is sweet.

However, when I pass it through a complete MVU pattern with:



main = Signal.map view stateSignal

view state = show state

stateSignal = Signal.foldp update initialState input

input =
  Signal.mergeMany [
    Signal.map WindowSize Window.dimensions,
    Signal.map MousePosition mousePosition ]




It starts with (0,0). I need to resize the browser in order for the Window.dimensions to emit a new value.


Why? 

Where does the initial signalled value get lost?

Laszlo Pandy

unread,
Jan 12, 2016, 7:33:29 PM1/12/16
to elm-d...@googlegroups.com
All signals have an initial state, and then updates which come later.
Foldp is one of those functions which ignores the initial state of the signal passed to it, because you have already given it an initialState argument.
There is another function foldp' available in a library, which uses the initial value:

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Birowsky

unread,
Jan 12, 2016, 7:42:55 PM1/12/16
to Elm Discuss
U da man

Birowsky

unread,
Jan 12, 2016, 9:37:20 PM1/12/16
to Elm Discuss
Can you help me understand how is foldp` it used?

This is how i use foldp: 

Signal.foldp update initialState input

But i noticed foldp' is expecting a function as second argument. That part i don't understand. What function is it?



On Wednesday, January 13, 2016 at 1:33:29 AM UTC+1, Laszlo Pandy wrote:

Peter Damoc

unread,
Jan 13, 2016, 4:47:38 AM1/13/16
to Elm Discuss
You need a function that will use the initial value of the input to produce the initial value of the output. 

Signal.foldp' update (\a -> update a initialState) input 




--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

Birowsky

unread,
Jan 13, 2016, 6:13:07 AM1/13/16
to Elm Discuss
And suddenly, it works. 
Thanx again. 
And expect to be bothered some more :}
Reply all
Reply to author
Forward
0 new messages