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
Unknown Object (File)
Mon, Nov 25, 5:45 PM
Unknown Object (File)
Mon, Nov 25, 3:45 PM
Unknown Object (File)
Sun, Nov 24, 6:21 AM
Unknown Object (File)
Fri, Nov 1, 5:26 AM
Unknown Object (File)
Fri, Nov 1, 3:47 AM
Unknown Object (File)
Oct 2 2024, 11:52 AM
Unknown Object (File)
Oct 2 2024, 11:52 AM
Unknown Object (File)
Oct 2 2024, 11:47 AM
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.