1import { useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
4import useSetState from 'lib/useSetState';
6const DEFAULT_OPTIMISTIC_DETAILS = {
7 keyRevisionNumber: Nothing(),
10export default function useOptimisticDetailsStore() {
11 const [optimisticDetails, addToOptimisticDetails] = useSetState({});
13 const getOptimisticDetails = useCallback(
14 point => optimisticDetails[point] || DEFAULT_OPTIMISTIC_DETAILS,
18 const _buildSetter = key =>
21 addToOptimisticDetails({
23 ...DEFAULT_OPTIMISTIC_DETAILS,
24 ...optimisticDetails[point],
25 ...optimisticDetails({ [key]: Just(value) }),
28 // NOTE: this usage of useCallback is ok because it is called a constant
29 // number of times. the linter also doesn't understand that it's within
30 // a closure, so we disable the rule here.
31 // eslint-disable-next-line react-hooks/exhaustive-deps
32 [addToOptimisticDetails, optimisticDetails]
35 const setOptimisticKeyRevision = _buildSetter('keyRevisionNumber');
37 return { getOptimisticDetails, setOptimisticKeyRevision };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list