mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 13:05:08 +09:00
memoize initialized breakpoints
This commit is contained in:
1 parent
2403d8dd8e
commit
539da2ba4f
2 files changed
+15
-10
No files matched your search
@@ -6,11 +6,9 @@ import {
|
||||
type OnChangeChildren,
|
||||
type Data,
|
||||
type Tree,
|
||||
type Breakpoint,
|
||||
useAllUserProps,
|
||||
WrapperComponent,
|
||||
globalStyles,
|
||||
setBreakpoints,
|
||||
Project,
|
||||
} from "@webstudio-is/sdk";
|
||||
import { useSubscribe } from "./shared/pubsub";
|
||||
@@ -41,6 +39,7 @@ import { useManageProps } from "./shared/props";
|
||||
import {
|
||||
useBreakpointChange,
|
||||
usePublishBreakpoints,
|
||||
useInitializeBreakpoints,
|
||||
} from "./shared/breakpoints";
|
||||
|
||||
const useElementsTree = () => {
|
||||
@@ -74,12 +73,6 @@ const useSubscribePreviewMode = () => {
|
||||
return isPreviewMode;
|
||||
};
|
||||
|
||||
const useUpdateBreakpoints = (breakpoints: Array<Breakpoint>) => {
|
||||
const [, setCurrentBreakpoints] = useBreakpoints();
|
||||
setBreakpoints(breakpoints);
|
||||
setCurrentBreakpoints(breakpoints);
|
||||
};
|
||||
|
||||
const PreviewMode = () => {
|
||||
const [rootInstance] = useRootInstance();
|
||||
const [breakpoints] = useBreakpoints();
|
||||
@@ -123,7 +116,7 @@ type CanvasProps = {
|
||||
};
|
||||
|
||||
export const Canvas = ({ data }: CanvasProps): JSX.Element | null => {
|
||||
useUpdateBreakpoints(data.breakpoints);
|
||||
useInitializeBreakpoints(data.breakpoints);
|
||||
globalStyles();
|
||||
useAllUserProps(data.props);
|
||||
usePopulateRootInstance(data.tree);
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
import { useEffect } from "react";
|
||||
import store from "immerhin";
|
||||
import { type Breakpoint, useSubscribe } from "@webstudio-is/sdk";
|
||||
import {
|
||||
type Breakpoint,
|
||||
useSubscribe,
|
||||
setBreakpoints,
|
||||
} from "@webstudio-is/sdk";
|
||||
import { useBreakpoints, breakpointsContainer } from "./nano-values";
|
||||
import { publish } from "./pubsub";
|
||||
|
||||
store.register("breakpoints", breakpointsContainer);
|
||||
|
||||
export const useInitializeBreakpoints = (breakpoints: Array<Breakpoint>) => {
|
||||
const [, setCurrentBreakpoints] = useBreakpoints();
|
||||
useEffect(() => {
|
||||
setBreakpoints(breakpoints);
|
||||
setCurrentBreakpoints(breakpoints);
|
||||
}, [breakpoints, setCurrentBreakpoints]);
|
||||
};
|
||||
|
||||
export const usePublishBreakpoints = () => {
|
||||
const [breakpoints] = useBreakpoints();
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user