SlideShare uma empresa Scribd logo
1 de 17
 Dividing a SPA
 Navigation and the URL
Elm SPA Navigation
1
Per Lundholm Crisp
 Problem statement
 Demo
 Divide an application into page modules
 Handle browser location
Per Lundholm 2
Agenda
 How can I structure my Elm app so that:
– Each page has Model, Messages, Update and View?
– Browser’s location bar is updated
• Backandforwardworks
• Bookmarkingpossible
 But an Elm app has only one source of truth
– OneModel
– OneUpdate
– OneView
Per Lundholm 3
Problem statement
 Book collection
 Pages
– Homepage
– Listing page
• Listsbooks
– Details page
• Detailsabouta selectedbook
Per Lundholm 4
Example Application
Demo
Per Lundholm 5
Dividing into Modules
Per Lundholm 6
Main
Msg = …
Model = …
main = …
init = …
update = …
view = …
Home Page
Msg = …
Model = …
init = …
update = …
view = …
Listing Page
Msg = …
Model = …
init = …
update = …
view = …
Details Page
Msg = …
Model = …
init = …
update = …
view = …
Router
Msg = …
Model = …
init = …
update = …
view = …
Source structure
Per Lundholm 7
 TheModel can only beone, the Main model
– TheMain modelcontainsthe Routermodel
– The Routermodel containsthe page’smodels.
Per Lundholm 8
Dividing the Model
type alias Model =
{ navKey : Browser.Navigation.Key
, url : Url
, sharedState : SharedState.SharedState
, routerModel : Routing.Router.Model
}
type alias Model =
{ route : Routing.Helpers.Route
, homeModel : Pages.Home.Model
, listingModel : Pages.Listing.Model
, detailsModel : Pages.Details.Model
}
type DetailsModel
= Initial
| NotFound
| Loaded Data.Book
type alias Model =
{ details : DetailsModel
}
Main.elm Router.elm
Details.elm
 The update function takes amessage and a model and returns a new
model plus a command
– update: Msg -> Model -> ( Model, Cmd Msg )
 We need to delegate the job
– Main to Router to Page
– But how? Main shouldn’t know about page’sMsg!
– Answer: Cmd.map
Per Lundholm 9
Delegating the update
Cmd.map
Per Lundholm 10
Details
Router
Mainfn BookLoaded
Cmd.map DetailMsg (fn BookLoaded)
Cmd.map RouterMsg (DetailMsg (fn BookLoaded))
RouterMsg (DetailMsg (BookLoaded))
DetailMsg (BookLoaded)
BookLoaded
11Per Lundholm
 How do we get Urls like:
 We use Browser.Navigation of elm/browser!
 Step 1. Declare messages for Url changes
Per Lundholm 12
Managing Browser Location
 Step 2: Handle the messages
– Main
– Router
Per Lundholm 13
 Step 3: Parse the Url
Per Lundholm 14
 Step 4: Enable bookmarking by parsing atinit
– Main
– Router init
Per Lundholm 15
 Divide app into modules for each page
– Delegate update to pages and use Cmd.map
 With elm/browser package handle browser location so that
– Back and forward works
– Bookmarking possible
Per Lundholm 16
Summary
 Source code for the demo
– https://github.com/perty/elm-navigation-test
 Ossi Hanhinen’sShared state
– https://github.com/ohanhi/elm-shared-state
 Elm’s Browser Navigation
– https://package.elm-lang.org/packages/elm/browser/latest/Browser-Navigation
Per Lundholm 17
Source

Mais conteúdo relacionado

Semelhante a Elm SPA navigation

Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...Codemotion
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCCarlo Bonamico
 
OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9
OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9
OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9Alkacon Software GmbH & Co. KG
 
Angular presentation
Angular presentationAngular presentation
Angular presentationMatus Szabo
 
Getting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal StackGetting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal Stacknuppla
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcherlottepitcher
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Arjan
 
Apex 5.1 migration and templates - APAC webinar tour
Apex 5.1 migration and templates - APAC webinar tourApex 5.1 migration and templates - APAC webinar tour
Apex 5.1 migration and templates - APAC webinar tourLino Schildenfeld
 
Model-driven development and Code generation
Model-driven development and Code generationModel-driven development and Code generation
Model-driven development and Code generationPavel Vlasov
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
What is Lazy Loading
What is Lazy LoadingWhat is Lazy Loading
What is Lazy Loadingsrinivaskapa1
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end appsZohar Arad
 
Auto Europe's ongoing journey with MariaDB and open source
Auto Europe's ongoing journey with MariaDB and open sourceAuto Europe's ongoing journey with MariaDB and open source
Auto Europe's ongoing journey with MariaDB and open sourceMariaDB plc
 
Front End Development in Magento
Front End Development in MagentoFront End Development in Magento
Front End Development in MagentoEric Landmann
 

Semelhante a Elm SPA navigation (20)

Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVC
 
OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9
OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9
OpenCms Days 2013 - How to update smoothly to OpenCms 9ms 9
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
NCIT civil Syllabus 2013-2014
NCIT civil Syllabus 2013-2014NCIT civil Syllabus 2013-2014
NCIT civil Syllabus 2013-2014
 
Getting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal StackGetting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal Stack
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
 
Compose in Theory
Compose in TheoryCompose in Theory
Compose in Theory
 
Apex 5.1 migration and templates - APAC webinar tour
Apex 5.1 migration and templates - APAC webinar tourApex 5.1 migration and templates - APAC webinar tour
Apex 5.1 migration and templates - APAC webinar tour
 
Model-driven development and Code generation
Model-driven development and Code generationModel-driven development and Code generation
Model-driven development and Code generation
 
Spring batch
Spring batchSpring batch
Spring batch
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
Workshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte IWorkshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte I
 
angular
angularangular
angular
 
lazy loading
lazy loadinglazy loading
lazy loading
 
What is Lazy Loading
What is Lazy LoadingWhat is Lazy Loading
What is Lazy Loading
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
Auto Europe's ongoing journey with MariaDB and open source
Auto Europe's ongoing journey with MariaDB and open sourceAuto Europe's ongoing journey with MariaDB and open source
Auto Europe's ongoing journey with MariaDB and open source
 
Front End Development in Magento
Front End Development in MagentoFront End Development in Magento
Front End Development in Magento
 

Último

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 

Último (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 

Elm SPA navigation

  • 1.  Dividing a SPA  Navigation and the URL Elm SPA Navigation 1 Per Lundholm Crisp
  • 2.  Problem statement  Demo  Divide an application into page modules  Handle browser location Per Lundholm 2 Agenda
  • 3.  How can I structure my Elm app so that: – Each page has Model, Messages, Update and View? – Browser’s location bar is updated • Backandforwardworks • Bookmarkingpossible  But an Elm app has only one source of truth – OneModel – OneUpdate – OneView Per Lundholm 3 Problem statement
  • 4.  Book collection  Pages – Homepage – Listing page • Listsbooks – Details page • Detailsabouta selectedbook Per Lundholm 4 Example Application
  • 6. Dividing into Modules Per Lundholm 6 Main Msg = … Model = … main = … init = … update = … view = … Home Page Msg = … Model = … init = … update = … view = … Listing Page Msg = … Model = … init = … update = … view = … Details Page Msg = … Model = … init = … update = … view = … Router Msg = … Model = … init = … update = … view = …
  • 8.  TheModel can only beone, the Main model – TheMain modelcontainsthe Routermodel – The Routermodel containsthe page’smodels. Per Lundholm 8 Dividing the Model type alias Model = { navKey : Browser.Navigation.Key , url : Url , sharedState : SharedState.SharedState , routerModel : Routing.Router.Model } type alias Model = { route : Routing.Helpers.Route , homeModel : Pages.Home.Model , listingModel : Pages.Listing.Model , detailsModel : Pages.Details.Model } type DetailsModel = Initial | NotFound | Loaded Data.Book type alias Model = { details : DetailsModel } Main.elm Router.elm Details.elm
  • 9.  The update function takes amessage and a model and returns a new model plus a command – update: Msg -> Model -> ( Model, Cmd Msg )  We need to delegate the job – Main to Router to Page – But how? Main shouldn’t know about page’sMsg! – Answer: Cmd.map Per Lundholm 9 Delegating the update
  • 10. Cmd.map Per Lundholm 10 Details Router Mainfn BookLoaded Cmd.map DetailMsg (fn BookLoaded) Cmd.map RouterMsg (DetailMsg (fn BookLoaded)) RouterMsg (DetailMsg (BookLoaded)) DetailMsg (BookLoaded) BookLoaded
  • 12.  How do we get Urls like:  We use Browser.Navigation of elm/browser!  Step 1. Declare messages for Url changes Per Lundholm 12 Managing Browser Location
  • 13.  Step 2: Handle the messages – Main – Router Per Lundholm 13
  • 14.  Step 3: Parse the Url Per Lundholm 14
  • 15.  Step 4: Enable bookmarking by parsing atinit – Main – Router init Per Lundholm 15
  • 16.  Divide app into modules for each page – Delegate update to pages and use Cmd.map  With elm/browser package handle browser location so that – Back and forward works – Bookmarking possible Per Lundholm 16 Summary
  • 17.  Source code for the demo – https://github.com/perty/elm-navigation-test  Ossi Hanhinen’sShared state – https://github.com/ohanhi/elm-shared-state  Elm’s Browser Navigation – https://package.elm-lang.org/packages/elm/browser/latest/Browser-Navigation Per Lundholm 17 Source

Notas do Editor

  1. Nivå på talet Vem är jag Vad gör jag nu
  2. You start with Main Model, Message, View, Update Easy no navigation Then?
  3. http://localhost:3005