Remove derive memos (#1538)

* Remove derive memos

* Remove outer memo

* Over-eager replace
This commit is contained in:
Jaco Greeff
2019-11-03 11:38:36 +01:00
committed by GitHub
parent 0e037de1b1
commit 506b042f8c
44 changed files with 273 additions and 305 deletions
+5 -6
View File
@@ -8,16 +8,15 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util';
import { drr } from '../util';
import { info } from './info';
export const eraLength = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
export function eraLength (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const infoCall = info(api);
return memo((): Observable<BlockNumber> =>
return (): Observable<BlockNumber> =>
infoCall().pipe(
map(({ eraLength }): BlockNumber => eraLength),
drr()
)
);
}, true);
);
}
@@ -8,16 +8,15 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util';
import { drr } from '../util';
import { info } from './info';
export const eraProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
export function eraProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const infoCall = info(api);
return memo((): Observable<BlockNumber> =>
return (): Observable<BlockNumber> =>
infoCall().pipe(
map(({ eraProgress }): BlockNumber => eraProgress),
drr()
)
);
}, true);
);
}
+5 -6
View File
@@ -10,10 +10,10 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { u32 } from '@polkadot/types';
import { drr, memo } from '../util';
import { drr } from '../util';
export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> => {
return memo((): Observable<DeriveSessionIndexes> =>
export function indexes (api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
return (): Observable<DeriveSessionIndexes> =>
api.queryMulti<[SessionIndex, EraIndex, u32]>([
api.query.session.currentIndex,
api.query.staking.currentEra,
@@ -23,6 +23,5 @@ export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessio
currentIndex, currentEra, validatorCount
})),
drr()
)
);
}, true);
);
}
+13 -16
View File
@@ -10,7 +10,7 @@ import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { Option, u64, createType } from '@polkadot/types';
import { drr, memo } from '../util';
import { drr } from '../util';
import { bestNumber } from '../chain';
import { indexes } from './indexes';
@@ -88,8 +88,7 @@ function infoV1 (api: ApiInterfaceRx, { bestNumberCall, indexesCall }: Calls): O
api.query.staking.sessionsPerEra
])
]).pipe(
map(createDerivedV1),
drr()
map(createDerivedV1)
);
}
@@ -101,8 +100,7 @@ function infoLatestAura (api: ApiInterfaceRx, { indexesCall }: Calls): Observabl
indexes,
[createType('u64', 1), createType('u64', 1), createType('u64', 1), createType('SessionIndex', 1)]
])
),
drr()
)
);
}
@@ -122,25 +120,24 @@ function infoLatestBabe (api: ApiInterfaceRx, { indexesCall }: Calls): Observabl
indexes,
slots
])
),
drr()
)
);
}
/**
* @description Retrieves all the session and era info and calculates specific values on it as the length of the session and eras
*/
export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedSessionInfo> => {
export function info (api: ApiInterfaceRx): () => Observable<DerivedSessionInfo> {
const calls = {
bestNumberCall: bestNumber(api),
indexesCall: indexes(api)
};
const query = api.consts.staking
? api.consts.babe
? infoLatestBabe // 2.x with Babe
: infoLatestAura // 2.x with Aura (not all info there)
: infoV1;
return memo((): Observable<DerivedSessionInfo> => {
return api.consts.staking
? api.consts.babe
? infoLatestBabe(api, calls) // 2.x with Babe
: infoLatestAura(api, calls) // 2.x with Aura (not all info there)
: infoV1(api, calls); // 1.x
});
}, true);
return (): Observable<DerivedSessionInfo> =>
query(api, calls).pipe(drr());
}
@@ -8,16 +8,15 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util';
import { drr } from '../util';
import { info } from './info';
export const sessionProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
export function sessionProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const infoCall = info(api);
return memo((): Observable<BlockNumber> =>
return (): Observable<BlockNumber> =>
infoCall().pipe(
map(({ sessionProgress }): BlockNumber => sessionProgress),
drr()
)
);
}, true);
);
}