From 42fca8bd4d485542731ccbb60f02debc63408fa2 Mon Sep 17 00:00:00 2001 From: MrWangJustToDo <2711470541@qq.com> Date: Tue, 5 Nov 2024 23:33:17 +0800 Subject: [PATCH] improve --- chrome/public/bundle/detector.js | 10 +++++----- chrome/public/bundle/hook.js | 10 +++++----- chrome/public/bundle/panel.js | 10 +++++----- chrome/public/bundle/proxy.js | 10 +++++----- chrome/public/bundle/service-worker.js | 10 +++++----- chrome/src/hooks/useIframeDev.ts | 24 +++++++++++++----------- packages/core/src/instance.ts | 4 ++-- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/chrome/public/bundle/detector.js b/chrome/public/bundle/detector.js index f018130..943f49e 100644 --- a/chrome/public/bundle/detector.js +++ b/chrome/public/bundle/detector.js @@ -1929,6 +1929,11 @@ this._listeners = new Set(); this._activeIds = {}; this.version = "0.0.1"; + this.notifyTrigger = debounce(function () { + if (!_this.hasEnable) + return; + _this._notify({ type: exports.DevToolMessageEnum.trigger, data: _this._trigger }); + }, 100); this.notifyRun = debounce(function () { if (!_this.hasEnable) return; @@ -2181,11 +2186,6 @@ return; this._notify({ type: exports.DevToolMessageEnum.init, data: this._detector }); }; - DevToolCore.prototype.notifyTrigger = function () { - if (!this.hasEnable) - return; - this._notify({ type: exports.DevToolMessageEnum.trigger, data: this._trigger }); - }; DevToolCore.prototype.notifyHighlight = function (id, type) { if (!this.hasEnable) return; diff --git a/chrome/public/bundle/hook.js b/chrome/public/bundle/hook.js index 0a1e724..4986da3 100644 --- a/chrome/public/bundle/hook.js +++ b/chrome/public/bundle/hook.js @@ -2002,6 +2002,11 @@ this._listeners = new Set(); this._activeIds = {}; this.version = "0.0.1"; + this.notifyTrigger = debounce(function () { + if (!_this.hasEnable) + return; + _this._notify({ type: exports.DevToolMessageEnum.trigger, data: _this._trigger }); + }, 100); this.notifyRun = debounce(function () { if (!_this.hasEnable) return; @@ -2254,11 +2259,6 @@ return; this._notify({ type: exports.DevToolMessageEnum.init, data: this._detector }); }; - DevToolCore.prototype.notifyTrigger = function () { - if (!this.hasEnable) - return; - this._notify({ type: exports.DevToolMessageEnum.trigger, data: this._trigger }); - }; DevToolCore.prototype.notifyHighlight = function (id, type) { if (!this.hasEnable) return; diff --git a/chrome/public/bundle/panel.js b/chrome/public/bundle/panel.js index 4cfca78..2f11514 100644 --- a/chrome/public/bundle/panel.js +++ b/chrome/public/bundle/panel.js @@ -2000,6 +2000,11 @@ this._listeners = new Set(); this._activeIds = {}; this.version = "0.0.1"; + this.notifyTrigger = debounce(function () { + if (!_this.hasEnable) + return; + _this._notify({ type: exports.DevToolMessageEnum.trigger, data: _this._trigger }); + }, 100); this.notifyRun = debounce(function () { if (!_this.hasEnable) return; @@ -2252,11 +2257,6 @@ return; this._notify({ type: exports.DevToolMessageEnum.init, data: this._detector }); }; - DevToolCore.prototype.notifyTrigger = function () { - if (!this.hasEnable) - return; - this._notify({ type: exports.DevToolMessageEnum.trigger, data: this._trigger }); - }; DevToolCore.prototype.notifyHighlight = function (id, type) { if (!this.hasEnable) return; diff --git a/chrome/public/bundle/proxy.js b/chrome/public/bundle/proxy.js index 9075b92..a841ccf 100644 --- a/chrome/public/bundle/proxy.js +++ b/chrome/public/bundle/proxy.js @@ -1929,6 +1929,11 @@ this._listeners = new Set(); this._activeIds = {}; this.version = "0.0.1"; + this.notifyTrigger = debounce(function () { + if (!_this.hasEnable) + return; + _this._notify({ type: exports.DevToolMessageEnum.trigger, data: _this._trigger }); + }, 100); this.notifyRun = debounce(function () { if (!_this.hasEnable) return; @@ -2181,11 +2186,6 @@ return; this._notify({ type: exports.DevToolMessageEnum.init, data: this._detector }); }; - DevToolCore.prototype.notifyTrigger = function () { - if (!this.hasEnable) - return; - this._notify({ type: exports.DevToolMessageEnum.trigger, data: this._trigger }); - }; DevToolCore.prototype.notifyHighlight = function (id, type) { if (!this.hasEnable) return; diff --git a/chrome/public/bundle/service-worker.js b/chrome/public/bundle/service-worker.js index 84be9ce..86fda63 100644 --- a/chrome/public/bundle/service-worker.js +++ b/chrome/public/bundle/service-worker.js @@ -1929,6 +1929,11 @@ this._listeners = new Set(); this._activeIds = {}; this.version = "0.0.1"; + this.notifyTrigger = debounce(function () { + if (!_this.hasEnable) + return; + _this._notify({ type: exports.DevToolMessageEnum.trigger, data: _this._trigger }); + }, 100); this.notifyRun = debounce(function () { if (!_this.hasEnable) return; @@ -2181,11 +2186,6 @@ return; this._notify({ type: exports.DevToolMessageEnum.init, data: this._detector }); }; - DevToolCore.prototype.notifyTrigger = function () { - if (!this.hasEnable) - return; - this._notify({ type: exports.DevToolMessageEnum.trigger, data: this._trigger }); - }; DevToolCore.prototype.notifyHighlight = function (id, type) { if (!this.hasEnable) return; diff --git a/chrome/src/hooks/useIframeDev.ts b/chrome/src/hooks/useIframeDev.ts index ac00177..0fade65 100644 --- a/chrome/src/hooks/useIframeDev.ts +++ b/chrome/src/hooks/useIframeDev.ts @@ -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; @@ -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); } @@ -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 }); } } ) @@ -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 }); } } ) @@ -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 }) ) ); @@ -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 }); } } ) diff --git a/packages/core/src/instance.ts b/packages/core/src/instance.ts index d4d460d..21e264a 100644 --- a/packages/core/src/instance.ts +++ b/packages/core/src/instance.ts @@ -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;