Skip to content

Commit

Permalink
weakmapmemoize
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredvu committed Jan 15, 2025
1 parent c827895 commit 25d2c9a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/abacus-ts/calculators/subaccount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BigNumber from 'bignumber.js';
import { groupBy, map, mapValues, orderBy, pickBy } from 'lodash';
import { weakMapMemoize } from 'reselect';

import { NUM_PARENT_SUBACCOUNTS } from '@/constants/account';
import {
Expand Down Expand Up @@ -296,18 +297,20 @@ function calculatePositionDerivedExtra(
};
}

export function calculateChildSubaccountSummaries(
parent: Omit<ParentSubaccountData, 'live'>,
markets: MarketsData
): Record<string, SubaccountSummary> {
return pickBy(
mapValues(
parent.childSubaccounts,
(subaccount) => subaccount && calculateSubaccountSummary(subaccount, markets)
),
isTruthy
);
}
export const calculateChildSubaccountSummaries = weakMapMemoize(
(
parent: Omit<ParentSubaccountData, 'live'>,
markets: MarketsData
): Record<string, SubaccountSummary> => {
return pickBy(
mapValues(
parent.childSubaccounts,
(subaccount) => subaccount && calculateSubaccountSummary(subaccount, markets)
),
isTruthy
);
}
);

/**
* @returns a list of pending isolated positions
Expand Down

0 comments on commit 25d2c9a

Please sign in to comment.