Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Nov 5, 2024
1 parent 4cdd91a commit 42fca8b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 38 deletions.
10 changes: 5 additions & 5 deletions chrome/public/bundle/detector.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions chrome/public/bundle/hook.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions chrome/public/bundle/panel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions chrome/public/bundle/proxy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions chrome/public/bundle/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions chrome/src/hooks/useIframeDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const from = "iframe";

const render = "hook-render";

const poseMessageFromIframe = (data: any) => {
const postMessageFromIframe = (data: any) => {
window.top?.postMessage({ from, ...data, source: DevToolSource }, "*");
};

const debouncePostMessageFromIframe = debounce(postMessageFromIframe, 100);

export const useIframeDev = () => {
useEffect(() => {
const currentIsIframe = window !== window.top;
Expand All @@ -39,9 +41,9 @@ export const useIframeDev = () => {
if (connect) {
return;
} else {
poseMessageFromIframe({ type: MessageWorkerType.init });
postMessageFromIframe({ type: MessageWorkerType.init });

poseMessageFromIframe({ type: MessagePanelType.show });
postMessageFromIframe({ type: MessagePanelType.show });

id = setTimeout(listenBackEndReady, 1000);
}
Expand All @@ -63,9 +65,9 @@ export const useIframeDev = () => {
if (currentSelect) {
useDetailNode.getActions().setLoading(true);

poseMessageFromIframe({ type: MessagePanelType.nodeSelect, data: currentSelect });
postMessageFromIframe({ type: MessagePanelType.nodeSelect, data: currentSelect });
} else {
poseMessageFromIframe({ type: MessagePanelType.nodeSelect, data: null });
postMessageFromIframe({ type: MessagePanelType.nodeSelect, data: null });
}
}
)
Expand All @@ -80,7 +82,7 @@ export const useIframeDev = () => {
if (currentSelect) {
useDetailNode.getActions().setLoading(true);

poseMessageFromIframe({ type: MessagePanelType.nodeSelectForce, data: currentSelect });
debouncePostMessageFromIframe({ type: MessagePanelType.nodeSelectForce, data: currentSelect });
}
}
)
Expand All @@ -89,28 +91,28 @@ export const useIframeDev = () => {
unSubscribeArray.push(
useTreeNode.subscribe(
(s) => s.hover,
() => poseMessageFromIframe({ type: MessagePanelType.nodeHover, data: useTreeNode.getReadonlyState().hover })
() => postMessageFromIframe({ type: MessagePanelType.nodeHover, data: useTreeNode.getReadonlyState().hover })
)
);

unSubscribeArray.push(
useActiveNode.subscribe(
(s) => s.state,
debounce(() => poseMessageFromIframe({ type: MessagePanelType.nodeSubscriber, data: useActiveNode.getReadonlyState().state }), 100)
debounce(() => postMessageFromIframe({ type: MessagePanelType.nodeSubscriber, data: useActiveNode.getReadonlyState().state }), 100)
)
);

unSubscribeArray.push(
useConfig.subscribe(
(s) => s.state.enableHover,
() => poseMessageFromIframe({ type: MessagePanelType.enableHover, data: useConfig.getReadonlyState().state.enableHover })
() => postMessageFromIframe({ type: MessagePanelType.enableHover, data: useConfig.getReadonlyState().state.enableHover })
)
);

unSubscribeArray.push(
useConfig.subscribe(
(s) => s.state.enableUpdate,
() => poseMessageFromIframe({ type: MessagePanelType.enableUpdate, data: useConfig.getReadonlyState().state.enableUpdate })
() => postMessageFromIframe({ type: MessagePanelType.enableUpdate, data: useConfig.getReadonlyState().state.enableUpdate })
)
);

Expand All @@ -120,7 +122,7 @@ export const useIframeDev = () => {
() => {
const id = useChunk.getReadonlyState().id;
if (id) {
poseMessageFromIframe({ type: MessagePanelType.chunk, data: id });
postMessageFromIframe({ type: MessagePanelType.chunk, data: id });
}
}
)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ export class DevToolCore {
this._notify({ type: DevToolMessageEnum.init, data: this._detector });
}

notifyTrigger() {
notifyTrigger = debounce(() => {
if (!this.hasEnable) return;

this._notify({ type: DevToolMessageEnum.trigger, data: this._trigger });
}
}, 100)

notifyRun = debounce(() => {
if (!this.hasEnable) return;
Expand Down

0 comments on commit 42fca8b

Please sign in to comment.