8000 fix(react): reactive hooks, expose type def, simplify logic by charlieforward9 · Pull Request #329 · visgl/hubble.gl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(react): reactive hooks, expose type def, simplify logic #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion modules/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export {
AnimationManager,
Animation,
DeckAnimation,
KeplerAnimation
KeplerAnimation,
// Config
FormatConfigs
} from '@hubble.gl/core';

export {
Expand Down
54 changes: 22 additions & 32 deletions modules/react/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export function useDeckAdapter(
a.animationManager.attachAnimation(deckAnimation);
deckAnimation.draw();
return a;
}, []);
}, [deckAnimation]);
return {adapter, layers, cameraFrame, setCameraFrame};
}

export function useDeckAnimation(params: DeckAnimationConstructor) {
return useMemo(() => new DeckAnimation(params), []);
return useMemo(() => new DeckAnimation(params), [params]);
}

export function useHubbleGl<ReactMapRef extends MapRef>({
Expand All @@ -53,43 +53,33 @@ export function useHubbleGl<ReactMapRef extends MapRef>({
initialViewState
);

const => {
if (mapRef) {
const map = mapRef.current.getMap();
map.on('render', () => adapter.onAfterRender(nextFrame, map.areTilesLoaded()));
}
}, [adapter, nextFrame]);

if (!mapRef) {
const mapProps = useMemo(() => {
if (!mapRef) return {};
return {
adapter,
cameraFrame,
setCameraFrame,
mapProps: {},
deckProps: adapter.getProps({
deck,
onNextFrame: nextFrame,
extraProps: {
layers
onLoad: () => {
if (mapRef.current) {
const map = mapRef.current.getMap();
map.on('render', () => adapter.onAfterRender(nextFrame, map.areTilesLoaded()));
}
})
},
preventStyleDiffing: true
};
}
}, [mapRef, adapter, nextFrame]);

const deckProps = useMemo(() => {
if (!deck) return {};
return adapter.getProps({
deck,
onNextFrame: mapRef ? undefined : nextFrame,
extraProps: {layers}
});
}, [deck, adapter, layers, mapRef, nextFrame]);

return {
adapter,
cameraFrame,
setCameraFrame,
onMapLoad,
mapProps: {
onLoad: onMapLoad,
preventStyleDiffing: true
},
deckProps: adapter.getProps({
deck,
extraProps: {
layers
}
})
mapProps,
deckProps
};
}
Loading
0