getx
getx copied to clipboard
[Potential Feature] `assignAll` notify the listener twice
Is there any way to make assignAll
to do not notify the listeners twice (once at clear
and another time at addAll
) ?
Is your feature request related to a problem? Please describe.
Every time I am trying to listen a RxList
I have the problem that I receive 2 events every time I want to "replace" the list with a new one.
final RxList<String> myAwesomeList = RxList();
// onInit
myAwesomeList.listen( (newList) => print('new value : ${newValue.length}'));
// somewhere in the app
myAwesomeList.assignAll(['This', 'is', 'cool'];
// Once I call `assignAll` the `listen` will return this
// -> "new value : 0"
// -> "new value : 3"
// if I call it again
myAwesomeList.assignAll(['nothing'];
// -> "new value : 0"
// -> "new value : 1"
Describe the solution you'd like
I have tried to understand how the assignAll
is working and after I have tried multiple solutions, seems like the only way is to change the set value
from RxObjectMixin and force it somehow to not sentToStream
in some specific situations. But also to be able to control the sentToStream
from assignAll
(or create replaceAll
, probably someone really needs the current assignAll
behaviour), because now sentToStream
can be accessed from assignAll
but it can't change the behaviour of set value
.
Any better idea I can try ?
Temporary Workaround
// instead of `.listen` I use `debounce` worker
debounce<List<String>>( myAwesomeList, (newList) => print('debounce : ${newList.length}'));
// it works because the operations `clear` and `addAll` are quick and ignored by `debounce`, so it will return only the last value provided by `addAll`
@jonataslaw Do you have any idea how we can solve this issue? Or any other approach I can try to avoid the double firing of the listen
callback ?