1import { Just, Nothing } from 'folktale/maybe';
2import Result from 'folktale/result';
3import React, { createContext, forwardRef, useContext } from 'react';
5import useDeepEqualReference from 'lib/useDeepEqualReference';
6import usePointStore from './lib/usePointStore';
9 * Avoid race condition by setting an initial dummy state. Previously, on
10 * occasion the application would render before the points queries finished
11 * loading data asynchronously from the roller and Infura. This would cause
12 * a crash in Points.tsx when attempting to destructure the data.
14const initialContext = {
16 rekeyDates: Nothing(),
17 controlledPoints: Just(Result.Error('not yet loaded')),
20 syncDetails: () => [],
21 syncRekeyDate: () => [],
22 syncControlledPoints: () => [],
24 syncResidents: () => [],
28export const PointCacheContext = createContext(initialContext);
30export function PointCacheProvider({ children }) {
31 const cache = usePointStore();
34 <PointCacheContext.Provider value={useDeepEqualReference(cache)}>
36 </PointCacheContext.Provider>
41export function usePointCache() {
42 return useContext(PointCacheContext);
46export const withPointCache = Component =>
47 forwardRef((props, ref) => (
48 <PointCacheContext.Consumer>
49 {cache => <Component ref={ref} {...cache} {...props} />}
50 </PointCacheContext.Consumer>
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