From 80ca0db9c351b5e6021fb5a59c388a84d7892a2b Mon Sep 17 00:00:00 2001 From: * <8> Date: Fri, 2 Dec 2022 18:59:38 +0800 Subject: [PATCH] Match-id-e80343297e5402927e0e2a30fa19743f685f1c2c --- libs/horizon/src/horizonx/devtools/index.ts | 26 ++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/libs/horizon/src/horizonx/devtools/index.ts b/libs/horizon/src/horizonx/devtools/index.ts index 7484fa88..9bb712b9 100644 --- a/libs/horizon/src/horizonx/devtools/index.ts +++ b/libs/horizon/src/horizonx/devtools/index.ts @@ -3,10 +3,12 @@ import { OBSERVED_COMPONENTS } from './constants'; const sessionId = Date.now(); +// this function is used to detect devtool connection export function isPanelActive() { return window['__HORIZON_DEV_HOOK__']; } +// serializes store and creates expanded object with baked-in containing current computed values function makeStoreSnapshot({ type, data }) { const expanded = {}; Object.keys(data.store.$c).forEach(key => { @@ -21,6 +23,7 @@ function makeStoreSnapshot({ type, data }) { return snapshot; } +// safely serializes variables containing values wrapped in Proxy object function makeProxySnapshot(obj) { let clone; try { @@ -47,10 +50,13 @@ function makeProxySnapshot(obj) { } export const devtools = { + // returns vNode id from horizon devtools getVNodeId: vNode => { if (!isPanelActive()) return; - getVNodeId(vNode); + window['__HORIZON_DEV_HOOK__'].send(); // update list first + return window['__HORIZON_DEV_HOOK__'].getVnodeId(vNode); }, + // sends horizonx devtool message to extension emit: (type, data) => { if (!isPanelActive()) return; window.postMessage({ @@ -61,6 +67,7 @@ export const devtools = { }, }; +// collects components that are dependant on horizonx store and their ids function getAffectedComponents() { const allStores = getAllStores(); const keys = Object.keys(allStores); @@ -87,6 +94,7 @@ function getAffectedComponents() { return res; } +// listens to messages from background window.addEventListener('message', messageEvent => { if (messageEvent.data.payload.type === 'horizonx request observed components') { // get observed components @@ -99,19 +107,5 @@ window.addEventListener('message', messageEvent => { }, 100); } - if (messageEvent.data.payload.type === 'horizonx executue action') { - const data = messageEvent.data.payload.data; - const store = getStore(data.storeId); - if (!store?.[data.action]) { - } - - const action = store[data.action]; - const params = data.params; - action(...params).bind(store); - } + }); - -export function getVNodeId(vNode) { - window['__HORIZON_DEV_HOOK__'].send(); - return window['__HORIZON_DEV_HOOK__'].getVnodeId(vNode); -}