Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate from react #56

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open

Separate from react #56

wants to merge 46 commits into from

Conversation

KidkArolis
Copy link
Collaborator

Yet to be tested in the real app! Need to rewire where the app reads the cache from for the global atom.

@KidkArolis KidkArolis requested a review from tjenkinson January 21, 2025 10:27
Copy link
Member

@tjenkinson tjenkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I like the separation now between the core/feathers and react

Got a few comments

lib/core/hash.js Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder how performant this is? Compared to something like https://www.npmjs.com/package/object-hash ?

* A helper to split the properties into a query descriptor `desc` (including 'params')
* and figbird-specific query configuration `config`
*/
export function splitConfig(combinedConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's clearer to keep the figbird/feathers properties in separate objects than try and merge the 2. Prevents a potential issue (although probably quite small), where a feathers update adds a property that conflicts with a figbird one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also this would be a breaking change and it's not a big deal

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, I think we can break backwards compat in the future, but wanted to make it work in the current codebase! so this splitConfig is a bit of stop gap to contain this issue

})
}

#subscribeToRealtime(queryId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes this returns an unsubscribe fn but if it's already subscribed it will return undefined. And it looks like where this is called it never uses the returned value so maybe missing an unsubscribe call somewhere?

If the idea is to subscribe once but allow multiple calls might need a reference counter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this bit a bit unfinished - the idea right now is that we never unsubscribe from relatime (and never delete anything from the cache) - once you ran the query, it keeps consuming realtime events. How to unsub/evict - not currently defined in. This is not far off from what the app is already doing, so I don't see this to be a big issue.


const shouldVacuumByDefault = q.config.fetchPolicy === 'network-only'
return ({ vacuum = shouldVacuumByDefault } = {}) => {
removeListener()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe here we should unsubscribe realtime too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then queries can get stale, for no good reason? Why not keep integrating those events if the websocket is receiving them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. But if the unsubscribe actually only stopped the listening when all queries have torn down then I think it makes sense, as there would be no queries using them?

Maybe at the point vacuum runs below, as that's clearing out the query anyway so it will need to be fetched again next time it's used?

Copy link
Member

@tjenkinson tjenkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! worth trying in the app


const shouldVacuumByDefault = q.config.fetchPolicy === 'network-only'
return ({ vacuum = shouldVacuumByDefault } = {}) => {
removeListener()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. But if the unsubscribe actually only stopped the listening when all queries have torn down then I think it makes sense, as there would be no queries using them?

Maybe at the point vacuum runs below, as that's clearing out the query anyway so it will need to be fetched again next time it's used?

@KidkArolis KidkArolis requested review from angusjf and KwanMan February 6, 2025 19:51
Comment on lines +48 to +50
const refetch = useCallback(() => q.refetch(), [q])
const subscribe = useCallback(fn => q.subscribe(fn), [q])
const getSnapshot = useCallback(() => q.getSnapshot(), [q])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if q is stable, then q.refetch, q.subscribe, and q.getSnapshot will also be stable, no need to wrap them in useCallbacks?

dispatch({ type: 'mutating' })
try {
const item = await figbird.mutate({ serviceName, method, args })
if (mountedRef.current) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this guard?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants