on master help sign in
Improve performance on IssueChild

By only using ob on-demand to get the number from the input, rather than rendering all available point numbers ahead of time.

commit0fb9b33fcc9029edd727bf008e692e5a3c49dd66 authorFang <git@fang.io> dateWed 24 Jul 2019, 20:43 (7 years ago) parent4adbdc3
2 files changed+17−7
src/lib/validators.js+10 src/views/IssueChild.js+7−7
src/lib/validators.js+10
@@ -252,6 +252,16 @@ export const validateInSet = (set, error) => m =>
252252 error,
253253 });
254254
255+export const validateNameInNumberSet = (set, error) => m =>
256+ simpleValidatorWrapper({
257+ prevMessage: m,
258+ validator: p => {
259+ const num = patp2dec(p);
260+ return set.has(num);
261+ },
262+ error,
263+ });
264+
255265export const validatePatpByteLength = byteLength => {
256266 return validateLength(patpStringLength(byteLength));
257267};
src/views/IssueChild.js+7−7
@@ -21,7 +21,7 @@ import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
2121import View from 'components/View';
2222import useLifecycle from 'lib/useLifecycle';
2323import { usePointCursor } from 'store/pointCursor';
24−import { validateInSet } from 'lib/validators';
24+import { validateNameInNumberSet } from 'lib/validators';
2525import { getSpawnCandidate } from 'lib/child';
2626
2727function useIssueChild() {
@@ -56,7 +56,7 @@ export default function IssueChild() {
5656 const _contracts = need.contracts(contracts);
5757 const _point = parseInt(need.point(pointCursor), 10);
5858
59− const [availablePointNames, setAvailablePointNames] = useState(Nothing());
59+ const [availablePoints, setAvailablePoints] = useState(Nothing());
6060
6161 const candidates = useMemo(() => {
6262 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
@@ -75,12 +75,12 @@ export default function IssueChild() {
7575
7676 const validators = useMemo(
7777 () => [
78− validateInSet(
79− availablePointNames.getOrElse(new Set()),
78+ validateNameInNumberSet(
79+ availablePoints.getOrElse(new Set()),
8080 'This point cannot be spawned.'
8181 ),
8282 ],
83− [availablePointNames]
83+ [availablePoints]
8484 );
8585 const [
8686 pointNameInput,
@@ -91,7 +91,7 @@ export default function IssueChild() {
9191 disabled: inputsLocked,
9292 autoFocus: true,
9393 validators,
94− error: availablePointNames.matchWith({
94+ error: availablePoints.matchWith({
9595 Nothing: () => 'Loading availability...',
9696 Just: () => undefined,
9797 }),
@@ -124,7 +124,7 @@ export default function IssueChild() {
124124 return;
125125 }
126126
127− setAvailablePointNames(Just(new Set(availablePoints.map(ob.patp))));
127+ setAvailablePoints(Just(new Set(availablePoints)));
128128 })();
129129
130130 return () => (mounted = false);