Comments (1)
Hi there @Ankoma22.
Actions are nested because it aids in modularity. For example, if you have:
enum AppAction {
case screen1(Screen1Action)
case screen2(Screen2Action)
}
Then the domain, reducer and view for screen 1 and 2 can each be broken out into their own modules with no dependencies on each other, and they can be pulled back and combined into a main app reducer that powers the entire application. This makes it possible to run those screens in isolation (without building the full app), and can help with compile times as well as many other benefits.
Redux may use global actions, but that could also be due to the fact that JS does not have proper enums, and so they really have no choice. You certainly can use global actions in the architecture by creating a "marker" protocol that your actions conform to:
protocol Action {}
struct MyState { ... }
struct MyAction: Action { ... }
func reducer(state: inout MyState, action: Action) {
switch action {
case _ as MyAction:
// Do things with the action here
break
default:
// Do nothing here?
break
}
}
We do not recommend this approach since it makes composition more difficult (you can't pullback
), and you lose exhaustivity of handling actions. Notice that we have a default
in the switch, and it's not clear what we should do there. Should it be an error if that ever executes? Exhaustivity means we never have to worry about actions coming in that we don't expect, and means we can refactor actions in far, deep corners of the code base and understand how those changes impact the entire application.
And we don't believe that nested actions goes against the law of Demeter. That law is really only applicable to reference types, where knowledge of far away units can cause you to make incorrect assumptions about how the system behaves. Value types don't have this problem, they are just inert data with no behavior.
Hope that helps clear up some of your questions!
from episode-code-samples.
Related Issues (20)
- 0167 Navigation is weird on iPad HOT 1
- Please fix the error Episode #76 ~ HOT 2
- [0171-modularization-pt1] Setting Up HOT 3
- modularization folders architecture HOT 1
- Missing episode 187: URL Route? HOT 1
- Cannot convert value of type - Examples will not compile using Xcode 13.3 HOT 2
- Request: Re-Record Episode 100 to 103 and Update Source Code HOT 3
- Episode 196: Runtime warning work only in half of the cases HOT 1
- minor bug in episode 198 sample HOT 1
- Code sample for episode 220 is missing HOT 1
- Strange navigation on episode 220 HOT 1
- Episode 2 -> Fish playground -> Ambiguous use of 'init(utf8String:)'
- Episode 0228 - Composable Navigation: Destinations sample code not found HOT 1
- navigationDestination not triggered HOT 3
- Modern SwiftUI: Standups App HOT 1
- Episode 241 code not published HOT 2
- Episode 109 sheet show twice when item name changed HOT 1
- Typo in Navigation Example code
- @FocusState not working with new @BindableState API HOT 5
- UIApplication.shared.windows deprecated in iOS 15 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 episode-code-samples.