Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rescuing a SPAghetti React project

Last9
April 27, 2021

Rescuing a SPAghetti React project

Every project starts with good code but if care is not taken after few months realization sinks in that the code is not maintainable at all. Everyone scares to touch the code. How do you come out of this? Well, you go back to drawing board and improve one thing at a time. With Confidence, safety toolkit and shared mental model it becomes easier to enforce correctness into the codebase and that's what we did to rescue our frontend app at Last9.

Last9

April 27, 2021
Tweet

Other Decks in Technology

Transcript

  1. function validateTimestamp(atTimestamp, currentUser) { if (atTimestamp > 0) { if

    (currentUser.admin) { dispatch() } return true; } return false; }
  2. function validateTimestamp(atTimestamp) { if (atTimestamp > 0) { return true;

    } return false; } validTs = validateTimestamp(atTimestamp); if (validTs && currentUser.admin) { dispatch() }
  3. function useDidUpdateEffect(fn, inputs) { const fncRef = useRef(); fncRef.current =

    fn; const didMountRef = useRef(false); useEffect(() => { if (!didMountRef.current) { didMountRef.current = true; } else { return fncRef.current(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, inputs); } useDidUpdateEffect
  4. useCallback true === true // true false === false //

    true 1 === 1 // true 'a' === 'a' // true {} === {} // false [] === [] // false () => {} === () => {} // false const z = {} z === z // true
  5. useCallback const isSelected = useCallback((item) => selectedItems.includes(item), [selectedItems]); return (

    <List classes={{ root: classes.listRoot }}> {listItems.map((item) => ( <ListItem key={item} onClick={() => onSelect(item)} disableGutters classes={{ root: classes.listItemRoot, selected: classes.listItemSelected }} selected={isSelected(item)} button > <ListItemText classes={{ primary: classes.listItemTextPrimary }}> {item} </ListItemText> </ListItem> ))} </List> );
  6. useEffect(() => { if (graphType === GraphType.Custom && views.length ===

    0) { setSelectedNodeIdents([]); } }, [views.length]);
  7. useEffect(() => { if (graphType === GraphType.Custom && views.length ===

    0) { setSelectedNodeIdents([]); } }, [views.length, graphType]);
  8. export type Timestamp = number; export type MaybeTimestamp = Timestamp|

    null | undefined; export interface TimeRange { from: Timestamp; to: Timestamp; } export enum ViewType { Custom = 'custom', Automatic = 'automatic', }
  9. export interface Query { where?: { name: string }; select?:

    { type: 'custom' | ‘automatic' }; } export interface QueryWithLimit extends Query { limit: number; }
  10. knowledge structure(s) held by each member of a team that

    enables them to form accurate explanations and expectations