Some minor cleanups (#1966)

* Some minor cleanups

* Small additions

* Cleanup ExtrinsicEra decoding

* Minor adjustments

* Remove support for metadata v0 parsing

* Adjust refCountDelay

* refCountDelay comments

* Adjust Metadata tests

* Metadata default creation

* Funky lines

* Cleanup as AccountIdAndIndex

* Some derive returns

* Try and cleanup info extraction
This commit is contained in:
Jaco Greeff
2020-02-27 15:01:20 +01:00
committed by GitHub
parent efd6c5331d
commit 4e756704ea
28 changed files with 194 additions and 247 deletions
+13 -17
View File
@@ -8,35 +8,31 @@ const DELAY = 1750;
/** @internal */
function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
let connected = 0; // 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
let refCount = 0;
let con = Subscription.EMPTY;
let sched = Subscription.EMPTY;
// state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
return new Observable((ob) => {
source.subscribe(ob);
if (refCount++ === 0) {
if (connected === 1) {
connected = 3;
sched.unsubscribe();
if (state === 1) {
scheduler.unsubscribe();
} else {
con = (source as ConnectableObservable<T>).connect();
connected = 3;
connection = (source as ConnectableObservable<T>).connect();
}
state = 3;
}
return (): void => {
if (--refCount === 0) {
if (connected === 2) {
connected = 0;
sched.unsubscribe();
if (state === 2) {
state = 0; scheduler.unsubscribe();
} else {
// connected === 3
connected = 1;
sched = asapScheduler.schedule((): void => {
con.unsubscribe();
connected = 0;
// state === 3
state = 1;
scheduler = asapScheduler.schedule((): void => {
state = 0; connection.unsubscribe();
}, DELAY);
}
}