Match-id-e80343297e5402927e0e2a30fa19743f685f1c2c
This commit is contained in:
parent
fc38d038d8
commit
80ca0db9c3
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue