Closed mattkrick closed 8 years ago
without making the user tell us what kind of mutation it is, we can use a heuristic to detect deletions and changes with pretty darn good (perfect?) accuracy.
however, it's possible that the mutation triggered a replace where the new state has 1 or more new docs and removed 1 or more docs. These are probably pretty rare because the UX to implement them is terrible, but they should be captured.
full
(no or complete pagination args) then target.full = src.full
.difference(newState, oldState) < threshold ? replace : append
.Alternatively, we know appends can only come from a query
and everything else can only come from a mutation. So, we could just create a different an isMutation
param that is passed into mergeStores
and achieve 100% accuracy.
The only problem with that is the EOF, BOF
support, since newState
won't receive that extra document.
So,
cashayArray
object,full
, the target.full = src.full
front
, detect if the last document was usedlast
, detect if the first document was used (or if it was just fetched optimistically)how do we detect if a doc was used? that's pretty difficult. BUT, we do know that the currentResponse
given to the mutationHandler
is a subset of the entire front
or back
array. So, if we could find out where that subset begins & ends, we could replace the old with the new.
so, how do we figure out the location of the subset?
startIdx
and subsetLength
on the denormalized array. then, we can use that info during the merge within redux. only problem is that during the merge we'll have to mutate the src
input (denormalized result). If we wanted to be kosher, we could do it before it entered dispatch
, but an extra tree traversal doesn't seem worth it. done!
currently, merging arrays works great for newsfeeds, but not great for things like a kanban. That's because when arrays are merged, they follow a basic set of rules:
For a kanban, we'd expect different handling. For example:
Currently, this is manageable by using hash tables
{1: {foo: 'bar'}}
, but that requires some back-end schema changes. It'd be nicer if it worked with arrays, too.