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
@@ -10,13 +10,13 @@ import { Observable, combineLatest, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { Option } from '@polkadot/types';
import { drr, memo } from '../util';
import { drr } from '../util';
/**
* @description From the list of stash accounts, retrieve the list of controllers
*/
export const controllers = memo((api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> => {
return memo((): Observable<[AccountId[], Option<AccountId>[]]> =>
export function controllers (api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> {
return (): Observable<[AccountId[], Option<AccountId>[]]> =>
api.query.staking.validators<[AccountId[]] & Codec>().pipe(
switchMap(([stashIds]): Observable<[AccountId[], Option<AccountId>[]]> =>
combineLatest([
@@ -28,6 +28,5 @@ export const controllers = memo((api: ApiInterfaceRx): () => Observable<[Account
])
),
drr()
)
);
}, true);
);
}
+5 -5
View File
@@ -18,7 +18,7 @@ import { isUndefined } from '@polkadot/util';
import { bestNumber } from '../chain/bestNumber';
import { eraLength } from '../session/eraLength';
import { recentlyOffline } from './recentlyOffline';
import { drr, memo } from '../util';
import { drr } from '../util';
interface Calls {
bestNumberCall (): Observable<BlockNumber>;
@@ -224,18 +224,18 @@ function retrieveV2 (api: ApiInterfaceRx, calls: Calls, stashId: AccountId): Obs
/**
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
*/
export const info = memo((api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> => {
export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> {
const calls = {
eraLengthCall: eraLength(api),
bestNumberCall: bestNumber(api),
recentlyOfflineCall: recentlyOffline(api)
};
return memo((_accountId: Uint8Array | string): Observable<DerivedStaking> => {
return (_accountId: Uint8Array | string): Observable<DerivedStaking> => {
const accountId = createType('AccountId', _accountId);
return api.consts.session
? retrieveV2(api, calls, accountId)
: retrieveV1(api, calls, accountId);
});
}, true);
};
}
+9 -10
View File
@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Option, Vec } from '@polkadot/types';
import { drr, memo } from '../util';
import { drr } from '../util';
// NOTE Unused ATM, preparing for V2-only
@@ -52,15 +52,14 @@ function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable<Result
]);
}
export const infoStash = memo((api: ApiInterfaceRx): (stashId: AccountId) => Observable<DerivedStakingStash> => {
return memo((stashId: AccountId): Observable<DerivedStakingStash> => {
return (
api.consts.session
? retrieveV2(api, stashId)
: retrieveV1(api, stashId)
).pipe(
export function infoStash (api: ApiInterfaceRx): (stashId: AccountId) => Observable<DerivedStakingStash> {
const query = api.consts.session
? retrieveV2
: retrieveV1;
return (stashId: AccountId): Observable<DerivedStakingStash> =>
query(api, stashId).pipe(
map((result): DerivedStakingStash => parse(stashId, result)),
drr()
);
});
}, true);
}
+5 -6
View File
@@ -10,16 +10,16 @@ import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { createType, Vec } from '@polkadot/types';
import { drr, memo } from '../util';
import { drr } from '../util';
import { indexes as sessionIndexes } from '../session';
/**
* @description Retrieve the staking overview, including elected and points earned
*/
export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> => {
export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> {
const sessionIndexesCall = sessionIndexes(api);
return memo((): Observable<DerivedStakingOverview> =>
return (): Observable<DerivedStakingOverview> =>
combineLatest([
sessionIndexesCall(),
api.queryMulti<[Vec<AccountId>, Vec<AccountId>]>([
@@ -40,6 +40,5 @@ export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStak
currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount
})),
drr()
)
);
}, true);
);
}
@@ -11,7 +11,7 @@ import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedRecentlyOffline } from '../types';
import { drr, memo } from '../util';
import { drr } from '../util';
type OfflineResult = [AccountId, BlockNumber, BN][] & Codec;
@@ -35,8 +35,8 @@ function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline
/**
* @description Retrieve a keyed record of accounts recently reported to be offline
*/
export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> => {
return memo((): Observable<DerivedRecentlyOffline> =>
export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> {
return (): Observable<DerivedRecentlyOffline> =>
(
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
// replacement as actually use and implement it
@@ -46,6 +46,5 @@ export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<Deri
).pipe(
map(expandDerived),
drr()
)
);
}, true);
);
}
@@ -8,19 +8,18 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { drr, memo } from '../util';
import { drr } from '../util';
import { overview } from './overview';
/**
* @description Retrieve latest list of validators
*/
export const validators = memo((api: ApiInterfaceRx): () => Observable<AccountId[]> => {
export function validators (api: ApiInterfaceRx): () => Observable<AccountId[]> {
const overviewCall = overview(api);
return memo((): Observable<AccountId[]> =>
return (): Observable<AccountId[]> =>
overviewCall().pipe(
map(({ validators }): AccountId[] => validators),
drr()
)
);
}, true);
);
}