[elm-discuss] Re: Task ports: A proposal to make it easier to integrate JS with Elm.

2017-04-14 Thread Nicholas Hollon
The process:

1. Share your ideas, experience, & code on elm-discuss.
2. Accept that you have no direct influence over what Evan works on next.
3. Look at the release history  for Elm. Notice 
that changes happen slowly. Notice that improvements to the JavaScript 
interface (ports, tasks, subscriptions) are spaced out by at least a year. 
Notice that 0.17 has only been out for about a year.
4. Remember that things are going to get better! Just because something 
isn't being worked on right this minute doesn't mean that it isn't going to 
be improved in the future.
6. Do things in life that make you happy. If it upsets you that Elm lacks 
something you think is super important, maybe take a break and come back 
later.



On Friday, April 14, 2017 at 10:24:46 AM UTC-7, Conner Ruhl wrote:
>
> What is the process for requesting these sort of features? Is there one?
>
> On Saturday, August 13, 2016 at 10:31:07 AM UTC-5, James Wilson wrote:
>>
>> The problem
>>
>> ports as they stand are fundamentally incompatible with Tasks. Being 
>> backed by Cmd's, they are harder to compose. A frustration of mine is that 
>> often we are directed to "just use ports" when a proper interface to some 
>> native API is not yet available, but this leads to our Msg types growing 
>> and more significant changes being required when eventually the proper 
>> interface is made available.
>>
>> Also, many JS interop things I find myself wanting to do are 
>> fundamentally one-shot functions which I expect a result back into Elm from 
>> immediately, or otherwise just want to compose with other Task based 
>> things. Some examples that come to mind of one-shot tasks you may want to 
>> compose rather than use the streaming interface that ports provide:
>>
>>- Getting items from local/sessionStorage
>>- .. really, most things involving working with the Web API that 
>>arent yet implemented in Elm.
>>- Embedding JS widgets into Elm elements
>>- Using a JS library for doing things like hashing passwords or 
>>obtaining some data back from some custom service
>>- Interacting with things like Electron for creating apps that can 
>>run in the desktop and interact with the filesystem etc.
>>
>>
>> The solution
>>
>> Task ports. The idea is that these are defined the same way that Ports in 
>> elm currently are, but they return a Task type rather than a Cmd or Sub 
>> type. On the JS Side, we attach a function to the Elm app that returns a 
>> Promise, and on the Elm side we wait for the Promise returned to reject or 
>> resolve, and marhsall the error or result from the promise into the error 
>> or result type required by the Task type of the port.
>>
>> Let's see how this might work:
>>
>>
>> *Ports.elm:*
>>
>> port apiSession: Task String SessionId
>>
>>
>>
>> *Main.elm:*
>>
>> import Ports
>> import Json.Decode as Decode
>> import Task exposing (andThen)
>>
>>
>> -- get an API session from JS land and make an http request using it
>> -- given some path and a decoder to decipher the result:
>> apiRequest : String -> Decoder a -> Task ApiError a
>> apiRequest path decoder =
>>   let
>> headers sessId =
>> [ ("Content-Type", "application/json")
>> , ("MyApp-SessionId", sessId)
>> ]
>>
>>
>> req sessId = Http.send Http.defaultSettings
>> { verb = "POST"
>> , headers = headers sessId
>> , url = path
>> }
>>
>>
>> decodeResponse res = Decode.decodeString decoder -- ...handle error 
>> etc
>>   in
>> Ports.apiSession `andThen` req `andThen` decodeResponse
>>
>>
>> *App.js:*
>>
>> Elm.Main.ports.apiSession = function(){
>> return new Promise(function(resolve,reject){
>>
>>
>> var sess = localStorage.getItem("sessionId");
>> if(!sess) reject("NO_SESSION");
>> else resolve(sess);
>>
>>
>> });
>> }
>>
>> var app = Elm.Main.fullscreen();
>>
>>
>>
>>
>> Here, we use a tiny bit of JS to access localStorage and pull out a 
>> session ID. This function is used whenever the apiRequest Task is performed 
>> in Elm, and composes nicely into our apiRequest without the need for a 
>> complicated effect manager or threading a sessionId through everywhere just 
>> because we need to get it from a Cmd based port.
>>
>> One of the nice things about this is that there is minimal refactoring to 
>> do for those things that do eventually receive coverage in the Elm Web API 
>> - you're just swapping out Tasks for other Tasks. As the Web API will 
>> always be changing, I think that having a nice way to make JS polyfills 
>> like this will always have some value, let alone for interacting with 
>> libraries written in JS that haven't or won't ever be ported to Elm.
>>
>> Elm would continue to make the same guarantees as with other ports; if 
>> the task port can't marshall the response back into Elm an error would be 
>> thrown along the same lines as is currently done via ports.
>>
>> Summary
>>
>> - 

[elm-discuss] Re: Call of init function behaviour

2017-04-12 Thread Nicholas Hollon
Glad you fixed your problem. If you give the button an onSubmit 
 
event handler, that should prevent the reload from happening, even if you 
are using Html.form.

On Tuesday, April 11, 2017 at 11:46:10 AM UTC-7, Oliver Dunkl wrote:
>
> Thank you for your reply. I have solved my problem after looking hours and 
> hours on my code :) The problem was that I had a button that calls to the 
> backend which I described in my question and the problem was that the 
> button was in a Html.form. Apparently it will first trigger the action and 
> than reloads the page and triggers the init function again.
>
> So Nicholas we had the right answer independently.
>
> Sorry for the noise but maybe I could help other people with the answer :)
>
> thx
> \= odi
>

-- 
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: elmvm (Elm Version Manager)

2017-04-06 Thread Nicholas Hollon

>
> There needs to be a better advertising of the ecosystem both in terms of 
> tools and in terms of packages.
>

I agree with this, but the effort needs to start with the library authors.

As far as I can tell (searching this list, Google, & r/elm), Erik is the 
only one of these authors who has publicized their work in any way.

If you invent a wheel, you need to tell people about it. You can't just 
leave it lying in your front yard and hope that people walk by your house 
:-)



On Thursday, April 6, 2017 at 6:34:53 AM UTC-7, Peter Damoc wrote:
>
> On Thu, Apr 6, 2017 at 3:43 PM, Eirik Sletteberg  > wrote:
>
>> None of these tools are mentioned in the Elm documentation. It only 
>> points to installers and the npm module.
>
>
> Exactly my point. 
> There needs to be a better advertising of the ecosystem both in terms of 
> tools and in terms of packages. 
>
>
> -- 
> 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: ANN: TypedSvg

2017-03-31 Thread Nicholas Hollon
This is awesome! Something I've wished for since about 5 minutes after I 
started learning elm-svg.

 Will definitely be adopting it for future projects... possibly sending 
some pull requests along the way.  :-)

On Thursday, March 30, 2017 at 8:35:32 AM UTC-7, Duane Johnson wrote:
>
> Hi all,
>
> I've been working on a TypedSvg package here:
>
> http://package.elm-lang.org/packages/canadaduane/typed-svg/2.0.1
>
> Its intent is to replace `elm-lang/svg` with a fully typed and documented 
> SVG package. There's still a lot of work to do (the SVG spec is huge) but 
> I'm pretty happy with the progress that's been made. I'm announcing this 
> now so that if others are interested in a similar package, we can 
> consolidate effort and help one another rather than duplicate effort.
>
> Thanks,
> Duane Johnson
>
>

-- 
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: Embedding multiple elements into JS

2017-03-24 Thread Nicholas Hollon
err, I meant that message to be a little bit more timely, but it got held 
up in moderation. Glad you got help -.-

On Friday, March 24, 2017 at 3:49:24 PM UTC-7, Nicholas Hollon wrote:
>
> You should have Elm return the , and embed the program an empty div. I 
> am pretty sure you are only allowed to embed Elm programs in divs anyway, 
> not just any old html tag.
>
> On Wednesday, March 22, 2017 at 7:36:44 AM UTC-7, Matt Joiner wrote:
>>
>> I'm looking to embed Elm in an existing web application gradually. I find 
>> it most appropriate in my projects to embed multiple elements, not a single 
>> parent element. For example I have some bootstrap:
>>
>> 
>>
>> I want to run Elm.Main.embed(document.getElementById('some-list')), and 
>> have that main return multiple  elements. Clearly I can't have Elm 
>> return a parent  because then I have . I also can't 
>> have Elm return the  because 
>> then there's no #some-list to embed it on in the first place.
>>
>> Look forward to suggestions, 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.


[elm-discuss] Re: Embedding multiple elements into JS

2017-03-24 Thread Nicholas Hollon
You should have Elm return the , and embed the program an empty div. I 
am pretty sure you are only allowed to embed Elm programs in divs anyway, 
not just any old html tag.

On Wednesday, March 22, 2017 at 7:36:44 AM UTC-7, Matt Joiner wrote:
>
> I'm looking to embed Elm in an existing web application gradually. I find 
> it most appropriate in my projects to embed multiple elements, not a single 
> parent element. For example I have some bootstrap:
>
> 
>
> I want to run Elm.Main.embed(document.getElementById('some-list')), and 
> have that main return multiple  elements. Clearly I can't have Elm 
> return a parent  because then I have . I also can't 
> have Elm return the  because 
> then there's no #some-list to embed it on in the first place.
>
> Look forward to suggestions, 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.