Page MenuHomePhabricator

[native][lib] Replace usages of FIDProvider with Synced Metadata Store
ClosedPublic

Authored by will on Apr 10 2024, 11:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 21, 3:24 PM
Unknown Object (File)
Sun, Nov 3, 10:07 AM
Unknown Object (File)
Oct 23 2024, 2:21 PM
Unknown Object (File)
Oct 13 2024, 1:10 AM
Unknown Object (File)
Oct 13 2024, 1:10 AM
Unknown Object (File)
Oct 13 2024, 1:10 AM
Unknown Object (File)
Oct 13 2024, 1:10 AM
Unknown Object (File)
Oct 13 2024, 1:09 AM
Subscribers

Details

Summary

This replaces usages of the FIDProvider with synced metadata store

depends on D11628

Test Plan

Went throught the registration and accounting settings connect farcaster workflows and successfully confirmed synced metadata database was populated and selector returned proper value.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

will requested review of this revision.Apr 11 2024, 12:01 AM
ashoat requested changes to this revision.Apr 11 2024, 1:02 PM

Would also be good for somebody with more familiarity with the rest of the stack to review the dispatch logic, but it generally looks good to me. Just a request to get rid of a createSelector

lib/selectors/synced-metadata-selectors.js
11–18 ↗(On Diff #39029)

There's really no need to use createSelector here, since what it returns is a primitive, and primitives won't have issues on equality checks.

Memoizing and things like createSelector in React can have two benefits:

  1. Reducing computation
  2. Making sure we return the same object reference if the inputs don't change

#2 is the main one you generally want to be thinking about, but #1 comes up sometimes. I don't think either of them are relevant here.

I think we can just replace this with a function that takes state and returns currentUserFID. The result of calling createSelector here has the same function signature, but it just has extra memoization we don't need

This revision now requires changes to proceed.Apr 11 2024, 1:02 PM

replace useSelector with function

ashoat requested changes to this revision.Apr 16 2024, 4:05 AM

One more round, sorry for the churn

lib/components/farcaster-data-handler.react.js
53 ↗(On Diff #39139)

I think it'd be better to move this function call into useSelector. See the docs:

When an action is dispatched, useSelector() will do a reference comparison of the previous selector result value and the current result value. If they are different, the component will be forced to re-render. If they are the same, the component will not re-render. useSelector() uses strict === reference equality checks by default, not shallow equality (see the following section for more details).

As you've written this, the component will re-render whenever anything in syncedMetadata changes. If you move the function call into useSelector, then the component will only rerender when the result of getCurrentUserFID changes.

lib/utils/farcaster-utils.js
8–10 ↗(On Diff #39139)

Given that every location you use this, you also call useSelector, I wonder if we should replace this with a hook that does this:

function useCurrentUserFID(): ?string {
  return useSelector(
    state => state.syncedMetadataStore.syncedMetadata[syncedMetadataNames.CURRENT_USER_FID] ?? null,
  );
}
This revision now requires changes to proceed.Apr 16 2024, 4:05 AM

create useCurrentUserFID hook instead of get function

lib/components/farcaster-data-handler.react.js
53 ↗(On Diff #39139)

Thanks for explaining that

lib/utils/farcaster-utils.js
8–10 ↗(On Diff #39139)

Makes sense. Included in latest rebase

This revision is now accepted and ready to land.Apr 16 2024, 12:20 PM