Commit Graph

18 Commits

Author SHA1 Message Date
Icaro Motta 6550bc058d
Document quo best practices and guidelines (#16901) 2023-08-09 11:32:36 -03:00
Icaro Motta b9890a9d44
Upgrade shadow-cljs and ClojureScript (#15417)
This commit upgrades Shadow CLJS from 2.11.16 (released on Feb/21) to latest
2.25.0 (Jul/23), so ~1.5 years worth of upgrades. By upgrading shadow we
can finally use the latest major Clojure version 1.11.x.

Why upgrade shadow?

- Shadow CLJS controls the ClojureScript version we can use. In order to use the
  latest major Clojure version we must upgrade Shadow CLJS.

- Shadow CLJS releases new versions very frequently, and if you take a look at
  its changelog https://github.com/thheller/shadow-cljs/blob/master/CHANGELOG.md, you'll see
  it had tons and tons of bug fixes over the years. I hope some of them help
  improve the DX for certain contributors who recently reported issues with
  it.

- Clojure 1.11 brings new features, bug fixes and even performance improvements
  (although I think the performance mostly impacts Clojure on the JVM). See the
  changelog https://github.com/clojure/clojure/blob/master/changes.md#changes-to-clojure-in-version-1110

Things that can be beneficial to us, or are interesting nonetheless:

- New :as-alias to be used in require, which is like :as but does not require
  the namespace to load. This means namespaced keywords using :as-alias can't
  cause circular dependency errors. This feature would very useful if we used
  namespaced keywords, but we don't, so...
  https://github.com/clojure/clojure/blob/master/changes.md#22-as-alias-in-require
- New macros run-test and run-test-var to run single test with fixtures and
  report.
- New iteration function, useful for processing paginated data.
  https://www.abhinavomprakash.com/posts/clojure-iteration/
- New update-keys function: applies a function to every key in a map.
- New update-vals function: applies a function to every value in a map.

Examples for update-vals and update-keys. They should perform better than the
common reduce-kv approach since they use a transient data structure.

    (let [m {:a 1 :b 2}]
      (update-vals m inc)) ; => {:a 2, :b 3}
    
    (let [m {:a 1 :b 2}]
      (update-keys m name)) ; => {"a" 1, "b" 2}

Why change namespaces within __tests__ directories?

Any namespace with the word --tests-- throws an error, like the one below. I
didn't bother investigating why, so I changed the guidelines to reflect the new
convention. It's probably related to the double dashes in the name.

    Namespace quo2.components.dividers.--tests--.divider-label-component-spec has a
    segment starting with an invalid JavaScript identifier at line 1
2023-07-28 13:40:54 -03:00
Jamie Caprani 9ac14b6fac
chore: update guidelines for figma api to match quo2 component api (#16454) 2023-07-10 02:45:39 -07:00
Icaro Motta a17efa7299
Make json-rpc/call effect more in line with re-frame standards (#15936)
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.
2023-05-18 15:56:10 -03:00
flexsurfer 4a42d20b0c
update guidlines (#15686) 2023-04-24 14:38:11 +02:00
Brian Sztamfater 0f8aec00f2
Add guidelines for defining styles with apply-animations-to-style
Signed-off-by: Brian Sztamfater <brian@status.im>
2023-03-28 11:58:06 -03:00
Ulises Manuel Cárdenas 94ddbbcd2e
Add checked? property, dark blur variant & tests to disclaimer component
Co-authored-by: Jamie Caprani <jamiecaprani@gmail.com>
2023-03-27 14:06:09 -06:00
Jamie Caprani d8c110bf85
feat: add title input component to quo2 (#15133) 2023-03-11 08:29:11 -08:00
Jamie Caprani cbad7f4c87
feat: add drawer buttons to quo2 (#15062)
feat: add drawer buttons to quo2
2023-02-16 06:29:44 -08:00
Icaro Motta 0c59ed5ceb
Improve guidelines (#15008)
- New section: Use [] instead of () in Reagent components: New section after
  this comment https://github.com/status-im/status-mobile/pull/15005#discussion_r1098220176
- Updated section "Don't use percents to define width/height": reworded to
  follow the style of the rest of the document.
- Update section "Accessibility labels": added example about avoiding dynamic
  labels.
2023-02-07 10:05:38 -03:00
Icaro Motta 2dad2b67e8
Update style namespaces (#14941)
Update certain `style.cljs` files to more strictly follow our guidelines. Except for animations and theme colors, *style* functions should be pure.

It turns out `style` namespaces are well behaved and are almost perfectly following guidelines 🚀 

The motivation for the PR came from this thread https://github.com/status-im/status-mobile/pull/14925#discussion_r1090485454
2023-02-02 07:23:06 -03:00
Volodymyr Kozieiev bfb2863774
Documentation updated (#14933) 2023-01-31 12:06:29 +00:00
Icaro Motta 7cf17b5d34
Move unit test helper namespace to `src/test_helpers/` (#14716) 2023-01-05 11:58:37 -03:00
Icaro Motta 915b8ebd9a
New component Selector > Filter (#14650) 2022-12-28 12:21:15 -03:00
Icaro Motta 5693df5a74
Lint namespace aliases (#14526) 2022-12-13 17:04:26 -03:00
Icaro Motta 6e272a96c8
Introduce subscription tests (#14472) 2022-12-06 13:36:05 -03:00
Icaro Motta c198133769
Update guidelines (#14445) 2022-11-28 09:58:36 -03:00
Icaro Motta a77f662948
Document new guidelines (#14309) 2022-11-14 07:15:49 -03:00