on adbcda8 help sign in
bridge/src/lib/useSyncPoints.js
24 lines 751 B history raw
1import { useEffect } from 'react';
2import { isEqual } from 'lodash';
4import { usePointCache } from 'store/pointCache';
5import usePreviousValue from 'lib/usePreviousValue';
7// sync a known point to the cache (i.e display values)
8export function useSyncKnownPoints(points = []) {
9 //
12// sync an owned point to the cache
13export function useSyncOwnedPoints(points = []) {
14 const { syncOwnedPoint } = usePointCache();
15 const prevPoints = usePreviousValue(points);
17 useEffect(() => {
18 if (!isEqual(prevPoints, points)) {
19 // if the actual set of points changes, sync the whole array
20 // TODO: we should get clever about caching
21 points.forEach(point => syncOwnedPoint(point));
22 }
23 }, [syncOwnedPoint, prevPoints, points]);