mattkrick / cashay

:moneybag: Relay for the rest of us :moneybag:
MIT License
453 stars 28 forks source link

array handling: deleting and moving #36

Closed mattkrick closed 8 years ago

mattkrick commented 8 years ago

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.

mattkrick commented 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.

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,

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?

done!