Some new user questions

90 views
Skip to first unread message

Mark Green

unread,
Jun 22, 2016, 10:44:04 AM6/22/16
to Elm Discuss
Hi,

I've recently tried doing a project in Elm (http://github.com/hyphz/StrikeGen if you're interested) and have a couple of questions I'd like to ask:

1) Is there any function for setting/updating a field in a record, similar to the .x functions for accessing fields? It's very awkward that in order to pass an updater to a higher order function I have to write (\newvalue, structure -> {structure | field = newvalue}) and because the field name is a syntax token I potentially have to rewrite this for every field.

2) Is there any version of case with the C++ fall-through behavior for occasions when accumulated results are desirable?

3) Is there any way to a) default a field in a record, or b) read a common field from a tagged union type?

4) I would like to have a document created in Elm be viewable with zoom+pan in HTML. There is the jQuery.panzoom library that can do this but a) is it going to interfere with Elm's DOM differ and b) to initialize it I need to send a port command to JS immediately after the view is displayed for the first time (otherwise the DIV will not exist - I can't just embed the elm in that DIV because there is a second DIV which should not zoom+pan) - is there a way of doing this? Will a command in init be sent at that point?

Mark

Janis Voigtländer

unread,
Jun 22, 2016, 10:58:47 AM6/22/16
to elm-d...@googlegroups.com
The answers to all of 1) to 3) are no.

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

Mark Green

unread,
Jun 22, 2016, 1:16:52 PM6/22/16
to Elm Discuss
Fair enough.

The situation is that as part of the view update, my database model is calculating what inputs it needs displayed by passing a form data structure to the view component which renders it in HTML. The current type is:

type Field =
    DropdownField { name: String, key : String, choices: (List String), del: Bool }
  | FreeformField { name: String, key : String, del: Bool }
  | NumberField { name: String, key: String, min: Int, max: Int, del: Bool }

There's two problems. First of all, there's some common validation done before any field is displayed involving checking that the key exists in the database (which is a Dict) and getting its value. At the moment, in order to do that I have to have a function

fieldKey x = case x of
  DropdownField df -> df.key
  FreeformField ff -> ff.key
  NumberField nf -> nf.key

which seems a bit awkward. As I understand it I could use a generic record instead by removing the tags on the field types above, but that creates the problem that if the function that does the preprocessing accepts the value as a generic record { key: String } then it can't call the function to render the field because that requires all the components of the record.

The second problem is that "del" field. It represents if the field can be deleted or not. It's a pain to have to constantly indicate it when it's in practice the same for all fields in any given form, but having to pass the form as well as the field to the field renderer is rather awkward, and as I understand it Elm doesn't support pointers so I can't put a reference back to the parent form in the field object.

Mark

Peter Damoc

unread,
Jun 22, 2016, 1:35:06 PM6/22/16
to Elm Discuss
How about modeling your problem differently:

type FieldData
    = DropdownField (List String) -- list of choices 
    | FreeformField
    | NumberField Int Int -- min max 


type alias Field =
    { name : String
    , key : String
    , del : Bool
    , data : FieldData
    }

This way you have easier access to the common fields. :) 



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



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

Mark Green

unread,
Jun 22, 2016, 8:04:11 PM6/22/16
to Elm Discuss
Nice. Makes a lot of sense, too. Thanks.

One more - is it possible for Elm to access the HTML field values submitted in the GET request? Or to load its values into an HTML form which is submitted? I've seen several examples online but they all seem to be either for earlier versions of Elm or to not actually perform submission.

Mark
Reply all
Reply to author
Forward
0 new messages