Comments (7)
I don't know if there's a good answer for what you asking, but a couple of small observations:
- You should never need to call
urlUpdate
fromupdate
- Delegate as much as possible into child modules (you can think of auth as viewless child)
from safe-bookstore.
- regarding urlupdate - care to send one of your famous refactoring PRs?
- yes but even if you push more into the submodules. it's still that weird pattern match - but on the other hand it's super explicit. Much better than hiding such things in DI containers. and compiler tells me if I forget. so ...
from safe-bookstore.
This match also looks funky to me, because when we have a message for a page, but we don't have the correct sub-model for that page (in the app model), we just drop through (i.e. ignore the message). Is this considered OK, from a logical perspective? It feels like it should be an error, but I'm assuming there must be conditions where you could get in this state legitimately.
from safe-bookstore.
@forki do you think it would improve things, if we promote the SubModel
to the top level match? To me, this makes it clearer and makes the drop through case distinct too.
let update msg model =
match msg, model.SubModel with
| AppMsg.OpenLogIn, _ ->
let m,cmd = Login.init None
{ model with
Page = Page.Login
SubModel = LoginModel m }, Cmd.batch [cmd; Navigation.modifyUrl (toHash Page.Login) ]
| StorageFailure e, _ ->
printfn "Unable to access local storage: %A" e
model, []
| LoginMsg msg, LoginModel m ->
let m,cmd = Login.update msg m
let cmd = Cmd.map LoginMsg cmd
match m.State with
| Login.LoginState.LoggedIn token ->
let newUser : UserData = { UserName = m.Login.UserName; Token = token }
let cmd =
if model.Menu.User = Some newUser then cmd else
Cmd.batch [cmd
Cmd.ofFunc (Utils.save "user") newUser (fun _ -> LoggedIn) StorageFailure ]
{ model with
SubModel = LoginModel m
Menu = { model.Menu with User = Some newUser }}, cmd
| _ ->
{ model with
SubModel = LoginModel m
Menu = { model.Menu with User = None } }, cmd
| LoginMsg msg, _ -> model, Cmd.none
| PromoMsg msg, PromoModel m ->
let m, cmd = Promo.update msg m
let cmd = Cmd.map PromoMsg cmd
{ model with
SubModel = PromoModel m }, cmd
| PromoMsg msg, _ -> model, Cmd.none
| WishListMsg msg, WishListModel m ->
let m,cmd = WishList.update msg m
let cmd = Cmd.map WishListMsg cmd
{ model with
SubModel = WishListModel m }, cmd
| WishListMsg msg, _ -> model, Cmd.none
| AppMsg.LoggedIn, _ ->
let nextPage = Page.WishList
let m,cmd = urlUpdate (Some nextPage) model
match m.Menu.User with
| Some user ->
m, Cmd.batch [cmd; Navigation.modifyUrl (toHash nextPage) ]
| None ->
m, Cmd.ofMsg Logout
| AppMsg.LoggedOut, _ ->
{ model with
Page = Page.Home
SubModel = NoSubModel
Menu = { model.Menu with User = None } },
Navigation.modifyUrl (toHash Page.Home)
| AppMsg.Logout, _ ->
model, Cmd.ofFunc Utils.delete "user" (fun _ -> LoggedOut) StorageFailure
from safe-bookstore.
yes. thought I already did that
from safe-bookstore.
The code you link to above, in master
has the nested match. Want me to PR it?
from safe-bookstore.
from safe-bookstore.
Related Issues (20)
- http://localhost:8080/login doesn't work HOT 14
- SAFE apps can't be hosted as sub-applications HOT 1
- Readme tutorial has diverged from code HOT 7
- Debugging issue in Visual Studio Code HOT 1
- Cannot find file specified HOT 2
- Feature request - GraphQL HOT 1
- SSR issue? HOT 4
- Is this still maintained? HOT 4
- ./build.run wants to install dotnet core sdk 3.01 on linux and fails HOT 1
- Add loading Skeleton - DaisyUI
- On browser refresh you get 2 api calls - Router issue
- Auth token does not expire after set time
- Repo settings with master branch protection and reviewers
- Update documentation HOT 1
- Proper hyperlinks
- Table not highlighting hover row
- Cleanup UX
- Move from Quartz to ASP .NET Background Services
- Use React Components for inner pages
- Clear the warning when getting the "Books" TableClient HOT 1
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 safe-bookstore.