Comments (5)
For some reason I missed that question, I'm sorry taking so long to reply.
The strict version of me would tell you that no side-effects should happen in the Reducer (even print or specially crashing the app). For debug purposes, however, that could be useful sometimes. But if you're willing to keep that assertionFailure in there, even given that assertionFailure only happens in Debug builds, it'd be more correct in the middleware, so I would recommend Middleware' afterReducer closure for that, at that point your new state is already reduced, you still have the original Action that originated the inconsistent state and you can even have the old state to compare if you want.
Another option, that I like much more, is trigger an "error" action from the middleware in that case, and another middleware called "DebugMiddleware" would be responsible for crashing, or logging to console or whatever crash breadcrumb backend you do have. This is very useful to track problems in production, because all these "assertionFailure" should give you very good hints when understanding other crashes or problems with Release builds. In my company's apps we have QA menus where you can crash the app and provide a text with some context, all of this goes to Crashlytics as breadcrumbs and all the possible "assertionFailures" on the way are also logged as breadcrumbs in there, so when QA crew finds something weird in the app, they crash the app on purpose and provide a text explaining their findings... Then they create a Jira ticket pointing to the crash on Crashlytics and we have a lot of information in there to debug.
By the way, every action in our apps is also logged to Crashlytics as "Records" (Crashlytics.crashlytics().log(Action as String)) and the last known state is logger as key/values to the "Keys" section (Crashlytics.crashlytics().setCustomValue(value, forKey: key)). I do this in a special Crashlytics middleware, and in a background queue.
Hope it helps.
from swiftrex.
override public func handle(action: AppAction, from dispatcher: ActionSource, afterReducer: inout AfterReducer) {
let recorder = crashRecorder() // Dependency Injection for Crashlytics
// log breadcrumbs
serialBgQueue.async {
recorder.log("🕹 \(action)")
}
// Saves the latest state. This will be overwritten continuoisly and the latest state is sent to firebase in case of a crash
afterReducer = .do { [weak self] in
guard let self = self else { return }
let state = self.getState()
self.serialBgQueue.async {
let json = state.toDictionary(encoder: self.encoder())
json.forEach { (key, value) in
recorder.set(value: value, for: "state.\(key)")
}
}
}
}
from swiftrex.
missed this one
extension Encodable {
public func toDictionary(encoder: JSONEncoder) -> [String: Any] {
guard
let data = try? encoder.encode(self),
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
else { return [:] }
return json
}
}
from swiftrex.
Moving question to Slack
https://swiftrex.slack.com/archives/C01M6CT2TJ9/p1612718006001200
from swiftrex.
Invitation link:
https://join.slack.com/t/swiftrex/shared_invite/zt-m9kk7xio-imhcsF2eHJqb~YP_ls6U9g
from swiftrex.
Related Issues (20)
- middleware lift with WritableKeyPath doesn't work on AnyMiddleware HOT 2
- Fix animations from Middleware
- Dead-Letter Queue HOT 1
- Memory leak in LiftMiddleware
- When will develop be the official release? HOT 2
- Lift EffectMiddleware using KeyPath not receiving context
- How to modify AppLifecycleMiddleware to adopt the new MiddlewareProtocol? HOT 2
- Redundant conformance of 'ASAPScheduler' to protocol 'Scheduler'
- Using await/async in middleware HOT 4
- IO monad and stack limit HOT 6
- Best option for actions triggering other actions ? HOT 28
- Dynamic store HOT 5
- Migrate away from Travis CI HOT 4
- Design question : Model to State migration HOT 2
- Dispatch actions and run reducers on background thread? HOT 4
- CombineRex : Unexpected PublisherType behavior HOT 3
- Trying to use Effect.promise with Firebase's DynamicLinkComponents.shortenURL HOT 5
- How organize communication between different states HOT 2
- Improve Tests
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 swiftrex.