[elm-discuss] Re: Task Composition Problem

2016-09-03 Thread Max Goldstein
As long as you want the time the HTTP request was sent, not the time the 
response was received, this is a correct solution.

If you want time of response, you need to fire Time.now in the callback, 
basically switching the order. 

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Task Composition Problem

2016-09-03 Thread Bryan Murphy
I'm struggling to compose two tasks.  Specifically, I'm making an HTTP
request, but I also want to know the time the http request was executed.

I have the following code:

type Msg =
Refresh
  | Success Time Documents
  | Failed Time Http.Error

requestDocuments : Cmd Msg
requestDocuments =
  Task.perform (Failed 0) (Success 0) <| httpInvoke documentsDecoder
"/collections/dashboard-alerts/keys"

httpInvoke : JsonDecode.Decoder value -> String -> Task.Task Http.Error
value
httpInvoke decoder path =
  let
request = {
  verb = "GET",
  headers = [ ("Authorization", "Basic SNIP") ],
  url = ("https://SNIP/1; ++ path),
  body = Http.empty
}
  in
Http.fromJson decoder <| Http.send Http.defaultSettings request

You can see I'm trying generate the Success/Failed messages that both
should include a time but for the moment I'm simply injecting a value of
zero.

It seems like I should use Task.andThen or Task.map or something similar to
compose httpInvoke with Time.now, but I'm really struggling to pull this
together and tie it into Task.perform.

Could somebody help?

Thanks!
Bryan

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: When to use Dict vs. List?

2016-09-03 Thread Brian John Farrar
Confirm it works!
Interesting and helpful.Thanks.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: When to use Dict vs. List?

2016-09-03 Thread Janis Voigtländer
Let me try to answer that, though I don’t have the compiler at hand right
now for checking this code works exactly:

update msg ({ entries } as model) =
let
updateEntry =
case msg of
ToggleDone id ->
Dict.update id (Maybe.map (\({ done } as t) -> { t
| done = not done }))

UpdateTaskName id newTaskName ->
Dict.update id (Maybe.map (\t -> { t | name =
newTaskName }))
in
{ model | entries = updateEntry entries }

​

2016-09-03 16:11 GMT+02:00 Brian John Farrar :

> Thanks all for the responses.
>
> For:
> "Maybe.map doesn't appear useful as record updates aren't compose-able?)"
>
> I'll reformulate the question: What is the most factored version of the
> following code?
>
> update msg model =
> case msg of
> ToggleDone id ->
> let
> updateEntry t =
> case t of
> Nothing ->
> Nothing
>
> Just t ->
> Just { t | done = not t.done }
> in
> { model | entries = Dict.update id updateEntry
> model.entries }
>
> UpdateTaskName id newTaskName ->
> let
> updateEntry t =
> case t of
> Nothing ->
> Nothing
>
> Just t ->
> Just { t | name = newTaskName }
> in
> { model | entries = Dict.update id updateEntry
> model.entries }
>
>
>> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] When to use Dict vs. List?

2016-09-03 Thread Wouter In t Velt
List and Dict are good for different things:
If most of the interaction with the collection is getting and setting, adding 
and deleting items 1 at a time: go with Dict.
If most of the interaction is going over the list, including sorting, 
rendering, counting items etc: then go with List.

Todo's in the example at more or less in the middle. List is simpler, so that 
would most sense.

Not sure what you mean with:
" Maybe.map doesn't appear useful as record updates aren't compose-able?)" 

I think you can do something like:

{ model | myCollection = Dict.update key (Maybe.map <| itemUpdate newText) 
model.myCollection }

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Introduction and architecture advice for navigation and routing

2016-09-03 Thread Peter
Hello all,

I spent the past week inbetween projects so took the time to have a good 
look at Elm and its starting to look good apart from when I blink or have a 
coffee break and then it seems to have all fallen out of my head.
Maybe its age as my knees have gone as well...

As a bit of history, web work accounts for about 1/3 of our current 
business and over the years this has gone from:


   - *asp.net* - project went live in 2002 or so (initial development was 
   on the beta versions and tweaked slightly as the official release came out 
   and then modified again during the years)
  - This is still running but luckily I've not had to touch it for 
  years as it was doing some fancy things (at the time) with image 
processing
  - Chosen as at the time we did 80% windows desktop work so c# skills 
  in hand anyway
  - Looking back it was clunky and evil and that may still be the case 
  as I've not looked at any of the newer versions and now we only do 10% 
  windows based work
   - *Django* - reworked a couple of internal projects to this
  - Was ok for what we wanted although didnt use it for any paying 
  customer work
   - *Rails* - couple of internal projects and some proof of concept work 
   for customers
  - Not for me at the time
   - *Python/Tornado* - A lot of our back end json API work is  written in 
   this and was an easy step to using templates to return pages to the users
  - Python, whats not to like!
  - Quite a few projects written in this and quite a bit of in house 
  Python skills
   - *Angular 1* - In a bid to make a few of our apps more snappy
  - Quite enjoyed this and have a few large scale projects with heavy 
  back end db work and front end users interacting with maps
   - *React/Riot/Vue* - Looking for something a little more lightweight and 
   less "frameworky"
  - Have a few projects using Riot and quite happy with those
   - *Elm* - Ive not touched Lazy ML or Haskell wince way back when at Uni 
   and that still brings me out in a cold sweat.


Now I seem to have got on reasonably well over a few days and must have 
read just about everything I could get my hands on.
Written small test apps for json parsing and general language functionality 
which has gone OK but then I read too much and get myself in a pickle, 
especially in working out how to handle routing/navigation.

Seems I get really close and it all makes sense then it goes again :(

I've put together a simple "all code in one file" demo app here 


Its a simple app that has a main index screen with the option to show 2 
others - a list of people and then a specific person. Run of the mill stuff.
This was cobbled together from all the navigation/routing sample apps I 
found.

Theres a lot of debug lines in there to show what is being called and when.

I'm at a bit of a loss as to where to put the "doing" bit, for example:

>From the index screen the user would click on Show People and this message 
is processed in the updateMain function.
Here is where I should be getting the list of people (from a json call, or 
just returning a list to keep the demo simple) and storing this in the 
models People property?

Theres some navigation calls here to update the visible url and also set 
the current route in the model (Navigation.newUrl url)

This seems to call the view code twice when looking at the console logs?

Also, if the user enters a url from scratch (say, localhost:8000/#/users) 
then this would need to know to get the list of users.
I'm handling this via the init function to get the initial route entered 
and then set the state for that route but that looks like duplication of 
what the ShowPeople message would be doing.


Am I putting things in the wrong place here and going about things the 
wrong way?

Maybe it will all just click soon as I've got myself all tied up from 
reading too much.
Theres been moments of clarity where its all clear and I start thinking in 
the Elm way and its a great feeling!

Demo code 
 - this 
is run with a simple index.html file via *python -m SimpleHTTPServer *in 
case of any issues with # url parsing via elm-reactor.

Thanks, and as I've never said to the wife, apologies for length.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.