on master help sign in
Improve performance on IssueChild
0fb9b33Fang
src/lib/validators.js+10
@@ -252,6 +252,16 @@ export const validateInSet = (set, error) => m =>
252 error,
252 error,
253 });
253 });
254
254
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+
255export const validatePatpByteLength = byteLength => {
265export const validatePatpByteLength = byteLength => {
256 return validateLength(patpStringLength(byteLength));
266 return validateLength(patpStringLength(byteLength));
257};
267};
src/views/IssueChild.js+7−7
@@ -21,7 +21,7 @@ import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
21import View from 'components/View';
21import View from 'components/View';
22import useLifecycle from 'lib/useLifecycle';
22import useLifecycle from 'lib/useLifecycle';
23import { usePointCursor } from 'store/pointCursor';
23import { usePointCursor } from 'store/pointCursor';
24−import { validateInSet } from 'lib/validators';
24+import { validateNameInNumberSet } from 'lib/validators';
25import { getSpawnCandidate } from 'lib/child';
25import { getSpawnCandidate } from 'lib/child';
26
26
27function useIssueChild() {
27function useIssueChild() {
@@ -56,7 +56,7 @@ export default function IssueChild() {
56 const _contracts = need.contracts(contracts);
56 const _contracts = need.contracts(contracts);
57 const _point = parseInt(need.point(pointCursor), 10);
57 const _point = parseInt(need.point(pointCursor), 10);
58
58
59− const [availablePointNames, setAvailablePointNames] = useState(Nothing());
59+ const [availablePoints, setAvailablePoints] = useState(Nothing());
60
60
61 const candidates = useMemo(() => {
61 const candidates = useMemo(() => {
62 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
62 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
@@ -75,12 +75,12 @@ export default function IssueChild() {
75
75
76 const validators = useMemo(
76 const validators = useMemo(
77 () => [
77 () => [
78− validateInSet(
78+ validateNameInNumberSet(
79− availablePointNames.getOrElse(new Set()),
79+ availablePoints.getOrElse(new Set()),
80 'This point cannot be spawned.'
80 'This point cannot be spawned.'
81 ),
81 ),
82 ],
82 ],
83− [availablePointNames]
83+ [availablePoints]
84 );
84 );
85 const [
85 const [
86 pointNameInput,
86 pointNameInput,
@@ -91,7 +91,7 @@ export default function IssueChild() {
91 disabled: inputsLocked,
91 disabled: inputsLocked,
92 autoFocus: true,
92 autoFocus: true,
93 validators,
93 validators,
94− error: availablePointNames.matchWith({
94+ error: availablePoints.matchWith({
95 Nothing: () => 'Loading availability...',
95 Nothing: () => 'Loading availability...',
96 Just: () => undefined,
96 Just: () => undefined,
97 }),
97 }),
@@ -124,7 +124,7 @@ export default function IssueChild() {
124 return;
124 return;
125 }
125 }
126
126
127− setAvailablePointNames(Just(new Set(availablePoints.map(ob.patp))));
127+ setAvailablePoints(Just(new Set(availablePoints)));
128 })();
128 })();
129
129
130 return () => (mounted = false);
130 return () => (mounted = false);