Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

simplify on any update using asterix for event name

Oleg Isonenf3c384d8cfc5
diff --git a/app/canvas/shared/use-on-any-update.ts b/app/canvas/shared/use-on-any-update.ts
new file mode 100644
index 0000000000..2997d3c56e
--- /dev/null
+++ b/app/canvas/shared/use-on-any-update.ts
@@ -0,0 +1,13 @@
+import { useCallback } from "react";
+import { useSubscribe } from "@webstudio-is/sdk";
+
+/**
+ * This hook lets you subscribe any rendering event we know that is triggered by pubsub.
+ * It calls the callback after the updates should have already happened.
+ */
+export const useOnAnyUpdate = (callback: () => void) => {
+ const handleUpdate = useCallback(() => {
+ requestAnimationFrame(callback);
+ }, [callback]);
+ useSubscribe("*", handleUpdate);
+};
diff --git a/app/canvas/shared/use-on-render.ts b/app/canvas/shared/use-on-render.ts
deleted file mode 100644
index 6b96f6235c..0000000000
--- a/app/canvas/shared/use-on-render.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { useCallback } from "react";
-import { useSubscribe } from "@webstudio-is/sdk";
-import { useSelectedElement } from "./nano-values";
-
-/**
- * This hook lets you subscribe any rendering event we know that is triggered by pubsub.
- * It calls the callback after the updates should have already happened.
- */
-export const useOnRender = (callback: () => void) => {
- const [selectedElement] = useSelectedElement();
- const handleUpdate = useCallback(() => {
- requestAnimationFrame(callback);
- }, [callback]);
- useSubscribe("updateStyle", handleUpdate);
- useSubscribe("updateProps", handleUpdate);
- useSubscribe(`previewStyle:${selectedElement?.id}`, handleUpdate);
- useSubscribe("insertInstance", handleUpdate);
- useSubscribe("reparentInstance", handleUpdate);
- useSubscribe("deleteInstance", handleUpdate);
- useSubscribe("breakpointChange", handleUpdate);
- useSubscribe("breakpointDelete", handleUpdate);
-};
diff --git a/app/canvas/shared/use-outline.tsx b/app/canvas/shared/use-outline.tsx
index f548506d06..d63b16eed6 100644
--- a/app/canvas/shared/use-outline.tsx
+++ b/app/canvas/shared/use-outline.tsx
@@ -5,7 +5,7 @@ import { getBoundingClientRect } from "~/shared/dom-utils";
import { primitives } from "~/shared/component";
import { useHoveredElement, useSelectedElement } from "./nano-values";
import { styled, darkTheme } from "~/shared/design-system";
-import { useOnRender } from "./use-on-render";
+import { useOnAnyUpdate } from "./use-on-any-update";
import { useWindowResize } from "~/shared/dom-hooks";
const useElement = (
@@ -36,7 +36,7 @@ const useStyle = (element?: HTMLElement) => {
forceRender(!rerenderFlag);
}, [element, rerenderFlag]);
- useOnRender(handleUpdate);
+ useOnAnyUpdate(handleUpdate);
useWindowResize(handleUpdate);
return useMemo(