Closed amaury1093 closed 5 years ago
Agreed that it probably needs to dit one lower. Not 100% sure how the update above happens - does the RPC really return 2 distinct values that we decode to 1? Or it doesn't and we decide to make it so?
does the RPC really return 2 distinct values that we decode to 1
No idea tbh, will have to investigate a bit
A quick sanity check suggests the RPC is returning the same value but the drr
is not correctly comparing the returned objects.
drr.spec.ts
it('should not fire twice the same object', (done): void => {
let count = 0;
of({ a: 1 }, { a: 1 }).pipe(drr()).subscribe((): void => { ++count; });
setTimeout((): void => {
expect(count).toBe(1);
done();
}, 50);
});
Checking for deep equality in the drr
with something like lodash will make the above test pass:
// drr.ts
import { isEqual } from 'lodash';
export const drr = (): DrrResult => <T> (source$: Observable<T>): Observable<T> =>
source$.pipe(
catchError((error): Observable<never> => {
l.error(error);
throw error;
}),
distinctUntilChanged(isEqual),
publishReplay(1),
refCount()
);
That being said, the whole distinctUntilChanged()
could be piped right into createMethodSubscribe
for the Codec
output from formatOutput
in RPCCore.
I don't think deep equality will work because we're dealing with classes here (not 100% sure though), but anyway a better way to check would be to use .eq()
from Codec
. We can assume that there are only Codec
and Codec[]
coming back from rpc responses.
createMethodSubscribe
sounds like a good place to put distinctUntilChanged.
Only Codec
from RPC responses.
Hmm, e.g. when I subscribe api.rpc.state.subscribeStorage([0x..., 0x...])
, I get a Codec[]
in return.
Dangit, I forgot about my fav call, you are right.
We mangle this thing "incorrectly" though since StorageChangeSet
has a Vec<KeyValueOption>
- and it actually also breaks since we should really be consistent. But then we get into the age-old "it is not really a codec anymore", like we have on derive.
But that is not a problem for this one.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.
Repro:
Expected:
Actual:
Notes:
Codec
andCodec[]