Re: [elm-discuss] How to do Context in 0.17 (passing in multiple Addesses to a view)

2016-07-27 Thread Peter Damoc
I like the Context record pattern. It's simple and can be extended.
You can start with a context record and, if the view gets more general
purpose you can slowly move to a signature similar to those found in Html
components where you would make its fields optional.

type alias Context msg =
{ someValue : String
, onMsg1 : Maybe msg
, onMsg2 : Maybe msg
}


defaultContext =
{ someValue = ""
, onMsg1 = Nothing
, onMsg2 = Nothing
}


type alias Attribute msg =
Context msg -> Context msg


someValue : String -> Attribute msg
someValue value ctx =
{ ctx | someValue = value }


onMsg1 : msg -> Attribute msg
onMsg1 msg ctx =
{ ctx | onMsg1 = msg }


onMsg2 : msg -> Attribute msg
onMsg2 msg ctx =
{ ctx | onMsg2 = msg }




view : List (Attribute msg) -> List (Html msg) -> Html msg
view props children =
let
ctx =
List.foldl (\p acc -> p acc) defaultContext props

content =
div [] [text ctx.someValue]
in
div []
[ content
, div [] children
]






On Thu, Jul 28, 2016 at 1:38 AM, Sean Clark Hess  wrote:

> For the app I'm working on, I would like to create some views that have no
> update function or message. In 0.16, you could pass in extra addresses to a
> view. The example in the elm architecture lumped them together in a Context
> parameter.
>
> I found this useful in 0.16 when creating very general views that didn't
> manage their own state. This approach was analogous to when you pass in a
> callback as a prop in React, if that helps.
>
> How does one do this in 0.17?
>
> Specifically I'm thinking about the use case of a general view function
> that takes any HTML children, but has some events that need to fire (like
> an accordion container opening and closing).
>
> --
> 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] How to do Context in 0.17 (passing in multiple Addesses to a view)

2016-07-27 Thread Noah Hall
This is what our accordion looks like in 0.17:

https://gist.github.com/eeue56/d0a2f901dc2fe36ab4562940b7fd28e4

it was a +7 -11 diff :)


Otherwise, you want `Html.App.map`. Make a component that has it's own
"update" function, with it's own messages. Map them and pass the
messages down from the top level in a wrapper to the `update` function
for that component. E.g


type MessageLevel = TopLevel Msg | SomeGenericViewLevel SomeGenericView.Msg


On Thu, Jul 28, 2016 at 12:38 AM, Sean Clark Hess  wrote:
> For the app I'm working on, I would like to create some views that have no
> update function or message. In 0.16, you could pass in extra addresses to a
> view. The example in the elm architecture lumped them together in a Context
> parameter.
>
> I found this useful in 0.16 when creating very general views that didn't
> manage their own state. This approach was analogous to when you pass in a
> callback as a prop in React, if that helps.
>
> How does one do this in 0.17?
>
> Specifically I'm thinking about the use case of a general view function that
> takes any HTML children, but has some events that need to fire (like an
> accordion container opening and closing).
>
> --
> 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] Re: Modifying the DOM with external JS libraries

2016-07-27 Thread Ian Mackenzie
In this particular case, if you're just using highlight.js to highlight a block 
of code, you might also be able to use evancz/elm-markdown 
(http://package.elm-lang.org/packages/evancz/elm-markdown/3.0.0/). You'll still 
need to load a version of highlight.js in your HTML as described by the 
elm-markdown README, but then you should just be able to render a Markdown 
fragment containing a code block without worrying about weird DOM interactions.

-- 
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] How to do Context in 0.17 (passing in multiple Addesses to a view)

2016-07-27 Thread Sean Clark Hess
For the app I'm working on, I would like to create some views that have no
update function or message. In 0.16, you could pass in extra addresses to a
view. The example in the elm architecture lumped them together in a Context
parameter.

I found this useful in 0.16 when creating very general views that didn't
manage their own state. This approach was analogous to when you pass in a
callback as a prop in React, if that helps.

How does one do this in 0.17?

Specifically I'm thinking about the use case of a general view function
that takes any HTML children, but has some events that need to fire (like
an accordion container opening and closing).

-- 
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] Touch module in Elm 0.17

2016-07-27 Thread art yerkes
A proper expression of touch includes multiple touches that can come and go
independently, along with extra parameters for each (pressure is one but
velocity is another too).  Neither was relevant to the things I was writing
but it'd be awesome to see a touch API that exposes touch fully in a way
that doesn't get weighed down with model state or require too much
boilerplate.

On Wed, Jul 27, 2016 at 9:50 AM, OvermindDL1  wrote:

> As long as you have multiple pointer objects.
>
> Linux supports multiple simultaneous mice (no clue if browsers do) so
> there is precedent there.  And touch's are basically multiple mice
> (although some interfaces expose a 'strength' or 'pressure' or so too to
> say how hard the person is touching).  Could easily be combined.
>
>
>
> On Wednesday, July 27, 2016 at 10:36:26 AM UTC-6, Rex van der Spuy wrote:
>>
>>
>>
>> On Tuesday, July 26, 2016 at 1:35:07 PM UTC-4, Janis Voigtländer wrote:
>>>
>>>  I guess because it’s much less clear for it than for the other three
>>> mentioned modules what the “final” API will look like.
>>>
>>  Would it make sense to combine both mouse and touch into a single
>> `pointer` object?
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elm-discuss/6Dj7FyoQF2g/unsubscribe.
> To unsubscribe from this group and all its topics, 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] Has elm reactor 0.17 dropped support for HTML files?

2016-07-27 Thread Steve Jones
Is there an issue to follow for this?

On Tuesday, June 28, 2016 at 3:23:49 PM UTC-4, Evan wrote:
>
> Try the 0.17.1 beta
>
> On Tuesday, June 28, 2016, Stuart Axon  
> wrote:
>
>> Hi,
>>I just started with elm and this is a bit confusing.   - I guess I 
>> need a separate http server for now to see the output ?
>>
>> So workflow - is:
>>
>> Compile, then refresh browser that is pointing at separate http server?
>>
>> S
>>
>>
>>
>> On Sunday, May 15, 2016 at 9:57:26 PM UTC+1, John Orford wrote:
>>>
>>> Yeh the manual compiles are irksome
>>>
>>> Paul D  schrieb am So., 15. Mai 2016 17:07:
>>>
 It's not just serving the files, it's also debugging. It'd be pretty 
 sad if embedding Elm meant that you couldn't use its main (sole?) 
 development tool. I'm glad to hear that HTML support is coming back!


 On Sunday, May 15, 2016 at 3:16:07 AM UTC-6, John Watson wrote:
>
> Don't worry - I'm quite happy just serving it with Apache.
>
> On Sunday, 15 May 2016 01:29:06 UTC+1, Evan wrote:
>>
>> It's probably a mistake in how I added the "pretty" view. Like I've 
>> been saying to everyone about reactor, I needed to release without 
>> *everything* or I'd never get 0.17 out the door. Things will be 
>> fixed up later!
>>
>> On Sat, May 14, 2016 at 8:11 AM, John Watson  
>> wrote:
>>
>>> elm-reactor --version gives 0.17.0.  I'm running 64-bit Ubuntu.
>>>
>>> On Saturday, 14 May 2016 16:07:29 UTC+1, Joey Eremondi wrote:

 Can you verify what version of Elm reactor is being used? 
 On May 14, 2016 2:43 AM, "John Watson"  wrote:

> I'm affected by this, too.  If I compile with --output Main.html 
> then an Html file is produced with the new syntax of 
> Elm.Main.fullscreen(); 
> however elm reactor no longer serves it.  I need this to test HTTP 
> requests 
> which otherwise will give me CORS errors.  Am I missing something 
> obvious?
>
> On Friday, 13 May 2016 09:51:39 UTC+1, Paul D wrote:
>>
>> I'm using the fullscreen function to embed an Elm app in an HTML 
>> file. With Elm 0.16, I could run elm-reactor and then go to 
>> http://localhost:8080/myfile.html to use the app. After 
>> upgrading to Elm 0.17, elm-reactor no longer serves the HTML. 
>> Instead it 
>> just displays the file contents, much like view source would. Is 
>> this a bug 
>> or was that functionality deliberately removed?
>>
> -- 
> 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.
>
 -- 
>>> 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.
>>>
>>
>> -- 
 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.

>>> -- 
>> 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.
>>
>
>
> -- 
> Sent from Gmail Mobile
>

-- 
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] Touch module in Elm 0.17

2016-07-27 Thread OvermindDL1
As long as you have multiple pointer objects.

Linux supports multiple simultaneous mice (no clue if browsers do) so there 
is precedent there.  And touch's are basically multiple mice (although some 
interfaces expose a 'strength' or 'pressure' or so too to say how hard the 
person is touching).  Could easily be combined.


On Wednesday, July 27, 2016 at 10:36:26 AM UTC-6, Rex van der Spuy wrote:
>
>
>
> On Tuesday, July 26, 2016 at 1:35:07 PM UTC-4, Janis Voigtländer wrote:
>>
>>  I guess because it’s much less clear for it than for the other three 
>> mentioned modules what the “final” API will look like.
>>
>  Would it make sense to combine both mouse and touch into a single 
> `pointer` object?
>

-- 
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] Parsing JSON — one more victim

2016-07-27 Thread Eduardo Cuducos
@Rex: I join this chant: nice trick this one on debugging — once more,
thanks, Peter! (and, yes, this community os awesome!)

@Peter: I've seem things that belong to the “public/common” such as a
decentralized Twitter
 or Chicago
transit timetable ! Maybe they are
not civic activism, but the decentralized Twitter is *per se* a political
and civic claim in itself IMHO… Anyway, this tiny page I created has
started with React managing the DOM in a smart way; thus I had the idea to
replace React by Elm in baby-steps. A couple of weeks ago I got rid of
react. Today I just completed the full migration of the HTML body to Elm <3

On Wed, Jul 27, 2016 at 6:33 PM Rex van der Spuy 
wrote:

>
>
> On Tuesday, July 26, 2016 at 7:27:25 AM UTC-4, Eduardo Cuducos wrote:
>>
>> You could be very mean due to my typo.
>>
>
> This is the Elm Community, we don't do mean here :)
>
> I had a similar, infuriating JSON decoding bug due to a simple typo that
> took me hours to find ... argh! :)
>
> Peter, I didn't know that trick about debugging the decoder, thanks for
> explaining it.
>
> --
> 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] Touch module in Elm 0.17

2016-07-27 Thread Rex van der Spuy


On Tuesday, July 26, 2016 at 1:35:07 PM UTC-4, Janis Voigtländer wrote:
>
>  I guess because it’s much less clear for it than for the other three 
> mentioned modules what the “final” API will look like.
>
 Would it make sense to combine both mouse and touch into a single 
`pointer` object?

-- 
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] Parsing JSON — one more victim

2016-07-27 Thread Rex van der Spuy


On Tuesday, July 26, 2016 at 7:27:25 AM UTC-4, Eduardo Cuducos wrote:
>
> You could be very mean due to my typo. 
>

This is the Elm Community, we don't do mean here :)

I had a similar, infuriating JSON decoding bug due to a simple typo that 
took me hours to find ... argh! :)

Peter, I didn't know that trick about debugging the decoder, thanks for 
explaining it.

-- 
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] Requests for comment: Chrome extensions can cause runtime exceptions

2016-07-27 Thread Gage Peterson
I've found the Elm.Main.fullscreen(). Can cause run time exceptions if a 
chrome extension decides to add a div to the body. We've been talking about 
various solutions such as either removing fullscreen altogether or possibly 
making it put a div inside of body instead of directly modifying it. 

Please read the GitHub issue for a full discussion of the reasons: 
https://github.com/elm-lang/html/issues/44

-- 
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: port module for JS interop.. without main/view ?

2016-07-27 Thread Jörg Winter
Do you think a correlating by Id is necessary ?
If it is the simple case of having only 1 inbound and 1 outbound port in
Elm and doing nothing async in Elm ... isn't a send/receive in JS basically
synchronous ?

A promise could still make sense but that Id would not be necessary.

Some explanation in the Elm Guide would help a lot here.

-- 
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: mounting and switching css stylesheets

2016-07-27 Thread Peter Damoc
I haven't bothered to check in Firefox and now I feel a little silly.

Thank you kind stranger!


On Wed, Jul 27, 2016 at 5:57 PM, OvermindDL1  wrote:

> Yeah Chrome will reset CSS to the system default when style is changed.
> I've not tried but maybe try to add the new one after the old, then remove
> the old only after it is added (and you wait like 50ms after too to let the
> page re-process the new styles)?
>
>
> On Wednesday, July 27, 2016 at 8:48:32 AM UTC-6, Peter Damoc wrote:
>>
>> Context:
>> - a single page app with multiple virtual pages.
>> - each page contributes a list of styles that is added to a list of
>> common styles and is compiled into a stylesheet that is mounted in a  
>> Html.node
>> "style".
>>
>>
>> Main problem:
>> - I'm seeing flickering when the style node changes.
>>
>> Secondary problem:
>> - Chrome is telling move the style information into the header for
>> performance reasons.
>>
>> I've seen this PowerCSS  presentation
>> and I'm wondering if this double-buffering strategy is applicable in my
>> situation
>>
>> What would you advise?
>>
>>
>> --
>> 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.
>



-- 
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: Modifying the DOM with external JS libraries

2016-07-27 Thread victor . noel
I think one of the main problem will be that Elm uses the virtualdom and so 
even if you modify the DOM, it could be reverted by the virtualdom on 
refresh (or something like that, I'm not an expert ^^).

There exists alternatives to virtualdom (such as morphdom: 
https://github.com/patrick-steele-idem/morphdom) that works differently and 
thus let you modify the DOM without problem externally but Elm does not use 
them.

Le mercredi 27 juillet 2016 17:00:49 UTC+2, Marco Perone a écrit :
>
> Hello everybody,
>
> I am building an application in Elm and I need to call an external JS 
> library that interacts directly with the DOM (in my case, highlights a 
>  section). I built a port to communicate from Elm to Javascript 
> and, on the Javascript side, I'd like to call my external library as soon 
> as the element appears on the page.
> My first try was to use the port command in the init function on my Elm 
> application, but this doesn't seem to work, because when the JS callback is 
> executed, the element of the DOM I need to interact with is not present yet.
> For the moment I solved it on the Javascript side, just by retrying until 
> the element is actually present, with something like this:
>
> var highlightWhenReady = function () {
> if (!document.getElementById("part-to-highlight")) {
> window.requestAnimationFrame(highlightWhenReady);
> }
> hljs.highlightBlock(document.getElementById("part-to-highlight"));
> };
>
> but it seems really dirty, and certainly not the Elm way to do it.
> What is the recommended way to do such things the Elm way? How could I 
> know when the DOM element actually got rendered in the page?
>
> Thank you!
>
> marco
>

-- 
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] Form with union type

2016-07-27 Thread Simone Vittori
I'm building a language selector and I'd like to map the options to a union 
type.

Here's what I tried:

import Json.Decode exposing (Decoder, customDecoder, string)

{-| Currently supported languages. -}
type Language
= English
| Japanese


{-| A JSON decoder of Language. -}
languageDecoder : Decoder Language
languageDecoder =
customDecoder string fromStringLanguage


fromStringLanguage : String -> Result String Language
fromStringLanguage str =
case str of
"English" -> Ok English
"Japanese" -> Ok Japanese
other -> Err ("Invalid language: " ++ other)

And here's how I'm using it:

-- MODEL

type alias Model = Language


-- UPDATE

type Msg
= Change Language

update : Msg -> Model -> Model
update msg model =
case msg of
Change language -> language


-- VIEW

view : Model -> Html Msg
view model =
Html.form []
[ select [ on "change" <| Json.Decode.map Change languageDecoder ]
(List.map (viewOption model) ["English", "Japanese"])
]

It does compile successfully, but when I select another option from the 
dropdown list, nothing happens. Any ideas?
Is this the right way of decoding a union type?

-- 
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: Modifying the DOM with external JS libraries

2016-07-27 Thread OvermindDL1
The call cycle seems to be:
0. main
1. init
2. subscribe
3. view (subscribe and view might be the other way, does not matter)
4. loop when receive msg
  1. receive msg -> update
  2. subscribe
  3. view

So instead of calling on init instead make a new Msg specifically for 
sending the command to your javascript port a cycle 'later'.  So in your 
init do `Cmd.cmd CallMyJSPort` or so, and put that again every time you 
need to run it again.  In your update callback for the `CallMyJSPort` 
message then call the port.  I do this and it works perfect every time. 
 *However*, you should not be mutating the Elm DOM as if it gets out of 
sync from the virtual DOM then weird bad things can happen.  You are 
'generally' safe if you, say, add things to an empty elm-div or if you 
absolutely never alter the DOM parts in elm again after mutating them in 
JS, but not recommended regardless.


On Wednesday, July 27, 2016 at 9:00:49 AM UTC-6, Marco Perone wrote:
>
> Hello everybody,
>
> I am building an application in Elm and I need to call an external JS 
> library that interacts directly with the DOM (in my case, highlights a 
>  section). I built a port to communicate from Elm to Javascript 
> and, on the Javascript side, I'd like to call my external library as soon 
> as the element appears on the page.
> My first try was to use the port command in the init function on my Elm 
> application, but this doesn't seem to work, because when the JS callback is 
> executed, the element of the DOM I need to interact with is not present yet.
> For the moment I solved it on the Javascript side, just by retrying until 
> the element is actually present, with something like this:
>
> var highlightWhenReady = function () {
> if (!document.getElementById("part-to-highlight")) {
> window.requestAnimationFrame(highlightWhenReady);
> }
> hljs.highlightBlock(document.getElementById("part-to-highlight"));
> };
>
> but it seems really dirty, and certainly not the Elm way to do it.
> What is the recommended way to do such things the Elm way? How could I 
> know when the DOM element actually got rendered in the page?
>
> Thank you!
>
> marco
>

-- 
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] Modifying the DOM with external JS libraries

2016-07-27 Thread Marco Perone
Hello everybody,

I am building an application in Elm and I need to call an external JS 
library that interacts directly with the DOM (in my case, highlights a 
 section). I built a port to communicate from Elm to Javascript 
and, on the Javascript side, I'd like to call my external library as soon 
as the element appears on the page.
My first try was to use the port command in the init function on my Elm 
application, but this doesn't seem to work, because when the JS callback is 
executed, the element of the DOM I need to interact with is not present yet.
For the moment I solved it on the Javascript side, just by retrying until 
the element is actually present, with something like this:

var highlightWhenReady = function () {
if (!document.getElementById("part-to-highlight")) {
window.requestAnimationFrame(highlightWhenReady);
}
hljs.highlightBlock(document.getElementById("part-to-highlight"));
};

but it seems really dirty, and certainly not the Elm way to do it.
What is the recommended way to do such things the Elm way? How could I know 
when the DOM element actually got rendered in the page?

Thank you!

marco

-- 
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] textarea selection

2016-07-27 Thread OvermindDL1
Correction, does not seem to work, I cannot find a way to access the 
textarea element from the button callback...

On Wednesday, July 27, 2016 at 8:37:05 AM UTC-6, OvermindDL1 wrote:
>
> I already use custom 'on' things to override default propagation (more 
> interaction with the legacy javascript that I am stopping in this case), 
> but you just gave me a fantastic idea...  I might be able to get rid of my 
> `surroundSelectionWith` javascript port...
>
> On Wednesday, July 27, 2016 at 12:56:24 AM UTC-6, Atamert Ölçgen wrote:
>>
>> Have you tried this:
>>
>> http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Events#on
>>
>> On Tue, Jul 26, 2016 at 11:02 PM, OvermindDL1  wrote:
>>
>>> When a user clicks a button I am needing to take the text that is 
>>> currently *selected* in a textarea and surround it with other text while 
>>> retaining what is selected.  What is the method to do this in Elm.  Is 
>>> there an onSelectionChanged callback or something that I am missing?
>>>
>>> -- 
>>> 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.
>>>
>>
>>
>>
>> -- 
>> Kind Regards,
>> Atamert Ölçgen
>>
>> ◻◼◻
>> ◻◻◼
>> ◼◼◼
>>
>> www.muhuk.com
>>
>

-- 
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: mounting and switching css stylesheets

2016-07-27 Thread OvermindDL1
Yeah Chrome will reset CSS to the system default when style is changed. 
 I've not tried but maybe try to add the new one after the old, then remove 
the old only after it is added (and you wait like 50ms after too to let the 
page re-process the new styles)?

On Wednesday, July 27, 2016 at 8:48:32 AM UTC-6, Peter Damoc wrote:
>
> Context: 
> - a single page app with multiple virtual pages.  
> - each page contributes a list of styles that is added to a list of common 
> styles and is compiled into a stylesheet that is mounted in a  Html.node 
> "style".  
>
>
> Main problem:
> - I'm seeing flickering when the style node changes. 
>
> Secondary problem: 
> - Chrome is telling move the style information into the header for 
> performance reasons. 
>
> I've seen this PowerCSS  presentation 
> and I'm wondering if this double-buffering strategy is applicable in my 
> situation 
>
> What would you advise? 
>
>
> -- 
> 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] mounting and switching css stylesheets

2016-07-27 Thread Peter Damoc
Context:
- a single page app with multiple virtual pages.
- each page contributes a list of styles that is added to a list of common
styles and is compiled into a stylesheet that is mounted in a  Html.node
"style".


Main problem:
- I'm seeing flickering when the style node changes.

Secondary problem:
- Chrome is telling move the style information into the header for
performance reasons.

I've seen this PowerCSS  presentation
and I'm wondering if this double-buffering strategy is applicable in my
situation

What would you advise?


-- 
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] textarea selection

2016-07-27 Thread OvermindDL1
I already use custom 'on' things to override default propagation (more 
interaction with the legacy javascript that I am stopping in this case), 
but you just gave me a fantastic idea...  I might be able to get rid of my 
`surroundSelectionWith` javascript port...

On Wednesday, July 27, 2016 at 12:56:24 AM UTC-6, Atamert Ölçgen wrote:
>
> Have you tried this:
>
> http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Events#on
>
> On Tue, Jul 26, 2016 at 11:02 PM, OvermindDL1  > wrote:
>
>> When a user clicks a button I am needing to take the text that is 
>> currently *selected* in a textarea and surround it with other text while 
>> retaining what is selected.  What is the method to do this in Elm.  Is 
>> there an onSelectionChanged callback or something that I am missing?
>>
>> -- 
>> 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.
>>
>
>
>
> -- 
> Kind Regards,
> Atamert Ölçgen
>
> ◻◼◻
> ◻◻◼
> ◼◼◼
>
> www.muhuk.com
>

-- 
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] Incosistent Port subscription

2016-07-27 Thread Zeljko Nesic
Hi, 

I have run to weird issue regarding sending data to port. 

*Background*

I am working on Angular app, that I want piece by piece replace with Elm. 
During the transition, ports are really important, so I can communicate 
data back and fourth. 

Now I have some Angular directive [basically a component], who's controller 
after fetching some data, will send it to Elm. Code is something along the 
lines of : 

controller: function($scope, dataservice){
  // $scope.id is unique for each directive, eg. controller
  dataservice.get()
.then (sendToElm($scope.$id)); 
}

function sendToElm (id){
 (data) => elmApp.ports.foo.send([id, data]);
}


Now this works fine if I have one controller, i.e. one directive on the 
page. But problem comes when I have multiple directives, ie, this 
controller function *fires couple of times in short interval. *

*Problem*

So the problem lies in the fact that ports don't accept second *send 
*invocation 
in short burst. 

When I tried to isolate test case, everything worked fine, no matter how 
fast I feed data into Elm.

So I had go back to my Angular app and check what is wrong. 

When I added random timeout, greater that 1s things started to work fine: 

controller: function($scope, dataservice){
  // $scope.id is unique for each directive, eg. controller
  dataservice.get()
.then (sendToElm($scope.$id)); 
}

function sendToElm (id){
 (data) => {
  time = parseInt(Math.random() * 1000);
  setTimeout(() => { 
elmApp.ports.foo.send([id, data]); 
  }, time);
 }
}

But the issue seems to persist if I decrease that 1000 multiplier to 
anything less than 900. 

Now I wonder, can anybody bring any insight into why this is behaving like 
it is. 

Many thanks folks

-- 
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: iframe performance

2016-07-27 Thread Nils Eriksson
It's pretty laggy

-- 
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: Trying to understand the community overlap between Elm and Elixir

2016-07-27 Thread John Orford
> Elm on the backend is ultimately the way to go.

A little tangential - have you seen this?

http://noisycode.com/blog/2016/06/27/introducing-mlfe/

On Mon, 18 Jul 2016 at 18:15 Rex van der Spuy  wrote:

>
>
>> Can someone help clarify why Elixir is appealing to Elm developers
>> specifically (as opposed to Elixir being appealing on its own merits)?
>>
>
> Actually, Elm is appealing to Elixir developers, not the other way around
> ;)
> A lot of the talk you see around Elixer in Elm's discussion forums seems
> to be from Elixer developers who have found Elm to be a useful front-end
> solution.
> Elm on the backend is ultimately the way to go.
>
> --
> 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] textarea selection

2016-07-27 Thread Atamert Ölçgen
Have you tried this:

http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Events#on

On Tue, Jul 26, 2016 at 11:02 PM, OvermindDL1  wrote:

> When a user clicks a button I am needing to take the text that is
> currently *selected* in a textarea and surround it with other text while
> retaining what is selected.  What is the method to do this in Elm.  Is
> there an onSelectionChanged callback or something that I am missing?
>
> --
> 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.
>



-- 
Kind Regards,
Atamert Ölçgen

◻◼◻
◻◻◼
◼◼◼

www.muhuk.com

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