Re: [elm-discuss] Re: control structure

2016-10-13 Thread Joey Eremondi
>
> One current limitation of Elm is that there is no tail call elimination


Like Janis says, this is not true, and in most cases, tail-recursive
functions will become while-loops in the resulting JS.

For example, consider a list-summing function:

sum : List Int -> Int
sum =
  let
helper accum lst =
  case lst of
[] -> accum
(h :: t) -> helper (h + accum) t
  in
helper 0

This gets turned into the following JS in 0.18 (though TCO has been around
for a few versions):

var _user$project$Main$sum = function () {
var helper = F2(
function (accum, lst) {
helper:
while (true) {
var _p0 = lst;
if (_p0.ctor === '[]') {
return accum;
} else {
var _v1 = _p0._0 + accum,
_v2 = _p0._1;
accum = _v1;
lst = _v2;
continue helper;
}
}
});
return helper(0);
}();



On Thu, Oct 13, 2016 at 9:10 PM, Janis Voigtländer <
janis.voigtlaen...@gmail.com> wrote:

> Your statement about tail call elimination is wrong. The Elm compiler does
> it.
>
> Am 13.10.2016 um 23:38 schrieb Kasey Speakman :
>
> It probably sounds insane that Elm doesn't have `for` or `while`. It would
> to me before exposure to functional programming.
>
> There are prebuilt functions for working with collections like List
>  and Array
>  which
> will take care of most needs.
>
> When you find you need something a bit more custom, a recursive loop is
> the normal way. Those take a little practice to get the feel for them.
>
> Often when I write my own recursive loop, I later find that I can
> accomplish the same by combining list operations or by just playing with
> List.foldr.
>
> One current limitation of Elm is that there is no tail call elimination
> when using a recursive loop, so if you write your own loop and have a large
> list, you can get a stack overflow. In practice, this is not a typical
> problem due to other factors. I.e. miles of data on the screen impacts
> performance, and is not considered good UX.
>
> On Wednesday, October 12, 2016 at 5:52:31 AM UTC-5, Patricia Nicole
> Benedicto wrote:
>>
>> hi can i ask what is the repetiton control structucture of this
>> programming languages?
>>
> --
> 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] Re: control structure

2016-10-13 Thread Janis Voigtländer
Your statement about tail call elimination is wrong. The Elm compiler does it. 

> Am 13.10.2016 um 23:38 schrieb Kasey Speakman :
> 
> It probably sounds insane that Elm doesn't have `for` or `while`. It would to 
> me before exposure to functional programming.
> 
> There are prebuilt functions for working with collections like List and Array 
> which will take care of most needs.
> 
> When you find you need something a bit more custom, a recursive loop is the 
> normal way. Those take a little practice to get the feel for them.
> 
> Often when I write my own recursive loop, I later find that I can accomplish 
> the same by combining list operations or by just playing with List.foldr.
> 
> One current limitation of Elm is that there is no tail call elimination when 
> using a recursive loop, so if you write your own loop and have a large list, 
> you can get a stack overflow. In practice, this is not a typical problem due 
> to other factors. I.e. miles of data on the screen impacts performance, and 
> is not considered good UX.
> 
>> On Wednesday, October 12, 2016 at 5:52:31 AM UTC-5, Patricia Nicole 
>> Benedicto wrote:
>> hi can i ask what is the repetiton control structucture of this programming 
>> languages?
> 
> -- 
> 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: control structure

2016-10-13 Thread David Legard

>
> When you find you need something a bit more custom, a recursive loop is 
> the normal way. Those take a little practice to get the feel for them.


I now make it a rule to see if I can avoid explicit recursion by using 
*scan* or *fold* instead.

-- 
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: control structure

2016-10-13 Thread Kasey Speakman
It probably sounds insane that Elm doesn't have `for` or `while`. It would 
to me before exposure to functional programming.

There are prebuilt functions for working with collections like List 
 and Array 
 which will 
take care of most needs.

When you find you need something a bit more custom, a recursive loop is the 
normal way. Those take a little practice to get the feel for them.

Often when I write my own recursive loop, I later find that I can 
accomplish the same by combining list operations or by just playing with 
List.foldr.

One current limitation of Elm is that there is no tail call elimination 
when using a recursive loop, so if you write your own loop and have a large 
list, you can get a stack overflow. In practice, this is not a typical 
problem due to other factors. I.e. miles of data on the screen impacts 
performance, and is not considered good UX.

On Wednesday, October 12, 2016 at 5:52:31 AM UTC-5, Patricia Nicole 
Benedicto wrote:
>
> hi can i ask what is the repetiton control structucture of this 
> programming languages?
>

-- 
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: Integrating Elm with Web Components / Polymer

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Thursday, October 13, 2016 at 12:23:30 PM UTC+1, Rupert Smith wrote:
>
> Which is ok, but what I really want is for the listbox user to be able to 
> display more than just a string in the listbox, along these lines:
>
> root : Model -> Html Msg
> root model =
> listbox [ attrForSelect "value", onSelectedChanged SelectChanged ]
> [ listItem  [ value "1" ] [ text "one" ],
>   listItem  [ value "2" ] [ text "two" ],
>   ...
> ]
>

I have been having a little experiment with adding events into the UI 
component.

On the consumer side I did this:

listbox [ items model.roleLookup, onSelectedChanged 
SelectChanged ]
[ Button.render Mdl
[ 0 ]
model.mdl
[ Button.onClick SomeAction
]
[ text "test" ]
]
] 

When I click the button, the event is received by the consumer application.

On the component side, I did this:

woodItem
styleAttrs
[ text value
, (Button.render Mdl
[ 5 ]
model.mdl
[ Button.onClick (Select "test") ]
[ text "test" ]
  )
]

Clicking this button triggers the Select "test" event on the consumer Elm 
program. So now I have a UI element owned by the consuming application, 
showing a list of items rendered by the component application. Within it 
there is a button which triggers an event on the consumer, and buttons 
which trigger events on the component!

If I would like the consumer of a component to be able to custom render 
within the component, allowing the consumer to build whatever  it 
wants inside the component would be convenient. However, I could still have 
the component render custom content, by simply creating a little DSL for 
building HTML, and passing this down as part of the component config, and 
having the component render it.

So between those two options, I think I can do components that are very 
customizeable from the consumer of the components perspective. But I have 
to chose which side it would be more useful to let the consumer define 
events on?

For example, if the component were a data table, and there was a column 
with 'action' button in it, for example, to take you to a screen to edit an 
item from the table, it makes sense for the consumer to be able to hook 
into the event.

If the component were the video example, with the consumer defining a 
custom control bar, it would be useful for the DSL to allow the consumer to 
say that a button hooks up to the components 'pause' action.

Be nice if I could do both, but I can't see a way to doing that yet.

Also, for the pause action, I could set a property instead of directly 
triggering an event within the component. Then the consumer could hook up 
to the pause button and set property playState = "paused" on the component, 
which will in turn get picked up by the component.

On that basis, I guess it is more useful to allow the consumer of a 
component to render customer  within it using the Html library and 
Html.Events.

-- 
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: http "middleware" options

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Thursday, October 13, 2016 at 2:17:50 AM UTC+1, Fa Qing wrote:
>
> The PageLevel is calling the service level for a command. We want 
> intermediate effects, before the final command. But we don't want to just 
> issue intermediate commands either, because the state that is reacting to 
> the final command (the only one we have currently) could also be affected 
> by the intermediate command. Also, it doesn't help us refactor out the 
> (common) inputs into the service layer, such as a header value we need to 
> write out.
>
> It seems like there's a missing abstraction from the Elm architecture.
>

Hi,

I decided to make an Auth module a special case, and not use the nested TEA 
architecture for it.

I have an API like this for Auth:

port module Auth exposing (..)

type alias Credentials =
{ username : String
, password : String
}

login : Credentials -> Cmd msg
login authRequest =
sendLogin authRequest

logout : Cmd msg
logout =
sendLogout ()

unauthed : Cmd msg
unauthed =
sendUnauthed ()

port sendLogin : Credentials -> Cmd msg
port sendLogout : () -> Cmd msg
port sendUnauthed : () -> Cmd msg

The ports I can use from anywhere in the application to login, logout or on 
a 403 unauthorized to set the global state to not logged in (unauthed).

The token is part of the state of the Auth module, which is linked in to 
the global state of the Main module of the application. All Msgs to 
sub-modules go through the update method of the Main module, and use the 
nested TEA and the 'lift' function from Material.Helpers to forwad them on 
the appropriate child module. Like this:

AccountsMsg a ->
lift .accounts (\m x -> { m | accounts = x }) AccountsMsg 
Accounts.State.update a model

Passes events for the Accounts module on to it.

This could easily be adapted to pass along the current Auth token.

Another way, perhaps more convenient, could be to hold the Auth token in 
'session storage' (not local storage as that would be insecure), and 
provide a global port in the Auth module to obtain it.

As Peter suggests, make all your API call functions take the token as an 
extra arg.

I didn't need that as I opted to use cookies, which means the browser does 
it for me. However, at some point I will need to deal with APIs that insist 
on tokens in the header. I think treating auth as a bit of a special case 
and using some ports to make it more easily global across the application 
feels right to me. It is not necessary though, there are other ways of 
doing 'out messages' whereby a child module sends a message to another 
child module without resorting to using ports.

-- 
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: Getting functions out of the model

2016-10-13 Thread Zinggi
These are some very good points.
I don't see how a library that doesn't store functions in the model could 
deal with these situations as easy as your library does.

The only possible solution I can think of is that you could extend the 
description of an animation to include possible future interruptions and 
delays.
e.g.

animationDescription =
  Animation {..., easing=something, onInterrupt= Delay 0.2 (Animation {..., 
easing=somethingElse}) }

I don't know whether this could cover all your use cases, and it might be 
difficult to use.


On Thursday, 13 October 2016 21:56:54 UTC+2, Matthew Griffith wrote:
>
>
> So it's not necessarily not having interruptible animations, it's more all 
> the code that you'll need to manage them.  
>
> In elm-style-animation you can just start a new animation and 
> interruptions are handled automatically.
>
> When you have description and state split, you have to juggle switching 
> out the animationDescription at the right time.
>
> view model =
>   animate animationDescription model.animationState
>
> becomes the following when you have multiple possible animation 
> descriptions.  Lets say we have model.animId to keep track of what 
> description is running so we can switch between them.
>
>
> view model =
> let 
> myAnimationDescription = lookup model.animId
> in
> animate animationDescription model.animationState
>
> Easy peasy.  
>
> What about when you want to have a delay and then an interruption, you 
> have to keep track of the delay and switching out animationDescription when 
> the interruption occurs.  Great, we can do that.
>
> You also have to implement logic that handles what happens when multiple 
> delayed interruptions are queued up.  So now you have a queue of animation 
> interruptions to manage.  Ok then.
>
> Basically all of this is totally writable code...it's just that that's a 
> large part of the built in functionality of the elm-style-animation 
> library.  Why write all that code if a library handles it out of the box?
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Thursday, October 13, 2016 at 3:25:17 PM UTC-4, Zinggi wrote:
>>
>> @Frederick
>> Yes, that's where I got my inspiration from ;)
>>
>> @Matthew
>> I don't think this is a problem, but I also don't understand what you 
>> mean by "you'd have to do all the interruptions manually".
>> Could you elaborate?
>> I haven't studies your library closely, so I don't know how your library 
>> currently deals with interruptions.
>>
>> I once created an animation library for react 
>> , it kinda works like I described 
>> above and it does have interruptable animations.
>> But of course react doesn't map nicely to elm.
>>
>>
>> On Thursday, 13 October 2016 21:02:29 UTC+2, Frederick Yankowski wrote:
>>>
>>> The elm-autocomplete package does something much like you describe. 
>>> Configuration data, including some functions, is defined separately from 
>>> the model and is passed as an additional parameter to the update function.
>>>
>>>
>>> https://github.com/thebritican/elm-autocomplete/blob/4.0.1/src/Autocomplete.elm#L181
>>>
>>> On Thursday, October 13, 2016 at 1:34:29 PM UTC-5, Zinggi wrote:
>>>
>>> I think it would be nice to separate the *descriptions* of an animation 
 from the *state* of an animation.

>>> ​
>>>
>>

-- 
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-13 Thread 'Rupert Smith' via Elm Discuss
On Thursday, October 13, 2016 at 9:20:36 PM UTC+1, Rupert Smith wrote:
>
> On Tuesday, October 11, 2016 at 9:09:31 PM UTC+1, OvermindDL1 wrote:
>>
>> Remember, it is just a diffing algorithm, when it gets to that point of 
>> your vdom and it compares an old vdom node of, for example:
>> ```
>>   checkbox [ onClick (CheckToggle 42) ] [ text "Something" ]
>> ```
>> and compares it to the new of:
>> ```
>>   checkbox [ onClick (CheckToggle 43) ] [ text "Another thing" ]
>> ```
>> It sees that there are two changes (well potentially 1 due to lack of 
>> keyed event handlers, but we'll say 2 for this example), thus it accesses 
>> the checkbox at the index that it is at here (say, 14 or so) by just 
>> something like `var node = curNode.children[14];` then just applies the 
>> two changes `node.removeEventHandler("click", oldEvent); 
>> node.addEventHandler("click", newEvent); node.children[0].nodeValue = 
>> "Another thing";`, which was just removing the old event handler, adding 
>> the new, and mutating the text.
>>
>  
> Interesting to see this expained, thanks.
>

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?

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

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Tuesday, October 11, 2016 at 9:09:31 PM UTC+1, OvermindDL1 wrote:
>
> Remember, it is just a diffing algorithm, when it gets to that point of 
> your vdom and it compares an old vdom node of, for example:
> ```
>   checkbox [ onClick (CheckToggle 42) ] [ text "Something" ]
> ```
> and compares it to the new of:
> ```
>   checkbox [ onClick (CheckToggle 43) ] [ text "Another thing" ]
> ```
> It sees that there are two changes (well potentially 1 due to lack of 
> keyed event handlers, but we'll say 2 for this example), thus it accesses 
> the checkbox at the index that it is at here (say, 14 or so) by just 
> something like `var node = curNode.children[14];` then just applies the 
> two changes `node.removeEventHandler("click", oldEvent); 
> node.addEventHandler("click", newEvent); node.children[0].nodeValue = 
> "Another thing";`, which was just removing the old event handler, adding 
> the new, and mutating the text.
>
 
Interesting to see this expained, thanks.

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.

-- 
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: Getting functions out of the model

2016-10-13 Thread Matthew Griffith

So it's not necessarily not having interruptible animations, it's more all 
the code that you'll need to manage them.  

In elm-style-animation you can just start a new animation and interruptions 
are handled automatically.

When you have description and state split, you have to juggle switching out 
the animationDescription at the right time.

view model =
  animate animationDescription model.animationState

becomes the following when you have multiple possible animation 
descriptions.  Lets say we have model.animId to keep track of what 
description is running so we can switch between them.


view model =
let 
myAnimationDescription = lookup model.animId
in
animate animationDescription model.animationState

Easy peasy.  

What about when you want to have a delay and then an interruption, you have 
to keep track of the delay and switching out animationDescription when the 
interruption occurs.  Great, we can do that.

You also have to implement logic that handles what happens when multiple 
delayed interruptions are queued up.  So now you have a queue of animation 
interruptions to manage.  Ok then.

Basically all of this is totally writable code...it's just that that's a 
large part of the built in functionality of the elm-style-animation 
library.  Why write all that code if a library handles it out of the box?














On Thursday, October 13, 2016 at 3:25:17 PM UTC-4, Zinggi wrote:
>
> @Frederick
> Yes, that's where I got my inspiration from ;)
>
> @Matthew
> I don't think this is a problem, but I also don't understand what you mean 
> by "you'd have to do all the interruptions manually".
> Could you elaborate?
> I haven't studies your library closely, so I don't know how your library 
> currently deals with interruptions.
>
> I once created an animation library for react 
> , it kinda works like I described 
> above and it does have interruptable animations.
> But of course react doesn't map nicely to elm.
>
>
> On Thursday, 13 October 2016 21:02:29 UTC+2, Frederick Yankowski wrote:
>>
>> The elm-autocomplete package does something much like you describe. 
>> Configuration data, including some functions, is defined separately from 
>> the model and is passed as an additional parameter to the update function.
>>
>>
>> https://github.com/thebritican/elm-autocomplete/blob/4.0.1/src/Autocomplete.elm#L181
>>
>> On Thursday, October 13, 2016 at 1:34:29 PM UTC-5, Zinggi wrote:
>>
>> I think it would be nice to separate the *descriptions* of an animation 
>>> from the *state* of an animation.
>>>
>> ​
>>
>

-- 
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: Getting functions out of the model

2016-10-13 Thread Zinggi

@Frederick
Yes, that's where I got my inspiration from ;)

@Matthew
I don't think this is a problem, but I also don't understand what you mean 
by "you'd have to do all the interruptions manually".
Could you elaborate?
I haven't studies your library closely, so I don't know how your library 
currently deals with interruptions.

I once created an animation library for react 
, it kinda works like I described 
above and it does have interruptable animations.
But of course react doesn't map nicely to elm.


On Thursday, 13 October 2016 21:02:29 UTC+2, Frederick Yankowski wrote:
>
> The elm-autocomplete package does something much like you describe. 
> Configuration data, including some functions, is defined separately from 
> the model and is passed as an additional parameter to the update function.
>
>
> https://github.com/thebritican/elm-autocomplete/blob/4.0.1/src/Autocomplete.elm#L181
>
> On Thursday, October 13, 2016 at 1:34:29 PM UTC-5, Zinggi wrote:
>
> I think it would be nice to separate the *descriptions* of an animation 
>> from the *state* of an animation.
>>
> ​
>

-- 
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: Getting functions out of the model

2016-10-13 Thread Matthew Griffith

That's interesting as well.  Though I think you'd run into challenges when 
trying to handle interruptible animations. Specifically you'd have to do 
all the interruptions manually.  This would be even more challenging in the 
context of interruptions that have a delay before they're supposed to 
interrupt.


On Thursday, October 13, 2016 at 2:34:29 PM UTC-4, Zinggi wrote:
>
> I also thought about this problem for a bit.
> I came up with a slightly different solution.
>
> I was not only not happy with storing functions in my model, but also with 
> storing static values in the model (e.g. stuff that wont change often).
> I think it would be nice to separate the *descriptions* of an animation 
> from the *state* of an animation.
>
> So when you actually use an animation, you need to provide an animation 
> description and an animation state, this might look kinda like this:
>
> model =
>   { animationState = Animation.new 0 }
>
> update msg model =
>   case msg of
> Tick dt ->
>   { model | animationState = Animation.tick dt model.animationState }
>
> animationDescription =
>   { startValue = 0, endValue = 10, speed = 2, easing = Easing.sinInOut, 
> etc... }
>
> view model =
>   animate animationDescription model.animationState
>
>
> On Thursday, 13 October 2016 08:29:19 UTC+2, Aaron VonderHaar wrote:
>>
>> As mentioned in some recent threads [1] [2], easing functions for 
>> animations have been an example of where functions in the model are 
>> currently used.  An alternative approach is to use a union type to indicate 
>> the easing, but a suggested shortcoming of that approach is that there 
>> would then be no way for downstream developers to use their own custom 
>> easings.
>>
>> I was just thinking that this could be achieved as follows:
>>
>> ```
>> type AdvancedEasing a
>> = Linear | InQuad | OutQuad | ...
>> | CustomEasing a
>>
>> type alias Easing = AdvancedEasing Never
>>
>> apply : Easing -> Float -> Float
>>
>> applyAdvanced : (a -> Float -> Float) -> AdvancedEasing a -> Float -> 
>> Float
>> ```
>>
>> In this way, the custom easing functions (a -> Float -> Float) are moved 
>> from the model to configuration.
>>
>> I was curious if anyone has experimented with this approach yet.
>>
>>
>> [1]: https://groups.google.com/d/topic/elm-discuss/bOAHwSnklLc/discussion
>> [2]: https://groups.google.com/d/topic/elm-discuss/9qV9iDcv-c8/discussion
>>
>>

-- 
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: Getting functions out of the model

2016-10-13 Thread Frederick Yankowski


The elm-autocomplete package does something much like you describe. 
Configuration data, including some functions, is defined separately from 
the model and is passed as an additional parameter to the update function.

https://github.com/thebritican/elm-autocomplete/blob/4.0.1/src/Autocomplete.elm#L181

On Thursday, October 13, 2016 at 1:34:29 PM UTC-5, Zinggi wrote:

I think it would be nice to separate the *descriptions* of an animation 
> from the *state* of an animation.
>
​

-- 
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] Access JS (ports?) from an Effects Manager

2016-10-13 Thread Simon
I want to build code to work with a well known JS library, and to make it 
reusable. I'm going to need some state that is ancillary to the core 
functionality, and thought about an Effects Manager.

I know we are normally directed towards Evan's Websocket library, but that 
uses Native code and gets Tasks that way.

As Native is otherwise banned, I obviously thought of Ports. However, 
Effects Managers work with Tasks, while ports return Cmds, and while 
.perform can turn a Task into a Command, the reverse does not seem 
possible. 

Comments? Does anyone have an example of an Effects Manager working via a 
Port?


-- 
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: Getting functions out of the model

2016-10-13 Thread Zinggi
I also thought about this problem for a bit.
I came up with a slightly different solution.

I was not only not happy with storing functions in my model, but also with 
storing static values in the model (e.g. stuff that wont change often).
I think it would be nice to separate the *descriptions* of an animation 
from the *state* of an animation.

So when you actually use an animation, you need to provide an animation 
description and an animation state, this might look kinda like this:

model =
  { animationState = Animation.new 0 }

update msg model =
  case msg of
Tick dt ->
  { model | animationState = Animation.tick dt model.animationState }

animationDescription =
  { startValue = 0, endValue = 10, speed = 2, easing = Easing.sinInOut, 
etc... }

view model =
  animate animationDescription model.animationState


On Thursday, 13 October 2016 08:29:19 UTC+2, Aaron VonderHaar wrote:
>
> As mentioned in some recent threads [1] [2], easing functions for 
> animations have been an example of where functions in the model are 
> currently used.  An alternative approach is to use a union type to indicate 
> the easing, but a suggested shortcoming of that approach is that there 
> would then be no way for downstream developers to use their own custom 
> easings.
>
> I was just thinking that this could be achieved as follows:
>
> ```
> type AdvancedEasing a
> = Linear | InQuad | OutQuad | ...
> | CustomEasing a
>
> type alias Easing = AdvancedEasing Never
>
> apply : Easing -> Float -> Float
>
> applyAdvanced : (a -> Float -> Float) -> AdvancedEasing a -> Float -> Float
> ```
>
> In this way, the custom easing functions (a -> Float -> Float) are moved 
> from the model to configuration.
>
> I was curious if anyone has experimented with this approach yet.
>
>
> [1]: https://groups.google.com/d/topic/elm-discuss/bOAHwSnklLc/discussion
> [2]: https://groups.google.com/d/topic/elm-discuss/9qV9iDcv-c8/discussion
>
>

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

2016-10-13 Thread Timothy Williams
Whenever I google something like this, I always get discussions about Elm 
libraries for this. 

As someone new to css in general, I just want to be able to do normal css 
animations using elm to model the state, do the event handling, and render 
the html.

For example, if the state is toggled in the model to that hides a menu, can 
I use css to make that menu gradually disappear, as opposed to suddenly, 
without using an elm library?

Of course, I'm not referring to anything complex with canvas or svg, I can 
see the appeal of writing svg or canvas code in elm. I just mean for plain 
dom elements for a basic ui.

Would this be the preferred approach?

-- 
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] why -> Sub msg in ports instead of Sub Msg

2016-10-13 Thread Petr Vápenka
Lowercase "msg" is just a type parameter. It says that the first and second
occurence of "msg" in the type signature means the same type, whatever that
type it actually is.

If it was Sub Msg, Msg would be some actual type you would be forced to
work with.

Petr

On Thu, Oct 13, 2016 at 6:42 PM, António Ramos  wrote:

> I would like to know why Sub msg in lowercase in above code
>
> port suggestions : (List String -> msg) -> Sub msg
>
> --
> 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] why -> Sub msg in ports instead of Sub Msg

2016-10-13 Thread Janis Voigtländer
Relevant:
http://faq.elm-community.org/17.html#what-is-the-difference-between-cmd-msg-and-cmd-msg
​

2016-10-13 18:42 GMT+02:00 António Ramos :

> I would like to know why Sub msg in lowercase in above code
>
> port suggestions : (List String -> msg) -> Sub msg
>
> --
> 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] why -> Sub msg in ports instead of Sub Msg

2016-10-13 Thread António Ramos
I would like to know why Sub msg in lowercase in above code

port suggestions : (List String -> msg) -> Sub msg

-- 
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: Integrating Elm with Web Components / Polymer

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Wednesday, October 12, 2016 at 1:34:32 PM UTC+1, Rupert Smith wrote:
>
> So there is an issue with being able to change the state of the component, 
> post initialization, from the consumer of the component. Because if there 
> is a port used to set state on the component... which component?
>

So I have been able to solve this problem without resorting to passing an 
id for the component down the port. Instead, the Elm program managing the 
component listens to its properties using a subscription.

I changed the code to not use attributes to initialize the component, but 
instead use a property. This means that the data does not need to be 
serialized too.

You can then set up a property change listener on the webcomponent:

properties: {
items: {
type: Array,
notify: true,
observer: '_itemsChanged',
value: []
},

_itemsChanged: function(newValue, oldValue) {
if (app) {
app.ports.itemsChanged.send(newValue);
}
}

With app being the Elm program set up in attached:

attached() {
console.log("attached : items = " + this.items);

app = Elm.Listbox.embed(this);

this._itemsChanged(this.items, []);

app.ports.setSelected.subscribe(items => {
this.selected = items;
});
},

You will also notice that attached triggers the change notifier for the 
items, so as to set the items to be rendered for the first time, as the 
items may get set prior to 'attached()' being invoked.

This has proved to be very useful, as I had a situation where I created a 
view with a list of items, but the items had not yet been returned from a 
REST endpoint, so the list would show as empty. Now I can set the 'items' 
property after the initial creation of the component, and have the items 
update in the component.

-- 
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: using js library inside elm?

2016-10-13 Thread António Ramos
Nice. thank you.

2016-10-13 15:00 GMT+01:00 Wouter In t Velt :

> On Thu, Oct 13, 2016 at 5:46 AM, António Ramos  wrote:
>>
>>> any example of calling an external js method ?
>>>
>>
> Another example of calling external JS method is in the Todo.elm example
> app .
> Where port to JS is used to store the model in LocalStorage.
>
> --
> 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] Re: using js library inside elm?

2016-10-13 Thread Wouter In t Velt

>
> On Thu, Oct 13, 2016 at 5:46 AM, António Ramos  > wrote:
>
>> any example of calling an external js method ?
>>
>
Another example of calling external JS method is in the Todo.elm example app 
.
Where port to JS is used to store the model in LocalStorage. 

-- 
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: Learning Elm and feeling alone in the world

2016-10-13 Thread António Ramos
this guy is very good at it :)

https://www.youtube.com/watch?v=R6vuO547DC8

2016-06-22 17:49 GMT+01:00 Joe Terry :

> This is a really exciting time in the ELM community and I'm embracing the
> rapid ... breaking changes ... world that we are in now ... because the
> tools are in place (semantic versioning) for this to be a much, much more
> orderly world going forward than other ecosystems like NODEJS and what's
> going on over there ... Nightmare ...
>
> And I would love to be involved in educational tools as you describe ...
> it's a national economic imperative ... coding is working ... in the future
> unless you are an athlete or working with people in healthcare, law, the
> arts, etc. But for many if not most professions in 20 years and beyond, if
> you can't think logically or program computers in the most rudimentary way
> ... you will not be able to work.
>
> https://code.org/
>
> Great Stuff ... ELM is up to the task ... You are in the right place ...
> at the right time.
>
> Joe Terry
> The Software Sculptor
>
>
> On Wednesday, June 22, 2016 at 9:38:14 AM UTC-7, rud...@gmail.com wrote:
>>
>> Further to the above (in case I'm not clear enough about what is IMO
>> missing for Elm to become "the missing link") I found this updated Space
>> Invaders code: https://ohanhi.github.io/base-for-game-elm-017.html
>>
>> This 1.7 rewrite might be be near perfect as a foundation if only it took
>> the next step and added rudimentary graphics play.  Although it could use
>> more documentation it is simple enough that I can almost understand the
>> skeleton.Would adding graphics be really easy?  Could someone give me a
>> hint?
>> On Wednesday, June 22, 2016 at 9:05:34 AM UTC-7, rud...@gmail.com wrote:
>>>
>>>
>>>
>>> On Saturday, November 7, 2015 at 4:12:22 AM UTC-8, Mohammad Alshafey
>>> wrote:

 Is there sufficient material online for someone to learn Elm? It seems
 that the examples available each use different libraries and functions and
 each with some unique elements. There are no tutorials only basic
 introductions. The core library documentations are very abstract and
 lacking. Feeling stuck. I want to learn but there's nothing to go on!

>>> I had just decided to try and learn something and I'm also foundering.
>>>
>>> First:  A lot -- I'm inclined to say "most" -- of the online learning
>>> material has been broken by the switch to version 1.7.  "An Introduction to
>>> Elm" is only half there (the more useful half, where things are actually
>>> becoming graphical, is promised in "the next few weeks"how many weeks
>>> exactly?).  The online tutorial https://pragmaticstudio.com/elm has
>>> been removed.  I have no doubt the move to subscriptions vs signals will be
>>> good in the long run but right now it is pretty painful right now.
>>>
>>> Second:  Beyond this, even the existing docs are IMO too presumptive of
>>> prior knowledge.  There are few/no line by line comments in "An
>>> Introduction to Elm", for one specific example. Doubtless that is because
>>> "everyone" already understands the line-by-line basics but, in fact, they
>>> don't.  At least *I* don't.
>>>
>>> Suggestion: A single one page (52 line max but ideally less) graphical
>>> game MASSIVELY documented (I mean, don't let there be anything on the line
>>> which a reasonably intelligent sixth grader wouldn't already know go
>>> unremarked) would, I think, work wonders for Elm.   Something as simple as
>>> a blob which could be moved in four directions on a screen to "eat" static
>>> "fruit" would work wonders.  The working tetris (flatrus) game DOES work in
>>> 1.7 but it is way, way, way too complicated for tutorial purposes --
>>> especially since if follows the practice of basically assuming people don't
>>> need line by line comments).   With the most simplistic of graphical games
>>> MASSIVELY overdocumented a solid foundation of understanding and playing
>>> with Elm could be laid.  A great follow on would be to step-by-step (over
>>> explaining every step) build on that base. For example, add a counter.  Add
>>> reset buttons.  Add movement to the fruit.  Etc.
>>>
>>> I would love to participate in development / documentation of such a
>>> thing but I can't figure out how to get to the basic level of understanding
>>> of what is going on.  FYI I have only the most basic level of "basic"
>>> programming skill.  I don't know javascript (and don't want to learn) nor
>>> HTML nor how to design a webpage.  I am, therefore, a perfect candidate for
>>> a student.  My motivation for wanting a really, really, really easy on-ramp
>>> to Elm?   (1) Of the functional languages Elm is, or could be, the most
>>> approachable and "playable"  (2) I would like to teach Em to 6th graders as
>>> an on-ramp to functional programming and, then, to functional thinking.
>>>
>>> These kinds of simplistic and "obvious" games existed once upon a time;
>>> that is how I learned to write BASIC 

Re: [elm-discuss] Re: using js library inside elm?

2016-10-13 Thread Duane Johnson
The example in the guide (the link that Matthew sent) is about as compact
as you're going to find as an example.

I know you're probably looking for a simple example, but calling an
external javascript method is not a one-liner in Elm.

On Thu, Oct 13, 2016 at 5:46 AM, António Ramos  wrote:

> any example of calling an external js method ?
>
> 2016-10-13 12:44 GMT+01:00 Matthew Griffith :
>
>> You still have to use ports.  Check out the SpellCheck part of this
>> https://guide.elm-lang.org/interop/javascript.html
>>
>>
>> On Thursday, October 13, 2016 at 5:00:47 AM UTC-4, António Ramos wrote:
>>>
>>> hello i know that i have to use ports to pass data from elm to
>>> javascript but if i want to call an external  library method inside my elm
>>> is there a way to do it?
>>> As i load my exeternal js file before my compiled elm in my index.html
>>> file there should be a way right?
>>>
>>> regards
>>> António
>>>
>> --
>> 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] Re: using js library inside elm?

2016-10-13 Thread António Ramos
any example of calling an external js method ?

2016-10-13 12:44 GMT+01:00 Matthew Griffith :

> You still have to use ports.  Check out the SpellCheck part of this
> https://guide.elm-lang.org/interop/javascript.html
>
>
> On Thursday, October 13, 2016 at 5:00:47 AM UTC-4, António Ramos wrote:
>>
>> hello i know that i have to use ports to pass data from elm to javascript
>> but if i want to call an external  library method inside my elm is there a
>> way to do it?
>> As i load my exeternal js file before my compiled elm in my index.html
>> file there should be a way right?
>>
>> regards
>> António
>>
> --
> 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: using js library inside elm?

2016-10-13 Thread Matthew Griffith
You still have to use ports.  Check out the SpellCheck part of this 
https://guide.elm-lang.org/interop/javascript.html

On Thursday, October 13, 2016 at 5:00:47 AM UTC-4, António Ramos wrote:
>
> hello i know that i have to use ports to pass data from elm to javascript 
> but if i want to call an external  library method inside my elm is there a 
> way to do it?
> As i load my exeternal js file before my compiled elm in my index.html 
> file there should be a way right?
>
> regards
> António
>

-- 
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: Getting functions out of the model

2016-10-13 Thread Matthew Griffith
That's an interesting approach, though I'm not sure it would work for 
elm-style-animation, at least in its current form.   In elm-style-animation 
you compose an animation under one Msg, and send animation 
updates(basically tick the animation forward) via a separate Msg.  

The `apply` and `applyAdvanced` functions would have to live in the 
animation update Msg in order for them to work and not store anything in a 
model, but choosing an easing is conceptually part of composing an 
animation, not updating it. 
As a sidenote, an animation in elm-style-animation can have any number of 
separate easings used in different stages of the animation.  This 
complicates things a bit for an implementation.

```
Animation.interrupt
 [ Animation.toWith {duration=(1*second), easing=identity)}
[opacity 0]
, Animation.toWith {duration=(1*second), easing=(\x -> x^2)}
[opacity 0]
]

```






On Thursday, October 13, 2016 at 2:29:19 AM UTC-4, Aaron VonderHaar wrote:
>
> As mentioned in some recent threads [1] [2], easing functions for 
> animations have been an example of where functions in the model are 
> currently used.  An alternative approach is to use a union type to indicate 
> the easing, but a suggested shortcoming of that approach is that there 
> would then be no way for downstream developers to use their own custom 
> easings.
>
> I was just thinking that this could be achieved as follows:
>
> ```
> type AdvancedEasing a
> = Linear | InQuad | OutQuad | ...
> | CustomEasing a
>
> type alias Easing = AdvancedEasing Never
>
> apply : Easing -> Float -> Float
>
> applyAdvanced : (a -> Float -> Float) -> AdvancedEasing a -> Float -> Float
> ```
>
> In this way, the custom easing functions (a -> Float -> Float) are moved 
> from the model to configuration.
>
> I was curious if anyone has experimented with this approach yet.
>
>
> [1]: https://groups.google.com/d/topic/elm-discuss/bOAHwSnklLc/discussion
> [2]: https://groups.google.com/d/topic/elm-discuss/9qV9iDcv-c8/discussion
>
>

-- 
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] Personal trainer ?

2016-10-13 Thread António Ramos
Hello i need an "expert" elm personal trainer
I´m in Portugal . the chosen one will get a week offer in
http://www.booking.com/hotel/pt/romantic-spa.pt-pt.html?aid=311098;label=romantic-spa-AbhuY4Mto34pPpnuKyglJQS52637424275%3Apl%3Ata%3Ap1%3Ap2%3Aac%3Aap1t1%3Aneg%3Afi%3Atiaud-146342138710%3Akwd-381243277%3Alp20865%3Ali%3Adec%3Adm;sid=29357db8b53203bc67b17da12f8e4ee5;dest_id=-2179627;dest_type=city;dist=0;room1=A%2CA;sb_price_type=total;srfid=3d3c02d747dbfe0a8ac611c44cfdfce7bca54d2dX1;type=total;ucfs=1;

valid for 2 people in november subject to discussion for the dates.
I need 3 hours a day ( in the evening). the rest of the day is free  and
i´m far away...
Dont need to bring a PC. i have 2 laptops...

Take it or leave it :)

Regards
António

-- 
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: Integrating Elm with Web Components / Polymer

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Tuesday, October 11, 2016 at 11:21:05 AM UTC+1, Rupert Smith wrote:
>
> I'm interested in expanding on the counter example to add more complexity 
> - and I have a component in mind that will be useful to me - the listbox 
> that I was working with previously.
>

So I have a first pass at making a listbox component, you can find it here:

https://github.com/rupertlssmith/wood-polymer

Sticking with the Polymer elements naming convention, I called this library 
'wood', since that also fits with the Elm theme...
 
I create a listbox like this:

root : Model -> Html Msg
root model =
listbox
[ items (Dict.fromList [ ( "1", "one" ), ( "2", "two" ), ( "3", 
"three" ) ])
, onSelectedChanged SelectChanged
]

Which is ok, but what I really want is for the listbox user to be able to 
display more than just a string in the listbox, along these lines:

root : Model -> Html Msg
root model =
listbox [ attrForSelect "value", onSelectedChanged SelectChanged ]
[ listItem  [ value "1" ] [ text "one" ],
  listItem  [ value "2" ] [ text "two" ],
  ...
]

But if the listitems are rendered withon the scope of the consuming Elm 
program, I run straight away into the previously discussed issue of not 
knowing which component to attach events to.

A listbox seems like quite a good component for allowing the consumer to 
decide how to render the list items. I might like an icon for example, or a 
checkbox which gets ticked when an item is selected, and so on. But it is 
wokring nicely for a plain text list.

-- 
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] any boilerplate of elm and cordova ?

2016-10-13 Thread António Ramos
Hi all
where can i find a simple boilerplate of elm and cordova together ?

Regards
António

-- 
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: Integrating Elm with Web Components / Polymer

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Thursday, October 13, 2016 at 9:33:18 AM UTC+1, Rupert Smith wrote:
>
> On Wednesday, October 12, 2016 at 5:34:36 PM UTC+1, Peter Damoc wrote:
>>
>> On Wed, Oct 12, 2016 at 6:57 PM, 'Rupert Smith' via Elm Discuss <
>> elm-d...@googlegroups.com> wrote:
>>
>>> This limitation means you can't have UI elements defined outside of a 
>>> component affect its state. Suppose you had a video component and a video 
>>> control bar compnent, you could not make those separate components, you'd 
>>> always have to embed the control bar inside the video component. 
>>>
>>
>> To my understanding, Html elements are treated as stateless so, there is 
>> no semantic to tell a certain Html element anything just like you cannot 
>> tell the integer number 42 to do something. It's just data. It's not an 
>> object.  
>>
>> If someone wants to say something to the actual html element, they have 
>> to give that element an ID in Elm and go to JS in order to give it a 
>> message.
>>
>
> Right, that is good point. State must always go on the model. 
>
> Sticking with my video controller analogy - suppose we put the "pause : 
> Bool" on the model, then the onClick action can simply set the state there. 
> Perhaps you could define a record visible in the components API, that holds 
> all of its state that can be modified from the outside. I wonder what 
> happens though, when the video component is re-built from this model:
>
> type alias Model =
> { ...
> , vidState : Video.Model
> }
>
> video model.vidstate [ src "http://myvids.com/cute_cats.mpg 
> "
>  
> ]
> [ videoControl [] [ button [ onclick Pause ] [ text "pause" ] ] ]
>
> Presumably the change to the state would cause a brand new video control 
> to be rendered and lose internal state like which point in the video you 
> were currently watching?
>
> Still, I quite like the idea of making any externally accesible state an 
> explicit type in the Elm program, even if the above approach were combined 
> with a ComponentId and a helper function using a port to set state on the 
> component; at least from the point of view of the Elm program we are 
> keeping state in the model not the Html component.
>

Any updates to the components state could be handled by a single helper 
function, which is quite convenient:

updateComponent : ComponentId -> Model -> Cmd msg

or perhaps you always put the ComponentId in the Model so it is just

updateComponent : Model -> Cmd msg

-- 
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: Integrating Elm with Web Components / Polymer

2016-10-13 Thread 'Rupert Smith' via Elm Discuss
On Wednesday, October 12, 2016 at 5:34:36 PM UTC+1, Peter Damoc wrote:
>
> On Wed, Oct 12, 2016 at 6:57 PM, 'Rupert Smith' via Elm Discuss <
> elm-d...@googlegroups.com > wrote:
>
>> This limitation means you can't have UI elements defined outside of a 
>> component affect its state. Suppose you had a video component and a video 
>> control bar compnent, you could not make those separate components, you'd 
>> always have to embed the control bar inside the video component. 
>>
>
> To my understanding, Html elements are treated as stateless so, there is 
> no semantic to tell a certain Html element anything just like you cannot 
> tell the integer number 42 to do something. It's just data. It's not an 
> object.  
>
> If someone wants to say something to the actual html element, they have to 
> give that element an ID in Elm and go to JS in order to give it a message.
>

Right, that is good point. State must always go on the model. 

Sticking with my video controller analogy - suppose we put the "pause : 
Bool" on the model, then the onClick action can simply set the state there. 
Perhaps you could define a record visible in the components API, that holds 
all of its state that can be modified from the outside. I wonder what 
happens though, when the video component is re-built from this model:

type alias Model =
{ ...
, vidState : Video.Model
}

video model.vidstate [ src "http://myvids.com/cute_cats.mpg 
"
 
]
[ videoControl [] [ button [ onclick Pause ] [ text "pause" ] ] ]

Presumably the change to the state would cause a brand new video control to 
be rendered and lose internal state like which point in the video you were 
currently watching?

Still, I quite like the idea of making any externally accesible state an 
explicit type in the Elm program, even if the above approach were combined 
with a ComponentId and a helper function using a port to set state on the 
component; at least from the point of view of the Elm program we are 
keeping state in the model not the Html component.

-- 
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: Pure Elm contenteditable rich text editor

2016-10-13 Thread Bulat Shamsutdinov
Thank you everyone! I'm currently studying Draft.js to see their way of 
implementing rich text edit.

-- 
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] Getting functions out of the model

2016-10-13 Thread Aaron VonderHaar
As mentioned in some recent threads [1] [2], easing functions for
animations have been an example of where functions in the model are
currently used.  An alternative approach is to use a union type to indicate
the easing, but a suggested shortcoming of that approach is that there
would then be no way for downstream developers to use their own custom
easings.

I was just thinking that this could be achieved as follows:

```
type AdvancedEasing a
= Linear | InQuad | OutQuad | ...
| CustomEasing a

type alias Easing = AdvancedEasing Never

apply : Easing -> Float -> Float

applyAdvanced : (a -> Float -> Float) -> AdvancedEasing a -> Float -> Float
```

In this way, the custom easing functions (a -> Float -> Float) are moved
from the model to configuration.

I was curious if anyone has experimented with this approach yet.


[1]: https://groups.google.com/d/topic/elm-discuss/bOAHwSnklLc/discussion
[2]: https://groups.google.com/d/topic/elm-discuss/9qV9iDcv-c8/discussion

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