Replies: 1 comment 5 replies
-
would it be an option to keep json serializable data in the cache and do the transformation to class instances in a different layer? The |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For legacy code reasons, I have a use case in which I'm using an API wrapper to access an API endpoint in my
useQuery
query function, and the wrapper returns an array of class instances. This is problematic since I don't get any structural sharing due to the non-JSON-serializable nature of the class instances, and there are many cases in which passing my owndeepEqual
function would do little to help; if only a single instance of 50 in the response genuinely differs in value (as opposed to reference), my view layer will still end up rerendering all 50.What I'd like is a way to specify a
customMerge
function (like custom structural sharing), which takes the current cacheTData
(orundefined
) and the incomingTData
, and merges them into anotherTData
, so that the consumer can dictate how to usefully retain references. In my case, a simple hash of the class properties would be enough to determine which elements of the cached array could be retained, and which need to be replaced.I think the implementation could be very simple indeed - just checking whether a
customMerge
function has been passed inreplaceData
, and returning the result of calling it withprevData
anddata
if so.If I'm the only person who ever needs this, I'd be happy to hear that this was the case, but my suspicion is that others will be forced to use API wrappers (or similar) which return non-JSON-serializable objects and are essentially locked out of structural sharing as a result, even though the logic to implement the appropriate level of reference-recycling for their use-case might be pretty simple.
Beta Was this translation helpful? Give feedback.
All reactions