Op vrijdag 21 oktober 2016 21:01:29 UTC+2 schreef Ed Ilyin: > > Can you, please, provide an example? >
In a SPA I am developing, I use a structure like: 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 Whenever I create a new page (let's say a page to see the entire calendar), I usually modify stuff in the following order: - add a route in Route.elm - add a type in Types.elm (if needed) - modify my Msg (if needed) - modify update.elm, - add another view file in the view folder, - and import this file in my main view.elm file. Flat helps me to only change what is needed: Often a new page I want is just another view of the same data. So I do not need a new model, and I do not need to change the model, I only need a new view function. And a very simple change to the update function, to enable navigating to the new page. I was very much inspired by the Time Tracker SPA (see here <https://github.com/knewter/time-tracker>), which may also be a good place to look at a flat structure. Previously, I had one exam component, with its own model, update and view. Each exam had a list of dates. When I wanted to create a page that showed a calendar, and for each date, show the exams for which the user plans to study, I realised my component structure broke down. -- 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 } Hope this helps! -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
