Page MenuHomePhabricator

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

Authored by will on Wed, Apr 10, 11:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 27, 5:03 PM
Unknown Object (File)
Fri, Apr 26, 3:22 PM
Unknown Object (File)
Fri, Apr 26, 2:27 PM
Unknown Object (File)
Fri, Apr 26, 12:03 PM
Unknown Object (File)
Thu, Apr 25, 1:27 PM
Unknown Object (File)
Mon, Apr 22, 3:48 PM
Unknown Object (File)
Sun, Apr 21, 1:14 PM
Unknown Object (File)
Tue, Apr 16, 12:25 PM
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.Thu, Apr 11, 12:01 AM
ashoat requested changes to this revision.Thu, Apr 11, 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.Thu, Apr 11, 1:02 PM

replace useSelector with function

ashoat requested changes to this revision.Tue, Apr 16, 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.Tue, Apr 16, 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.Tue, Apr 16, 12:20 PM