Comments (3)
How do you handle page navigation in Release mode ?
My bad, I will fix it right away 😄
Why a custom navigation module instead of the one from Elmish.Browser ?
Using the Parser
api became messy real quick when you have nested pages and especially messy when you have parameters in the url.
Compare these two implementations, which one is easier to understad? this is the old one
let pageParser: Parser<Page -> Page, Page> =
oneOf [ map About (s Urls.about)
map (Admin Admin.Types.Page.Login) (s Urls.login)
map (PostsPage.Post >> Posts) (s Urls.posts </> str)
map (Posts PostsPage.AllPosts) (s Urls.posts )
map (Admin (Admin.Types.Page.Backoffice BackofficePage.Home)) (s Urls.admin)
map (Admin (Admin.Types.Page.Backoffice BackofficePage.NewPost)) (s Urls.admin </> s Urls.newPost)
map (fun id -> Admin (Admin.Types.Page.Backoffice (BackofficePage.EditArticle id))) (s Urls.admin </> s Urls.editPost </> i32)
map (Admin (Admin.Types.Page.Backoffice BackofficePage.Drafts)) (s Urls.admin </> s Urls.drafts)
map (Admin (Admin.Types.Page.Backoffice BackofficePage.PublishedPosts)) (s Urls.admin </> s Urls.publishedPosts)
map (Admin (Admin.Types.Page.Backoffice BackofficePage.Settings)) (s Urls.admin </> s Urls.settings) ]
and this is the new one
/// Tries to parse a url into a page
let parseUrl (urlHash: string) =
let segments =
if urlHash.StartsWith "#"
then urlHash.Substring(1, urlHash.Length - 1) // remove the hash sign
else urlHash
|> fun hash -> hash.Split '/' // split the url segments
|> List.ofArray
|> List.filter (String.IsNullOrWhiteSpace >> not)
match segments with
| [ Urls.about ] ->
// the about page
App.Types.Page.About
|> Some
| [ Urls.posts ] ->
// all posts page
Posts.Types.Page.AllPosts
|> App.Types.Page.Posts
|> Some
| [ Urls.posts; postSlug ] ->
// matches against a specific post by it's slug
Posts.Types.Page.Post postSlug
|> App.Types.Page.Posts
|> Some
| [ Urls.admin ] ->
// the home page of the backoffice
Admin.Backoffice.Types.Page.Home
|> Admin.Types.Page.Backoffice
|> App.Types.Page.Admin
|> Some
| [ Urls.login ] ->
// the login page
Admin.Types.Page.Login
|> App.Types.Page.Admin
|> Some
| [ Urls.admin; Urls.drafts ] ->
// the drafts page
Admin.Backoffice.Types.Page.Drafts
|> Admin.Types.Page.Backoffice
|> App.Types.Page.Admin
|> Some
| [ Urls.admin; Urls.publishedPosts ] ->
// the page of published stories
Admin.Backoffice.Types.Page.PublishedPosts
|> Admin.Types.Page.Backoffice
|> App.Types.Page.Admin
|> Some
| [ Urls.admin; Urls.newPost ] ->
// the new post page
Admin.Backoffice.Types.Page.NewPost
|> Admin.Types.Page.Backoffice
|> App.Types.Page.Admin
|> Some
| [ Urls.admin; Urls.settings ] ->
// the settings page
Admin.Backoffice.Types.Page.Settings
|> Admin.Types.Page.Backoffice
|> App.Types.Page.Admin
|> Some
| [ Urls.admin; Urls.editPost; Urls.Int postId ] ->
// editing a post by the post id
Admin.Backoffice.Types.Page.EditArticle postId
|> Admin.Types.Page.Backoffice
|> App.Types.Page.Admin
|> Some
| _ -> None
It is a bit longer, yes, but more obvious to read and understand.
Also the Elmish navigation module clutters the debug the messages with UserMsg
because it wraps the main program which I didn't like, although it is a small inconvenience.
Thank you for pointing out the subscription in Debug mode and please let me know if you come across other bugs.
from tabula-rasa.
Ok, I do unterstand and agree about the pageParser
becoming a bit messy.
At a time, I was wondering if doing a Suave/Giraffe like routing thing made sense or not.
please let me know if you come across other bugs.
Sure, I am just reading bit of the code to see how different your structure is from mine. :) As we have in general a different approach to the different problems :)
from tabula-rasa.
Sure, I am just reading bit of the code to see how different your structure is from mine. :) As we have in general a different approach to the different problems :)
Yeah, I am still exploring the best ways to solve common problems in large apps, the result you see now is after many iterations on how to make the code scalable, readable, etc.
from tabula-rasa.
Related Issues (12)
- Fix build
- Store only active page state in the model HOT 5
- Error while running build.cmd Watch HOT 18
- Rewrite with Feliz HOT 5
- How to get started on Windows HOT 14
- Port to Giraffe? HOT 4
- Error creating a database file on macOS (simple fix included)
- .build.sh file does not work
- How to login? HOT 4
- Running build.cmd Watch leads to errors
- Websockets don't work with Firefox? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tabula-rasa.