Page MenuHomePhabricator

[lib] Move current user updates logic into a spec
ClosedPublic

Authored by tomek on Sep 22 2023, 6:36 AM.
Tags
None
Referenced Files
F2144266: D9268.id31778.diff
Sat, Jun 29, 7:26 PM
Unknown Object (File)
Sat, Jun 29, 7:45 AM
Unknown Object (File)
Wed, Jun 26, 4:15 PM
Unknown Object (File)
Fri, Jun 21, 9:50 AM
Unknown Object (File)
Fri, Jun 21, 9:50 AM
Unknown Object (File)
Fri, Jun 21, 9:49 AM
Unknown Object (File)
Fri, Jun 21, 9:44 AM
Unknown Object (File)
Wed, Jun 19, 7:25 PM
Subscribers

Details

Summary

Introduce a new function to a spec that reduces current user store.

Use this function in a reducer - the approach is a little different from the original one:

  1. Instead of returning immediately, we reduce every update. There should be at most one CurrentUserUpdateInfo, which is the only update that affects this store, so it should be equivalent.
  2. If there were more updates affecting this store, we should apply more reductions. The updates should be sorted by timestamp on a server, so it makes sense to iterate through them using the same ordering.
  3. We always return for these actions instead of waiting for the default return state at the end.

Depends on D9257

https://linear.app/comm/issue/ENG-4241/handle-processupdatesactiontype-as-a-part-of-a-spec

Test Plan

Check if updating the current user from a different client works correctly.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tomek requested review of this revision.Sep 22 2023, 6:56 AM
kamil added inline comments.
lib/reducers/user-reducer.js
82 ↗(On Diff #31367)

the fact that this has a very similar name to reducers itself makes me very confused but probably there isn't a better option

This revision is now accepted and ready to land.Sep 25 2023, 5:35 AM
lib/reducers/user-reducer.js
82 ↗(On Diff #31367)

The similarity in names makes some sense because a reducer takes some state, and an action and returns a new state. In this case, it takes a reduced state, and an update and returns a new state.