[elm-discuss] Re: Catching error in fullscreen/App.programWithFlags

2016-10-15 Thread OvermindDL1
You will not be able to do that as Elm has its own scheduler that uses 
`setTimeout(0, ...)` to do the event loops, including the very first init, 
and that errors causes that event loop to die.  I'd probably recommend 
changing your flags to handle this case differently or you might be able to 
do it by setting up a port and messaging into it and maybe seeing if the 
port exists (if it does not exist it all then the app may not have loaded, 
I've not tested this to see 'when' the ports are setup in the setup but you 
could always have the program message back 'out' if it was successful, 
though I'd go with changing how the data is passed in).

On Saturday, October 15, 2016 at 11:20:11 AM UTC-6, Kevin Berridge wrote:
>
> I'm using App.programWithFlags to initialize the state of my model from 
> local storage (as described in this blog article 
> ).
>  
>  But when the schema of my model changes (ex: I added a new field to a 
> record type) it will correctly error out when Elm.Main.fullscreen is called 
> with error: "You are trying to initialize module `Main` with an unexpected 
> argument."
>
> I am OK with throwing away the state from local storage and starting from 
> scratch when this happens, so I tried to add a try catch in the JavaScript 
> but surprisingly (to me) the catch doesn't fire.
>
> try {
> elmApp = Elm.Main.fullscreen(startingState);
> }
> catch (e) {
> elmApp = Elm.Main.fullscreen(null); // this never gets called
> }
>
> Is there a way that I can catch this error?  Or do I need to use a 
> different approach?
>
> Thanks,
> Kevin
>

-- 
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: Html.Keyed

2016-10-15 Thread OvermindDL1
On Wednesday, October 12, 2016 at 5:32:09 AM UTC-6, Max Froumentin wrote:
>
> Thanks OvermindDL1, that's very helpful. I now understand it's down to the 
> lack of two-way binding. Makes sense.
> Wouldn't it be useful to use a change of id attribute as a change of key?
>

Yep, adding an attribute ID of some sort would make that 'more expected', 
and some vdom libraries do indeed do that (that I could link you to if you 
are curious at seeing the implementation).  :-) 

On Wednesday, October 12, 2016 at 9:59:47 AM UTC-6, Mark Hamburg wrote:
>
> On Oct 11, 2016, at 1:09 PM, OvermindDL1  wrote: 
> > 
> > And as for cocoa, unlike the DOM anytime something like, say a checkbox 
> is checked, cocoa sends a message to the application to handle the change, 
> if unhandled then no update would happen... and the app would be frozen as 
> the event loop would not be processing, unlike the DOM in a browser that 
> would just keep on puttering along even if no handlers for any events were 
> registered in javascript at all.  They are entirely different programming 
> domains. 
>
> Actually, no, with respect to Cocoa. If a Cocoa view sends out a message 
> that the value changed, the controller is not required or even expected to 
> echo that change back. The message can disappear into the aether and the 
> state will remain. (Caveat: It's been a while since I've coded against the 
> Cocoa APIs.) So, it is essentially an identical situation of there being 
> extra state that is tied to the existence of a Cocoa view object or a DOM 
> element.


This is indeed true that you do not need to handle it, however you still 
need to `pump` the message loop so, in elm terminology, it gets processed 
to the right effect manager (in reality when the message loop gets pumped 
anything listening to the messages can react as you wish, but you yourself 
still have to pump it, although that code is generally already set up for 
you via the normal scaffolds, but it is very explicit where elm is more 
implicit and magical). 

On Thursday, October 13, 2016 at 2:20:36 PM UTC-6, Rupert Smith wrote:

By making it keyed then it is like "oh, these do not match at all, probably 
> a major structural change, kill the old, create the new".
>

I have to admit I am not really sure how Html.Keyed works, so this is an 
illuminating discussion for me. Could you answer some basic questions about 
it for me?

If the 'key' of a keyed node is the same, is it never updated?
If 'key' of a keyed node changes, is the whole node built anew?

Or something else, please explain it to me, thanks.


In Elm if a 'keyed node'  is changed then it will diff as normal.  If a 
keyed node has an ID change then it tests the node before and after in the 
old version and shuffles around as necessary (only 1 at a time, larger 
jumps cause destroy/recreations), and if none nearby match then it entirely 
destroys or creates it as necessary.  I went a different route with my VDom 
but I'm still unsure about my style, though it does work well and gets rid 
of the keyed node and lazy node concepts in a larger singular super-node 
thing...

On Thursday, October 13, 2016 at 2:23:04 PM UTC-6, Rupert Smith wrote:

Some other questions relating to this.

I have a node that I changed an Html.Attribute.property on. The node had 2 
properties, but I only changed one. However, the node as a webcomponent 
fired triggered an observer on the other property that was not changed.

If I change just one property of a node, are all properties updated?

What about atttributes, if I change one attribute are all updated?


Uh, it should not do that I would think, sounds like a bug as an un-touched 
attribute should not be touched.  Unsure if Elm or the 
webcomponent-library-that-you-are-using kind of bug, but it sounds like a 
bug (I'd wager in the webcomponent polyfill you are using most likely, does 
sound weird...).

-- 
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] Catch Elm.Main.fullscreen "unexpected argument" error?

2016-10-15 Thread Peter Damoc
You can check for a version of the storage schema and patch the data before
sending it to Elm (or just drop it). In your case, you could also work with
the fact that you know that the new version has comments:


const storedState = localStorage.getItem('model');
var startingState = storedState ? JSON.parse(storedState) : null;
if (! "comment" in startingState) {
startingState = null;
}
try {
elmApp = Elm.Main.fullscreen(startingState);
}
catch (e) {
throw "it caught!";
}
elmApp.ports.setStorage.subscribe(function (state) {
  localStorage.setItem('model', JSON.stringify(state));
})



Alternatively, you could pass the data as Value in your program and use
multiple decoders to extract the data but that would be a little bit more
complicated.



On Thu, Oct 13, 2016 at 10:31 PM, Kevin Berridge  wrote:

> Is there a way to catch the "You are trying to initialize module `Main`
> with an unexpected argument." error when calling Elm.Main.fullscreen({})
> with out of date arguments?  I tried wrapping it in a try/catch, but the
> catch is not running.
>
> What I'm really trying to do is pass in state that was persisted in local
> storage as described here https://medium.com/wunder-
> nerds/storing-and-restoring-the-state-in-elm-0-17-94874429dc1d#.gmkt7hrwu.
> But I changed my model, so now it errors.  I'm happy to just forget the
> state and start over when that happens, so if I could catch the error in JS
> I could do that.
>
> Here's the JS I'm using.  The throw in that catch block doesn't run.
> 
> const storedState = localStorage.getItem('model');
> const startingState = storedState ? JSON.parse(storedState) : null;
> try {
> elmApp = Elm.Main.fullscreen(startingState);
> }
> catch (e) {
> throw "it caught!";
> }
> elmApp.ports.setStorage.subscribe(function (state) {
>   localStorage.setItem('model', JSON.stringify(state));
> })
> 
>
> And the JS error that is being thrown (but not being caught) is:
> Uncaught Error: You are trying to initialize module `Main` with an
> unexpected argument.
> When trying to convert it to a usable Elm value, I run into this problem:
>
> I ran into the following problems:
>
> Expecting null but instead got: {...}
> Expecting an object with a field named `comment` at _.distractions[4] but
> instead got: {...}
>
> I truncated the object properties in that message.  That error is correct,
> 'comment' was added to my elm model and therefore does not exist in the
> previously stored state that it is trying to deserialize.
>
> Thanks in advance,
> Kevin
>
> --
> 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.
>



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

-- 
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] Outgoing port event ordering

2016-10-15 Thread Peter Damoc
Cmd.batch does not make any guarantee about the order of execution. It is
use to bundle a batch of commands in one entity.

If you need order of execution, you need to use something lower level, like
Tasks where you have `andThen`.


On Thu, Oct 13, 2016 at 9:59 PM, David Andrews  wrote:

> When using Cmd.batch to send data over two ports, the ports receive the
> events in the same order regardless of the order in which they appear in
> the batch.  I would expect the events to occur in the order they appear in
> the batch.
>
> Working example: https://daviddta.github.io/elm-port-order-bug/
> Code: https://github.com/DavidDTA/elm-port-order-bug
> Looking at the console, we see that port one always receives the event
> before port two.
>
> As some motivation, consider two ports which both write to the same local
> storage key.  Without a guarantee on the ordering of events, the two
> subscriptions will race to write the key.
>
> --
> 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.
>



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

-- 
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] Re: Can I use css animations normally in elm?

2016-10-15 Thread Wouter In t Velt
Interesting! Having only discrete state in elm, with animations in CSS will 
definitely keep code simpler.

-- 
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] Properly using Task.perform with tasks that always succeed

2016-10-15 Thread Austin Bingham
Brilliant, thanks!

On Sat, Oct 15, 2016 at 8:06 PM Janis Voigtländer <
janis.voigtlaen...@gmail.com> wrote:

> The function from that thread exists as
> http://package.elm-lang.org/packages/NoRedInk/elm-task-extra/2.0.0/Task-Extra#performFailproof
>
>
>
> Am 15.10.2016 um 19:39 schrieb Austin Bingham :
>
> I've got a situation where I've got task that will always succeed, and I
> want to know the best practice for using it with Task.perform.
>
> The task itself is a Task.sequence of tasks that may individually fail,
> and I want to report the result - success or failure - for each of them. So
> there's no meaningful failure mode that I can find for the final
> Task.perform.
>
> I've seen a suggestion in this group for defining a performSucceed
> function (
> https://groups.google.com/d/msg/elm-discuss/5Q9ktTuavgY/mGk3PVn7CgAJ),
> and this seems perfectly reasonable to me. But I'm also trying to write elm
> as idiomatically as I can, so I wanted to know if this is generally
> considered "correct".
>
> Similarly, if my approach (i.e. aggregating a bunch of results into a
> sequence of success-failure Results) is wrong-headed, I'm happy to
> entertain alternative implementations.
>
>
> --
> 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.
>

-- 
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] Properly using Task.perform with tasks that always succeed

2016-10-15 Thread Janis Voigtländer
The function from that thread exists as 
http://package.elm-lang.org/packages/NoRedInk/elm-task-extra/2.0.0/Task-Extra#performFailproof



> Am 15.10.2016 um 19:39 schrieb Austin Bingham :
> 
> I've got a situation where I've got task that will always succeed, and I want 
> to know the best practice for using it with Task.perform.
> 
> The task itself is a Task.sequence of tasks that may individually fail, and I 
> want to report the result - success or failure - for each of them. So there's 
> no meaningful failure mode that I can find for the final Task.perform.
> 
> I've seen a suggestion in this group for defining a performSucceed function 
> (https://groups.google.com/d/msg/elm-discuss/5Q9ktTuavgY/mGk3PVn7CgAJ), and 
> this seems perfectly reasonable to me. But I'm also trying to write elm as 
> idiomatically as I can, so I wanted to know if this is generally considered 
> "correct".
> 
> Similarly, if my approach (i.e. aggregating a bunch of results into a 
> sequence of success-failure Results) is wrong-headed, I'm happy to entertain 
> alternative implementations. 
> 
> 
> -- 
> 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] Properly using Task.perform with tasks that always succeed

2016-10-15 Thread Austin Bingham
I've got a situation where I've got task that will always succeed, and I 
want to know the best practice for using it with Task.perform.

The task itself is a Task.sequence of tasks that may individually fail, and 
I want to report the result - success or failure - for each of them. So 
there's no meaningful failure mode that I can find for the final 
Task.perform.

I've seen a suggestion in this group for defining a performSucceed function 
(https://groups.google.com/d/msg/elm-discuss/5Q9ktTuavgY/mGk3PVn7CgAJ), and 
this seems perfectly reasonable to me. But I'm also trying to write elm as 
idiomatically as I can, so I wanted to know if this is generally considered 
"correct".

Similarly, if my approach (i.e. aggregating a bunch of results into a 
sequence of success-failure Results) is wrong-headed, I'm happy to 
entertain alternative implementations. 


-- 
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] Outgoing port event ordering

2016-10-15 Thread David Andrews
When using Cmd.batch to send data over two ports, the ports receive the 
events in the same order regardless of the order in which they appear in 
the batch.  I would expect the events to occur in the order they appear in 
the batch.

Working example: https://daviddta.github.io/elm-port-order-bug/
Code: https://github.com/DavidDTA/elm-port-order-bug
Looking at the console, we see that port one always receives the event 
before port two.

As some motivation, consider two ports which both write to the same local 
storage key.  Without a guarantee on the ordering of events, the two 
subscriptions will race to write the key.

-- 
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] Re: trying to draw a diagram about elm-architecture

2016-10-15 Thread Lidor Cohen
I did some drawing myself in attempt to understand better the elm 
architecture.
It's by hand and focusing mostly on basic data flow...

https://drive.google.com/open?id=0B7DsiWb2uc5AOGxiZVZoMFNxbW8

I'd love to get some feedback :)

On Tuesday, May 31, 2016 at 6:14:38 AM UTC+3, 大魔头 wrote:
>
> hi,
>
> I've tried out examples in http://guide.elm-lang.org/  , now I want to 
> prepare myself to share what I've learnt to my team mates.  
>
> since there isn't an official diagram about the elm-architecure(maybe 
> there is?), so I draw my own.
> https://raw.githubusercontent.com/notyy/learn_elm/master/elm_arch.png
>
> review is very much welcome. I hope my diagram won't be miss leading 
> others.
>

-- 
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] Where have the nested counter examples gone ?

2016-10-15 Thread clouddie
Hi, a few months ago there were examples to scale and nest elm apps with 
list of counters ? I cannot find them anymore, does anyone know where they 
have been ? Was it bad practice ?

-- 
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] Catch Elm.Main.fullscreen "unexpected argument" error?

2016-10-15 Thread Kevin Berridge
Is there a way to catch the "You are trying to initialize module `Main` 
with an unexpected argument." error when calling Elm.Main.fullscreen({}) 
with out of date arguments?  I tried wrapping it in a try/catch, but the 
catch is not running.

What I'm really trying to do is pass in state that was persisted in local 
storage as described here 
https://medium.com/wunder-nerds/storing-and-restoring-the-state-in-elm-0-17-94874429dc1d#.gmkt7hrwu.
 
 But I changed my model, so now it errors.  I'm happy to just forget the 
state and start over when that happens, so if I could catch the error in JS 
I could do that.

Here's the JS I'm using.  The throw in that catch block doesn't run.

const storedState = localStorage.getItem('model');
const startingState = storedState ? JSON.parse(storedState) : null;
try {
elmApp = Elm.Main.fullscreen(startingState);
}
catch (e) {
throw "it caught!";
}
elmApp.ports.setStorage.subscribe(function (state) {
  localStorage.setItem('model', JSON.stringify(state));
})


And the JS error that is being thrown (but not being caught) is:
Uncaught Error: You are trying to initialize module `Main` with an 
unexpected argument.
When trying to convert it to a usable Elm value, I run into this problem:

I ran into the following problems:

Expecting null but instead got: {...}
Expecting an object with a field named `comment` at _.distractions[4] but 
instead got: {...}

I truncated the object properties in that message.  That error is correct, 
'comment' was added to my elm model and therefore does not exist in the 
previously stored state that it is trying to deserialize.

Thanks in advance,
Kevin

-- 
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] Re: Can I use css animations normally in elm?

2016-10-15 Thread Simone Vittori
I think it's worth mentioning your Elm code can be totally independent from 
any animation done in an external stylesheet.

See this style for 
example: 
https://github.com/simonewebdesign/elm-double-folding-pattern/blob/a27de84ba14f46f46d4d3878b233dcd32b31d13d/style.css#L357

The animation starts as soon as the item gets added to the DOM.


On Friday, 14 October 2016 20:21:03 UTC+1, Aislan de Sousa Maia wrote:
>
> Some repo to see this more advanced animations with CSS + Elm ??
>

-- 
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] Re: Another case of functions in the model

2016-10-15 Thread Oliver Searle-Barnes
Have you had a look at (the currently not 
released) https://github.com/saschatimme/elm-phoenix? Phoenix channels have 
request/response semantics built in which you can use in elm-phoenix via 
Phoenix.push - 
https://github.com/saschatimme/elm-phoenix/blob/master/src/Phoenix.elm#L85. 
See Push.ok for adding a response 
handler 
https://github.com/saschatimme/elm-phoenix/blob/master/src/Phoenix/Push.elm#L69.

On Saturday, 15 October 2016 01:04:32 UTC+2, Mark Hamburg wrote:
>
> We have an app based on making multiple HTTP requests to a server for 
> various pieces of information. All of these requests get implemented as 
> tasks that more or less immediately become commands which then get routed 
> via tagging functions as they flow up through the model. Pretty standard 
> stuff. (I think in 0.18, we get to ignore the task aspect.) 
>
> We're interested in exploring using web sockets or Phoenix channels as an 
> alternative. Now, the request would go upstream on the socket with a tag 
> (probably just a number) and the response would come back down bearing the 
> same tag. 
>
> To keep the same general style of coding as in the HTTP case, it seems 
> like the best implementation would be to use the 
> Requests-as-alternatives-to-Cmds approach. Rather than building a command 
> directly, we would build requests that could be similarly mapped with 
> routing functions as they propagated up through the model from update 
> functions. At the top level, we would maintain a dictionary mapping request 
> ID's to decode-and-route functions and turn the request itself into a 
> command to post to the upstream channel. The listener on the socket would 
> see the responses coming back and look in the dictionary for a 
> corresponding entry. 
>
> That all seems pretty straightforward. But note that the model now 
> contains a dictionary of decode-and-route functions. Is there a solution 
> that avoids this and doesn't gum things up significantly in other ways? 
>
> Mark 
>
>

-- 
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.