Constant holding a collection of invites changing without being changed
I explained exactly what's going on in the comments of the code below, any help would be greatly appreciated.
18 Replies
It looks like ur storing the reference to the Invite objects, which is mutated upon fetching them
What do you mean?
The Invites constant is just initiated as
const Invites = new Collection();
at the top of the code.Are you storing Invite objects in there?
I am lower down in the code
Or more so, Collection of Invite objects
Basically right after the code above goes this code:
Yea, ur storing the Invite objects
So it's basically supposed to compare old invites and new invites before updating the collection
D.js mutates those Invite object if your refetch
What do you mean by mutate?
Update in place
Like how Arrays are mutable
How do I keep the old collection the same then?
Because this never happened with d.js 12
You could map it to a plain object or ur own class w/ just the uses and inviter
And whatever else you need
Cloning the collection doesn't help?
I probably sound stupid but how do I map it to a plain object?
It’s a shallow copy
The items are basically moved (but not actually deleted) over to a new Collection. It doesn’t deep copy the items
.map((item) => ({ key: val, key2, val2, … })
I have to loop through and map every single invite??
Yea
You make it sound like a big issue
I do lol, let me try that.
Alright, it worked, thanks a lot for your help.