Re: [elm-discuss] Under what conditions will a node in the DOM be deleted and replaced?

2017-03-02 Thread 'Rupert Smith' via Elm Discuss
On Wednesday, March 1, 2017 at 9:30:32 PM UTC, Rupert Smith wrote:
>
> On Wednesday, March 1, 2017 at 4:24:54 PM UTC, Witold Szczerba wrote:
>>
>> So, you ask for a list of mutations and then, for each mutation you 
>> repeat exactly the same procedure which is not related to the mutation you 
>> are currently at.
>> Why are you iterating over mutations?
>>
>
> Good point. No need to iterate, its just got left in there from your code.
>
> Using a MutationObserver to implement a ResizeObserver does not seem the 
> best idea. I don't really like that I end up scanning from the top instead 
> of looking at an actual mutation 'target'. But this trick of putting the 
> observer at the top is needed to get around the virtual DOM issue that 
> prevents the observer being placed on the actual node that I want to watch, 
> so I suppose doing a scan from the top on any mutation is justified as it 
> is part of this workaround.
>
> A ResizeObserver would be better its 'target' would definitely be the 
> thing being resized - not having to guess something is resized because it 
> or one of its children was mutated. I think ResizeObserver is not so well 
> supported though, which is why I stuck with MutationObserver. I called the 
> Elm module I wrote around it ResizeObserver, with a view to rewriting it 
> with a ResizeObserver at some future time when ResizeObserver is widely 
> supported.
>

A more efficient way might be to start at the 'target' of the mutation, but 
then scan up the DOM ancestry until a node with the matching class us 
found, using jquery .closest:

https://api.jquery.com/closest/

Using that approach I would iterate all the mutations and scan upwards for 
each one.

-- 
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: Record syntax overhaul

2017-03-02 Thread 'Rupert Smith' via Elm Discuss
On Thursday, March 2, 2017 at 1:30:44 AM UTC, Francesco Orsenigo wrote:
>
> 2) 
> In my current project, I need to edit a "Rule" record.
> The app has already a "Rule" type, which *must* have an "id", because 
> that's how the data arrives from the DB and is displayed to the user.
> However, the form to edit a Rule will need a different type, because 
> depending on whether I am creating a new rule or editing an existing one, 
> it may or may not have an "id".
>

I have the same issue. All I did was to make the id a Maybe String.

When a record arrives from the server, having been looked up in the 
database, it contains id = Just "1234".
When I am creating a new record in the application to add to the database, 
it contains id = Nothing.

That way I am able to use the same record for both purposes.

Another way is to define your record as a tuple (or a record of records or 
a union type constructor with >1 arg):

type alias MyEntity = ( Id, Fields)
type alias MyEntity = { id : Id, fields : Fields)
type MyEntity = Entity Id Fields
type MyEntity = 
 Persistent Id Fields
   | Ephemeral Fields

Are some possible data modelling options for your problem.

It might be nice to have some syntactical sugar to add and remove fields 
from records easily, to produce new types. Perhaps it might encourage more 
fragmented data modelling though? instead of designing a Type that is 
sufficient to handle the whole problem.

P.S. I put the Maybe String for ids in my db records as a quick solution to 
the problem, but even at the time I was aware that there are more options 
that might need to be spelled out explicitly. Suppose you have a db record 
that hold a reference to another record, do you also fetch that record? or 
do you just fetch a link (reference) to it? or do you not fetch it at all? 
or does it not even exist? So maybe when one record holds a reference to 
another, all the options need to be spelled out in a union type:

type Ref a = 
   None
 | DontKnow
 | Link String
 | Value a

-- 
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: Record syntax overhaul

2017-03-02 Thread 'Rupert Smith' via Elm Discuss
On Thursday, March 2, 2017 at 11:21:20 AM UTC, Rupert Smith wrote:
>
> On Thursday, March 2, 2017 at 1:30:44 AM UTC, Francesco Orsenigo wrote:
>>
>> 2) 
>> In my current project, I need to edit a "Rule" record.
>> The app has already a "Rule" type, which *must* have an "id", because 
>> that's how the data arrives from the DB and is displayed to the user.
>> However, the form to edit a Rule will need a different type, because 
>> depending on whether I am creating a new rule or editing an existing one, 
>> it may or may not have an "id".
>>
>
> I have the same issue. All I did was to make the id a Maybe String.
>
> Blah blah blah
>

But don't let me put you off. There are plenty situations where some syntax 
sugar can make our code more concise, I do agree. 

-- 
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] Simple way to screen-share an application written in Elm?

2017-03-02 Thread 'Rupert Smith' via Elm Discuss
Anyone tried something along these lines:

The state of an application in Elm can be re-built by starting from its 
'init' state, then replaying all messages to a given state. This is called 
event sourcing.

If I am using some application written in Elm, and I want to share what I 
am doing with someone else, all I need is for them to start up the same 
application, the replay my event stream over it. Something like AMQP over 
Web Sockets could provide the transport layer.

There might need to be a way on the slave application to ignore all of the 
local users events, and only update the model from the event source from 
the master. That should be fairly easy to achieve by wrapping the Program 
with one that does this.

For a multi-user application, a simple but perhaps too inefficient way of 
keeping things in sync would be for all user events to be round-tripped 
through a message queue in order to put them in a sequential order that is 
the same for all participants. So local input events would not go straight 
to the update function, but be round tripped over the network. Would 
probably work well enough for a small number of users on the LAN.

Just curious to know if anyone has ever experimented with Elm along these 
lines.

-- 
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 decode nested Json Structure

2017-03-02 Thread Євген Петров
Hello, All

I do not understand how to work  Json.Decode.Pipeline for nested Json.

Json Structure
{
"count": "null",
"data": [
{
"configType": "2",
"date": "2012-02-07 11:51:29",
"desc": "Access Limiter",
"id": "26",
"term": "ACCESS_LIMITER"
},
{
"configType": "2",
"date": "2012-02-07 11:51:29",
"desc": "Sort top boxes",
"id": "2",
"term": "BOXES.SORT"
}
],
"messages": "",
"success": "true"
}

decodeRisResponse : Decode.Decoder RisConfigResponse
decodeRisResponse =
  decode RisConfigResponse
  |> required "count" Decode.string
  |> required "data" Decode.list
  |> required "message" Decode.string
  |> required "success" Decode.bool

decodeConfigs : Decode.Decoder (List Config)
decodeConfigs =
Decode.list decodeConfig

decodeConfig : Decode.Decoder Config
decodeConfig =
decode Config
|> required "id" Decode.string
|> required "term" Decode.string
|> required "desc" Decode.string
|> required "date" Decode.string
|> required "configType" Decode.string

type alias RisConfigResponse =
  {
count : String
, data : (List Config)
, message : String
, success : Bool
  }



type alias ConfigId = String

type alias Config =
 {
id: ConfigId
, term : String
, desc : String
, date : String
, configType : String
 }


But I have Error 

2:16:39 PM client.1 |  -- TYPE MISMATCH 
>  ./src/Commands.elm
> 2:16:39 PM client.1 |  The 2nd argument to function `required` is causing 
> a mismatch.
> 2:16:39 PM client.1 |  25|  required "data" Decode.list
> 2:16:39 PM client.1 |   ^^^
> 2:16:39 PM client.1 |  Function `required` is expecting the 2nd argument 
> to be:
> 2:16:39 PM client.1 |  Decode.Decoder (List a)
> 2:16:39 PM client.1 |  But it is:
> 2:16:39 PM client.1 |  Decode.Decoder a -> Decode.Decoder (List a)
> 2:16:39 P


How do it parse "data" : (List Config) ? 

P.S. Sorry for my english ^)

-- 
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 decode nested Json Structure

2017-03-02 Thread Witold Szczerba
Hi,
having a super-quick scan of your code, look at this line:

  |> required "data" Decode.list

You say: "data" is a list of… you did not tell what kind of list.
Have to go now, so you are on your own, but just focus on this problem.

Regards,
Witold Szczerba

On Thu, Mar 2, 2017 at 1:20 PM, Євген Петров  wrote:

> Hello, All
>
> I do not understand how to work  Json.Decode.Pipeline for nested Json.
>
> Json Structure
> {
> "count": "null",
> "data": [
> {
> "configType": "2",
> "date": "2012-02-07 11:51:29",
> "desc": "Access Limiter",
> "id": "26",
> "term": "ACCESS_LIMITER"
> },
> {
> "configType": "2",
> "date": "2012-02-07 11:51:29",
> "desc": "Sort top boxes",
> "id": "2",
> "term": "BOXES.SORT"
> }
> ],
> "messages": "",
> "success": "true"
> }
>
> decodeRisResponse : Decode.Decoder RisConfigResponse
> decodeRisResponse =
>   decode RisConfigResponse
>   |> required "count" Decode.string
>   |> required "data" Decode.list
>   |> required "message" Decode.string
>   |> required "success" Decode.bool
>
> decodeConfigs : Decode.Decoder (List Config)
> decodeConfigs =
> Decode.list decodeConfig
>
> decodeConfig : Decode.Decoder Config
> decodeConfig =
> decode Config
> |> required "id" Decode.string
> |> required "term" Decode.string
> |> required "desc" Decode.string
> |> required "date" Decode.string
> |> required "configType" Decode.string
>
> type alias RisConfigResponse =
>   {
> count : String
> , data : (List Config)
> , message : String
> , success : Bool
>   }
>
>
>
> type alias ConfigId = String
>
> type alias Config =
>  {
> id: ConfigId
> , term : String
> , desc : String
> , date : String
> , configType : String
>  }
>
>
> But I have Error
>
> 2:16:39 PM client.1 |  -- TYPE MISMATCH 
> 
>> ./src/Commands.elm
>> 2:16:39 PM client.1 |  The 2nd argument to function `required` is causing
>> a mismatch.
>> 2:16:39 PM client.1 |  25|  required "data" Decode.list
>> 2:16:39 PM client.1 |   ^^^
>> 2:16:39 PM client.1 |  Function `required` is expecting the 2nd argument
>> to be:
>> 2:16:39 PM client.1 |  Decode.Decoder (List a)
>> 2:16:39 PM client.1 |  But it is:
>> 2:16:39 PM client.1 |  Decode.Decoder a -> Decode.Decoder (List a)
>> 2:16:39 P
>
>
> How do it parse "data" : (List Config) ?
>
> P.S. Sorry for my english ^)
>
> --
> 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] Linear algebra (matrix, vectors, ...) in the context of image processing

2017-03-02 Thread Matthieu Pizenberg
I'm currently looking for a library to do some basic image processing and 
matrix manipulation stuff.

I have a research background (mostly spending time in Matlab), and 
currently preparing a user study. Elm has been great for my needs so far, 
but I'm encountering now a few obstacles.

Types and functions regarding the manipulations I might need could be:
* Binary image mask ~> could be some kind of Matrix/Array Bool
* Boolean mask operations (And, Or, ...) ~> I guess if using a _ Bool data 
structure, this is not complicated
* Mask generation from simple polygons
* etc.

The second issue, is the visualization of these masks/images. Until now, I 
was only dealing with raw png images, and polygons. So the obvious choice 
of representation was SVG. Now I'd also like to visualize those masks (that 
would be computed in some form of matrix data type). I do not know of a 
trivial way to do this in svg?

Finally, I wonder how to retrieve those (binary mask or not) images and 
transform them in a more computing-friendly data type (kind of imread in 
Matlab). Since I don't think Elm is able to manipulate byte data types, 
this doesn't seem trivial to me.

Any thought regarding these problematics?

-- 
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] Post Examples of Painful Record Updates Here!

2017-03-02 Thread Richard Feldman
There have been various discussions of potential ways to improve Elm's 
record update syntax. Evan commented that "(examples > design work) at this 
point" - any potential designs for syntax improvements would need to be run 
through a gauntlet of examples to see how well they'd work, so the first 
step in the process is to gather those examples.

So let's collect a ton of different real-world examples! That will help 
guide the design process.

If you've run into a record update that you felt was painful and could be 
improved in some way, please post it here! (Also, *please keep this thread 
for posting of examples* *only* - it'll be easier to link back here during 
design discussions if we can reference a clean thread of examples, as 
opposed to a mismash of examples interleaved with suggestions.)

-- 
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] Simple way to screen-share an application written in Elm?

2017-03-02 Thread Zachary Kessin
No but that would be a really cool idea, I can think of several places that
this could be useful, for example checking that things work the same on all
browsers. Or being able to generate a sequence of events from a quickcheck
type thing and play them in a browser.

Zach
ᐧ

On Thu, Mar 2, 2017 at 5:57 PM, 'Rupert Smith' via Elm Discuss <
elm-discuss@googlegroups.com> wrote:

> Anyone tried something along these lines:
>
> The state of an application in Elm can be re-built by starting from its
> 'init' state, then replaying all messages to a given state. This is called
> event sourcing.
>
> If I am using some application written in Elm, and I want to share what I
> am doing with someone else, all I need is for them to start up the same
> application, the replay my event stream over it. Something like AMQP over
> Web Sockets could provide the transport layer.
>
> There might need to be a way on the slave application to ignore all of the
> local users events, and only update the model from the event source from
> the master. That should be fairly easy to achieve by wrapping the Program
> with one that does this.
>
> For a multi-user application, a simple but perhaps too inefficient way of
> keeping things in sync would be for all user events to be round-tripped
> through a message queue in order to put them in a sequential order that is
> the same for all participants. So local input events would not go straight
> to the update function, but be round tripped over the network. Would
> probably work well enough for a small number of users on the LAN.
>
> Just curious to know if anyone has ever experimented with Elm along these
> lines.
>
> --
> 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.
>



-- 
Zach Kessin
Skype: zachkessin

-- 
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: Post Examples of Painful Record Updates Here!

2017-03-02 Thread Richard Feldman
Re-posting the first example from Franscisco's thread 
:

There is a common pattern where a library (ex, elm-markdown) will provide a 
default config, to be extended by the user.

Here the two ways to do this right now, one painfully verbose and the other 
relying on exposing values that would read better if fully qualified 
instead of exposed:

import Slides

slidesDefaultConfig =
  Slides.defaultConfig

myCustomSlidesConfig =
 { slidesDefaultConfig | someAttribute = myCustomvalue }

or

import Slides exposing (slidesDefaultConfig)

myCustomSlidesConfig =
 { slidesDefaultConfig | someAttribute = myCustomvalue }

Not a big deal TBH, but annoying.


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