Hi, are there official guidelines for structuring large scale apps ? For instance, what is the community take on things like https://github.com/rogeriochaves/structured-elm-todomvc/tree/modular ?
This is quite neat although I cannot quite m'y head round the fact the Update fonctions in TaskList deal with messages for Task ans TaskList, and they do not respect thé standard (Model, Cmd Msg) signatures ?
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Note: I plan to fill this section in with more examples of growing yourModel
andupdate
functions. It is roughly the same ideas though. If you find yourself repeating yourself, maybe break things out. If a function gets too big, make a helper function. If you see related things, maybe move them to a module. But at the end of the day, it is not a huge deal if you let things get big. Elm is great at finding problems and making refactors easy, so it is not actually a huge deal if you have a bunch of entries in yourModel
because it does not seem better to break them out in some way. I will be writing more about this!
update is a function that takes a message and a model and produces the updated version of the model. In some cases, update also can produce some requests for more input (http requests, requests for random numbers, ports requests) this is why the top level update has (Model, Cmd Msg) as return.Internal updates however, might not need these requests and can be simpler.What you see in the repository you linked is a pattern of nesting "components" that is currently passively discouraged. (there use to be a set of examples around this but they are gone).
The official recommendation around scaling is to focus on breaking the functionality into functions:
https://guide.elm-lang.org/reuse/
On Mon, Oct 17, 2016 at 12:00 AM, clouddie <contact....@gmail.com> wrote:
Hi, are there official guidelines for structuring large scale apps ? For instance, what is the community take on things like https://github.com/rogeriochaves/structured-elm-todomvc/tree/modular ?
This is quite neat although I cannot quite m'y head round the fact the Update fonctions in TaskList deal with messages for Task ans TaskList, and they do not respect thé standard (Model, Cmd Msg) signatures ?
--
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.
Is this article (and the one it refers to) taking a good or bad approach to program structure?I copied the structure as a way of seeing how a program might perhaps be broken down, but it feels like a very component based approach, given each level has its own update function. I learnt a fair bit about mapping between message types, so it was useful.I've broken my app down into pages using this structure, and so each page has a view, model, etc. Then the top level model has a model record for each page. This seems to work as it means the page doesn't need to know how it's being used at the level above. But the general conversations I see suggests this is not the right way to go and to break things down more into modules of related code. So I guess back to the original question, is this structure a good way to work?
On Mon, Oct 17, 2016 at 7:50 AM, Peter Damoc <pda...@gmail.com> wrote:
update is a function that takes a message and a model and produces the updated version of the model. In some cases, update also can produce some requests for more input (http requests, requests for random numbers, ports requests) this is why the top level update has (Model, Cmd Msg) as return.Internal updates however, might not need these requests and can be simpler.What you see in the repository you linked is a pattern of nesting "components" that is currently passively discouraged. (there use to be a set of examples around this but they are gone).
The official recommendation around scaling is to focus on breaking the functionality into functions:
https://guide.elm-lang.org/reuse/
On Mon, Oct 17, 2016 at 12:00 AM, clouddie <contact....@gmail.com> wrote:
Hi, are there official guidelines for structuring large scale apps ? For instance, what is the community take on things like https://github.com/rogeriochaves/structured-elm-todomvc/tree/modular ?
This is quite neat although I cannot quite m'y head round the fact the Update fonctions in TaskList deal with messages for Task ans TaskList, and they do not respect thé standard (Model, Cmd Msg) signatures ?
--
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/
--
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.
From personal experience (admittedly limited) I definitely agree to the "flat is better than nested". Having one update function with helpers, and not having any components with local state has made debugging at least 10x faster for me.
Adding features like an undo function was way easier with a flat structure.
Can you, please, provide an example?
Helpers.elm
Helpers -- folder with more helpers
Nav.elm -- helpers for navigation
Exam.elm -- helpers for updating the exam
Summaries.elm -- helpers (for view) to create a summary string from details
Main.elm
Model.elm
Msg.elm
Route.elm -- with routes the user can navigate to
Types.elm -- details of the stuff in the model
Update.elm
View.elm
Views -- folder with elm file per page, imported by view.elm
Today.elm
Exams.elm
EditExam.elm
PickExamDate.elm
-- before (nested)
type alias Model =
{ exams : List Exam }
type alias Exam =
{ subject : String
, studyDates : List Date
}
-- now (flat)
type alias Model =
{ exams : List Exam
, studyDates : List StudyDate
}
type alias Exam =
{ id : Int
, subject : String
}
type alias StudyDate =
{ studyDate : Date
, exam : Int -- id only
}
Is this article (and the one it refers to) taking a good or bad approach to program structure?I copied the structure as a way of seeing how a program might perhaps be broken down, but it feels like a very component based approach, given each level has its own update function. I learnt a fair bit about mapping between message types, so it was useful.I've broken my app down into pages using this structure, and so each page has a view, model, etc. Then the top level model has a model record for each page. This seems to work as it means the page doesn't need to know how it's being used at the level above. But the general conversations I see suggests this is not the right way to go and to break things down more into modules of related code. So I guess back to the original question, is this structure a good way to work?
On Mon, Oct 17, 2016 at 7:50 AM, Peter Damoc <pda...@gmail.com> wrote:
update is a function that takes a message and a model and produces the updated version of the model. In some cases, update also can produce some requests for more input (http requests, requests for random numbers, ports requests) this is why the top level update has (Model, Cmd Msg) as return.Internal updates however, might not need these requests and can be simpler.What you see in the repository you linked is a pattern of nesting "components" that is currently passively discouraged. (there use to be a set of examples around this but they are gone).
The official recommendation around scaling is to focus on breaking the functionality into functions:
https://guide.elm-lang.org/reuse/
On Mon, Oct 17, 2016 at 12:00 AM, clouddie <contact....@gmail.com> wrote:
Hi, are there official guidelines for structuring large scale apps ? For instance, what is the community take on things like https://github.com/rogeriochaves/structured-elm-todomvc/tree/modular ?
This is quite neat although I cannot quite m'y head round the fact the Update fonctions in TaskList deal with messages for Task ans TaskList, and they do not respect thé standard (Model, Cmd Msg) signatures ?
--
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/
--
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.
update : Login.Msg -> Login.Model -> ( Login.Model, Cmd Login.Msg, Maybe User )
--
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+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
Above all of this, the other key subdivision we are making in our SPA and that I would recommend having seen where other programmers often first head, is having a top layer that handles overall app state — e.g., logged in v not logged in — as a type union. This can also often be where the routing logic plugs in.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
type alias User = String
type alias DataModel = List User
-- In model:
dataModel : DataModel
type alias ViewModel = Dict User Bool
-- In model:
The view function can now map over the data model (list of users) and extract the extra view model information by consulting the dictionary.viewModel : ViewModel
view : DataModel -> ViewModel -> Html ViewMsg
updateView : ViewMsg -> ViewModel -> (ViewModel, Cmd ViewMsg, Maybe DataMsg)
updateData: DataMsg -> DataModel -> (DataModel, Cmd DataMsg)
Then we get something like the following at the model level:updateViewForData: DataModel -> ViewModel -> (ViewModel, Cmd ViewMsg)
type alias Model = { dataModel : DataModel, viewModel : ViewModel }
type Msg = ToData DataMsg | ToView ViewMsg
update : Msg -> Model -> (Model, Cmd Msg)update msg model =
case msg of
ToData dataMsg ->
let
(newData, dataCmd ) = updateData dataMsg model.dataModel(newView, viewCmd ) = updateViewForData newData model.viewModel
in
( { model | dataModel = newData, viewModel = newView }, Cmd.batch [ Cmd.map ToData dataCmd, Cmd.map ToView viewCmd ])
ToView viewMsg ->
updateView viewMsg model.viewModel|> OutMessage.mapComponent (\newView -> { model | viewModel = newView })|> OutMessage.mapCmd ToView|> OutMessage.evaluateMaybe (\dataMsg m -> update (ToData dataMsg) m)
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.