a17efa7299
Changes effect :json/rpc-call to accept on-success and on-error parameters either as functions OR as re-frame event vectors. The changes are 100% backwards compatible. ## Why? Re-frame is very explicit in its documentation and its architecture, saying that event handlers should be pure. Calling re-frame.core/dispatch in event handlers makes them sort of stateful. > So, you can "get away with it". But it ain't pure. > > -- https://day8.github.io/re-frame/EffectfulHandlers/#90-solution In status-mobile, arguably one of our most important effects (not to be confused with event handlers) is :json-rpc/call, but at the moment, the on-success and on-error values are expected to be stateful functions (e.g. usually used for logging and dispatching subsequent events). This creates two important problems: 1. The value returned by event handlers is more opaque and cannot be easily inspected (for example using tap>, log/debug or just println). If we try to inspect or log them, on-success and on-error will be printed as #object[Function]. 2. Testing event handlers using :json-rpc/call becomes an exercise of frustration, because we can't simply compare the results of the event handler with a good expected value, which is one of the big selling points of testing pure functions. ### The testability of event handlers > For any re-frame app, there's three things to test: > > - Event Handlers - most of your testing focus will be here because this is > where most of the logic lives > - Subscription Handlers - often not a lot to test here. Only Layer 3 > subscriptions need testing. > - View functions - I don't tend to write tests for views. > > -- https://day8.github.io/re-frame/Testing/#what-to-test So re-frame is saying event handlers should be pure, and that event handlers should be tested. In order to achieve the divine simplicity of testing event handlers as pure functions, we need to make :json-rpc/call also accept on-success and on-error as event vectors. Good news is that there is a known pattern to solve this problem, e.g. used by the library https://github.com/Day8/re-frame-http-fx. The pattern is simple once we see it: behind the scenes, :json-rpc/call conj'es the results of the RPC call into the event vectors on-success and on-error, and :json-rpc/call dispatches the events itself. This eliminates the need for the stateful dispatch call in event handlers. |
||
---|---|---|
.. | ||
decisions | ||
images | ||
sign_in | ||
README.md | ||
codebase-structure-and-guidelines.md | ||
component-tests-overview.md | ||
debugging.md | ||
dependencies.md | ||
export-icons.md | ||
fdroid.md | ||
how-to-launch-e2e.md | ||
ide-setup.md | ||
merging-pr-process.md | ||
new-guidelines.md | ||
pipeline_process.md | ||
post-mortem.md | ||
release-checklist.md | ||
release-guide.md | ||
starting-guide.md | ||
testing.md | ||
troubleshooting.md |
README.md
Getting Started
Development Process
Working on PR together with QA team
Testing
End-to-end tests (e2e) overview
Component tests (jest) overview
Misc
Importing icons from Figma into project
Updating Status APK builds for the F-Droid Android application catalogue
Troubleshooting for known errors