Remove derive memos (#1538)
* Remove derive memos * Remove outer memo * Over-eager replace
This commit is contained in:
@@ -9,7 +9,7 @@ import { Observable } from 'rxjs';
|
||||
import { Vec } from '@polkadot/types';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr, memo } from '../util';
|
||||
import { drr } from '../util';
|
||||
|
||||
/**
|
||||
* @name approvalsOf
|
||||
@@ -23,8 +23,8 @@ import { drr, memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> => {
|
||||
return memo((who: AccountId | string): Observable<boolean[][]> =>
|
||||
export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> {
|
||||
return (who: AccountId | string): Observable<boolean[][]> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi(
|
||||
@@ -39,6 +39,5 @@ export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Obser
|
||||
)
|
||||
),
|
||||
drr()
|
||||
)
|
||||
);
|
||||
}, true);
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr, memo } from '../util';
|
||||
import { drr } from '../util';
|
||||
|
||||
/**
|
||||
* @name approvalsOfAt
|
||||
@@ -25,11 +25,10 @@ import { drr, memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const approvalsOfAt = memo((api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> => {
|
||||
return memo((who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
||||
export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> {
|
||||
return (who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
||||
api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]).pipe(
|
||||
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
drr()
|
||||
)
|
||||
);
|
||||
}, true);
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType, Vec, u32 } from '@polkadot/types';
|
||||
|
||||
import { DerivedElectionsInfo } from '../types';
|
||||
import { drr, memo } from '../util';
|
||||
import { drr } from '../util';
|
||||
|
||||
type ResultElectionsInner = [u32, u32, Vec<[AccountId, BlockNumber] & Codec>, SetIndex, BlockNumber, VoteIndex, SetIndex];
|
||||
type ResultElections = [Vec<AccountId>, ResultElectionsInner];
|
||||
@@ -89,10 +89,9 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> => {
|
||||
return memo((): Observable<DerivedElectionsInfo> => {
|
||||
return api.query.electionsPhragmen
|
||||
export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
|
||||
return (): Observable<DerivedElectionsInfo> =>
|
||||
api.query.electionsPhragmen
|
||||
? queryPhragmen(api)
|
||||
: queryElections(api);
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import BN from 'bn.js';
|
||||
import { of, combineLatest, Observable } from 'rxjs';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
|
||||
import { drr, memo } from '../util';
|
||||
import { drr } from '../util';
|
||||
|
||||
/**
|
||||
* @name voterPositions
|
||||
@@ -26,8 +26,8 @@ import { drr, memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> => {
|
||||
return memo((): Observable<DerivedVoterPositions> =>
|
||||
export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> {
|
||||
return (): Observable<DerivedVoterPositions> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize) as any as Observable<BN>,
|
||||
@@ -54,6 +54,5 @@ export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<Deriv
|
||||
}, {});
|
||||
}),
|
||||
drr()
|
||||
)
|
||||
);
|
||||
}, true);
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr, memo } from '../util';
|
||||
import { drr } from '../util';
|
||||
import { voterPositions } from './voterPositions';
|
||||
|
||||
/**
|
||||
@@ -25,21 +25,19 @@ import { voterPositions } from './voterPositions';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const voters = memo((api: ApiInterfaceRx): () => Observable<Vec<AccountId>> => {
|
||||
export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
|
||||
const voterPositionsCall = voterPositions(api);
|
||||
|
||||
return memo((): Observable<Vec<AccountId>> =>
|
||||
return (): Observable<Vec<AccountId>> =>
|
||||
voterPositionsCall().pipe(
|
||||
map(
|
||||
(voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
createType(
|
||||
'Vec<AccountId>',
|
||||
Object.entries(voterPositions)
|
||||
.sort((a, b): 0 | 1 | -1 => a[1].globalIndex.cmp(b[1].globalIndex))
|
||||
.map(([accountId]): AccountId => createType('AccountId', accountId))
|
||||
)
|
||||
map((voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
createType(
|
||||
'Vec<AccountId>',
|
||||
Object.entries(voterPositions)
|
||||
.sort((a, b): number => a[1].globalIndex.cmp(b[1].globalIndex))
|
||||
.map(([accountId]): AccountId => createType('AccountId', accountId))
|
||||
)
|
||||
),
|
||||
drr()
|
||||
)
|
||||
);
|
||||
}, true);
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user