animated-stream-list icon indicating copy to clipboard operation
animated-stream-list copied to clipboard

DiffUtil.eq always null in isolate

Open dcemmerson opened this issue 4 years ago • 0 comments

While trying to use the animated stream list package in my project, I am finding that DiffUtil.eq is always null inside the _myersDiff method, which is called in a separate isolate. This results in undesired behavior, such as animating out the wrong list item on the UI when removing an item.

Before spawning the isolate, DiffUtil.eq is correctly set to the function I pass to AnimatedStreamList for the equals parameter. Inside the spawned isolate, DiffUtil.eq is null, meaning _myersDiff defaults to using (a, b) => a == b for comparison.

From my (minimal) knowledge of isolates, I think this is the expected behavior when spawning an isolate since the isolate does not share memory with the main thread.

Here are a few thoughts I've had on ways to resolve this issue:

  1. Pass the equality function to _myersDiff in the spawned isolate arguments. I think this might be the best option, but I know there are some important semantics that need to be considered when passing arguments to an isolate, as mentioned in #5 by @JulianAssmann.

  2. Schedule _myersDiff to run as a microtask instead of a separate isolate, as mentioned in #4 by @feedrdev. I think this would be a pretty simple and easy solution to the problem and would work fine for reasonably sized lists.

  3. Require the user to override the == operator in the class for which the stream passed to AnimatedStreamList emits. I think this is unnecessarily intrusive to the user and probably the least ideal option.

I'm happy to implement any of these solutions and create a pull request, but was hoping to get some consensus first.

dcemmerson avatar Nov 19 '20 00:11 dcemmerson