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)
Tue, Sep 10, 12:06 PM
Unknown Object (File)
Aug 29 2024, 1:58 AM
Unknown Object (File)
Aug 22 2024, 12:07 PM
Unknown Object (File)
Aug 1 2024, 10:19 AM
Unknown Object (File)
Aug 1 2024, 10:19 AM
Unknown Object (File)
Aug 1 2024, 10:19 AM
Unknown Object (File)
Aug 1 2024, 10:13 AM
Unknown Object (File)
Jul 30 2024, 10:55 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.