@solid-devtools/debugger
Advanced tools
| // src/primitives.ts | ||
| import { createEffect, onCleanup as onCleanup2, untrack } from "solid-js"; | ||
| import { throttle } from "@solid-primitives/scheduled"; | ||
| // ../shared/graph.ts | ||
| import { getOwner as _getOwner } from "solid-js"; | ||
| var getOwner = _getOwner; | ||
| // ../shared/messanger.ts | ||
| import { isServer } from "@solid-primitives/utils"; | ||
| // src/batchUpdates.ts | ||
| import { onCleanup } from "solid-js"; | ||
| import { chain, createMicrotask } from "@solid-primitives/utils"; | ||
| var updateBatchQueue = []; | ||
| var batchUpdateListeners = /* @__PURE__ */ new Set(); | ||
| var callBatchUpdateListeners = chain(batchUpdateListeners); | ||
| var emitBatchUpdates = createMicrotask(() => { | ||
| callBatchUpdateListeners([...updateBatchQueue]); | ||
| updateBatchQueue = []; | ||
| }); | ||
| function batchUpdate(update) { | ||
| updateBatchQueue.push(update); | ||
| emitBatchUpdates(); | ||
| } | ||
| function makeBatchUpdateListener(listener) { | ||
| batchUpdateListeners.add(listener); | ||
| return onCleanup(() => batchUpdateListeners.delete(listener)); | ||
| } | ||
| // src/walker.ts | ||
| import { resolveElements } from "@solid-primitives/refs"; | ||
| // src/utils.ts | ||
| import { | ||
| createComputed, | ||
| createMemo, | ||
| createRoot, | ||
| createSignal, | ||
| runWithOwner | ||
| } from "solid-js"; | ||
| import { noop, warn } from "@solid-primitives/utils"; | ||
| // ../shared/variables.ts | ||
| var WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore"; | ||
| var UNNAMED = "(unnamed)"; | ||
| var INTERNAL = Symbol("internal"); | ||
| // ../shared/utils.ts | ||
| function trimString(str, maxLength) { | ||
| if (str.length <= maxLength) | ||
| return str; | ||
| return str.slice(0, maxLength) + "\u2026"; | ||
| } | ||
| // src/utils.ts | ||
| var isSolidComputation = (o) => "fn" in o; | ||
| var isSolidMemo = (o) => _isMemo(o); | ||
| var isSolidOwner = (o) => "owned" in o; | ||
| var isSolidRoot = (o) => o.sdtType === 7 /* Root */ || !isSolidComputation(o); | ||
| var _isComponent = (o) => "componentName" in o; | ||
| var _isMemo = (o) => "value" in o && "comparator" in o && o.pure === true; | ||
| var fnMatchesRefresh = (fn) => (fn + "").replace(/[\n\t]/g, "").replace(/ +/g, " ") === "() => { const c = source(); if (c) { return untrack(() => c(props)); } return undefined; }"; | ||
| function getOwnerName(owner) { | ||
| const { name, componentName: component } = owner; | ||
| if (component && typeof component === "string") | ||
| return component.startsWith("_Hot$$") ? component.slice(6) : component; | ||
| return name || UNNAMED; | ||
| } | ||
| function getSignalName(signal) { | ||
| return signal.name || UNNAMED; | ||
| } | ||
| function getNodeName(o) { | ||
| const name = isSolidOwner(o) ? getOwnerName(o) : getSignalName(o); | ||
| return trimString(name, 20); | ||
| } | ||
| function getNodeType(o) { | ||
| if (isSolidOwner(o)) | ||
| return getOwnerType(o); | ||
| return 6 /* Signal */; | ||
| } | ||
| var getOwnerType = (o) => { | ||
| if (typeof o.sdtType !== "undefined") | ||
| return o.sdtType; | ||
| if (!isSolidComputation(o)) | ||
| return 7 /* Root */; | ||
| if (_isComponent(o)) | ||
| return 0 /* Component */; | ||
| if (isSolidMemo(o)) { | ||
| if (fnMatchesRefresh(o.fn)) | ||
| return 5 /* Refresh */; | ||
| return 3 /* Memo */; | ||
| } | ||
| if (o.pure === false) { | ||
| if (o.user === true) | ||
| return 1 /* Effect */; | ||
| return 2 /* Render */; | ||
| } | ||
| return 4 /* Computation */; | ||
| }; | ||
| var literalTypes = ["bigint", "number", "boolean", "string", "undefined"]; | ||
| function getSafeValue(value) { | ||
| if (literalTypes.includes(typeof value)) | ||
| return value; | ||
| return value + ""; | ||
| } | ||
| function lookupOwner(owner, predicate) { | ||
| do { | ||
| if (predicate(owner)) | ||
| return owner; | ||
| owner = owner.owner; | ||
| } while (owner.owner); | ||
| return null; | ||
| } | ||
| function setDebuggerContext(owner, ctx) { | ||
| owner.sdtContext = ctx; | ||
| } | ||
| function getDebuggerContext(owner) { | ||
| while (!owner.sdtContext && owner.owner) | ||
| owner = owner.owner; | ||
| return owner.sdtContext; | ||
| } | ||
| function removeDebuggerContext(owner) { | ||
| delete owner.sdtContext; | ||
| } | ||
| function onOwnerCleanup(owner, fn, prepend = false) { | ||
| if (owner.cleanups === null) | ||
| owner.cleanups = [fn]; | ||
| else if (prepend) | ||
| owner.cleanups.splice(0, 0, fn); | ||
| else | ||
| owner.cleanups.push(fn); | ||
| return () => { | ||
| var _a; | ||
| return (_a = owner.cleanups) == null ? void 0 : _a.splice(owner.cleanups.indexOf(fn), 1); | ||
| }; | ||
| } | ||
| function onParentCleanup(owner, fn, prepend = false) { | ||
| if (owner.owner) | ||
| return onOwnerCleanup(owner.owner, fn, prepend); | ||
| return noop; | ||
| } | ||
| var DISPOSE_ID = Symbol("Dispose ID"); | ||
| function createUnownedRoot(fn) { | ||
| return runWithOwner(null, () => createRoot(fn)); | ||
| } | ||
| function getFunctionSources(fn) { | ||
| let nodes; | ||
| let init = true; | ||
| runWithOwner( | ||
| null, | ||
| () => createRoot( | ||
| (dispose) => createComputed(() => { | ||
| if (!init) | ||
| return; | ||
| init = false; | ||
| fn(); | ||
| const sources = getOwner().sources; | ||
| if (sources) | ||
| nodes = [...sources]; | ||
| dispose(); | ||
| }) | ||
| ) | ||
| ); | ||
| return nodes ?? []; | ||
| } | ||
| var LAST_ID = 0; | ||
| var getNewSdtId = () => LAST_ID++; | ||
| function markOwnerType(o, type) { | ||
| if (o.sdtType !== void 0) | ||
| return o.sdtType; | ||
| else | ||
| return o.sdtType = type ?? getOwnerType(o); | ||
| } | ||
| function markNodeID(o) { | ||
| if (o.sdtId !== void 0) | ||
| return o.sdtId; | ||
| else | ||
| return o.sdtId = getNewSdtId(); | ||
| } | ||
| function markNodesID(nodes) { | ||
| if (!nodes || !nodes.length) | ||
| return []; | ||
| return nodes.map(markNodeID); | ||
| } | ||
| function addRootToOwnedRoots(parent, root) { | ||
| const ownedRoots = parent.ownedRoots ?? (parent.ownedRoots = /* @__PURE__ */ new Set()); | ||
| ownedRoots.add(root); | ||
| return () => void ownedRoots.delete(root); | ||
| } | ||
| function createConsumers() { | ||
| const [consumers, setConsumers] = createSignal([], { name: "consumers" }); | ||
| const enabled2 = createMemo(() => consumers().some((consumer) => consumer())); | ||
| return [enabled2, (consumer) => setConsumers((p) => [...p, consumer])]; | ||
| } | ||
| var SkipInternalRoot = null; | ||
| function createInternalRoot(fn, detachedOwner) { | ||
| SkipInternalRoot = fn; | ||
| const v = createRoot((dispose) => { | ||
| const owner = getOwner(); | ||
| setDebuggerContext(owner, INTERNAL); | ||
| return fn(dispose); | ||
| }, detachedOwner); | ||
| if (SkipInternalRoot === fn) | ||
| SkipInternalRoot = null; | ||
| return v; | ||
| } | ||
| var skipInternalRoot = () => { | ||
| const skip = !!SkipInternalRoot; | ||
| if (skip) | ||
| SkipInternalRoot = null; | ||
| return skip; | ||
| }; | ||
| // src/update.ts | ||
| import { noop as noop2, onRootCleanup } from "@solid-primitives/utils"; | ||
| import { Observable } from "object-observer"; | ||
| var GraphUpdateListeners = /* @__PURE__ */ new Set(); | ||
| { | ||
| const runListeners = () => GraphUpdateListeners.forEach((f) => f()); | ||
| if (typeof window._$afterUpdate === "function") { | ||
| GraphUpdateListeners.add(window._$afterUpdate); | ||
| } | ||
| window._$afterUpdate = runListeners; | ||
| } | ||
| function makeSolidUpdateListener(onUpdate2) { | ||
| GraphUpdateListeners.add(onUpdate2); | ||
| return onRootCleanup(() => { | ||
| GraphUpdateListeners.delete(onUpdate2); | ||
| }); | ||
| } | ||
| var CreateRootListeners = /* @__PURE__ */ new Set(); | ||
| { | ||
| const runListeners = (root) => { | ||
| if (skipInternalRoot()) | ||
| return; | ||
| CreateRootListeners.forEach((f) => f(root)); | ||
| }; | ||
| if (typeof window._$afterCreateRoot === "function") { | ||
| CreateRootListeners.add(window._$afterCreateRoot); | ||
| } | ||
| window._$afterCreateRoot = runListeners; | ||
| } | ||
| function makeCreateRootListener(onUpdate2) { | ||
| CreateRootListeners.add(onUpdate2); | ||
| return onRootCleanup(() => CreateRootListeners.delete(onUpdate2)); | ||
| } | ||
| window[WINDOW_WRAP_STORE_PROPERTY] = (init) => { | ||
| return Observable.from(init); | ||
| }; | ||
| function makeStoreObserver(state, onUpdate2) { | ||
| if (!Observable.isObservable(state)) { | ||
| console.warn(`Object ${state} is not wrapped`); | ||
| return noop2; | ||
| } | ||
| Observable.observe(state, onUpdate2); | ||
| return onRootCleanup(() => Observable.unobserve(state, onUpdate2)); | ||
| } | ||
| function observeComputationUpdate(owner, onRun) { | ||
| if (owner.onComputationUpdate) | ||
| return void (owner.onComputationUpdate = onRun); | ||
| owner.onComputationUpdate = onRun; | ||
| interceptComputationRerun(owner, (fn) => { | ||
| owner.onComputationUpdate(); | ||
| fn(); | ||
| }); | ||
| } | ||
| function interceptComputationRerun(owner, onRun) { | ||
| const _fn = owner.fn; | ||
| let v; | ||
| let prev; | ||
| const fn = () => v = _fn(prev); | ||
| owner.fn = !!owner.fn.length ? (p) => { | ||
| onRun(fn, prev = p); | ||
| return v; | ||
| } : () => { | ||
| onRun(fn, void 0); | ||
| return v; | ||
| }; | ||
| } | ||
| function observeValueUpdate(node, onUpdate2, symbol) { | ||
| const remove = () => delete node.onValueUpdate[symbol]; | ||
| if (node.onValueUpdate) { | ||
| node.onValueUpdate[symbol] = onUpdate2; | ||
| return remove; | ||
| } | ||
| const map = node.onValueUpdate = { [symbol]: onUpdate2 }; | ||
| let value = node.value; | ||
| Object.defineProperty(node, "value", { | ||
| get: () => value, | ||
| set: (newValue) => { | ||
| for (let sym of Object.getOwnPropertySymbols(map)) | ||
| map[sym](newValue, value); | ||
| value = newValue; | ||
| } | ||
| }); | ||
| return remove; | ||
| } | ||
| // src/walker.ts | ||
| var RootID; | ||
| var OnSignalUpdate; | ||
| var OnComputationUpdate; | ||
| var TrackSignals; | ||
| var TrackBatchedUpdates; | ||
| var TrackComponents; | ||
| var Components = []; | ||
| var WALKER = Symbol("walker"); | ||
| function observeComputation(owner, id) { | ||
| if (TrackBatchedUpdates && isSolidComputation(owner)) | ||
| observeComputationUpdate(owner, OnComputationUpdate.bind(void 0, id)); | ||
| } | ||
| function observeValue(node, id) { | ||
| const handler = OnSignalUpdate; | ||
| if (TrackBatchedUpdates) | ||
| observeValueUpdate(node, (value, oldValue) => handler({ id, value, oldValue }), WALKER); | ||
| } | ||
| function createSignalNode(raw) { | ||
| return { | ||
| name: raw.name ?? "(anonymous)", | ||
| id: raw.id, | ||
| observers: markNodesID(raw.observers), | ||
| value: getSafeValue(raw.value) | ||
| }; | ||
| } | ||
| function mapOwnerSignals(owner) { | ||
| if (!owner.sourceMap || !TrackSignals) | ||
| return []; | ||
| return Object.values(owner.sourceMap).map((raw) => { | ||
| const id = markNodeID(raw); | ||
| observeValue(raw, id); | ||
| return createSignalNode({ ...raw, id }); | ||
| }); | ||
| } | ||
| function mapMemo(mapped, owner) { | ||
| const { id, name } = mapped; | ||
| observeValue(owner, id); | ||
| return Object.assign(mapped, { | ||
| signal: createSignalNode({ id, name, value: owner.value, observers: owner.observers }) | ||
| }); | ||
| } | ||
| function mapOwner(owner, type) { | ||
| type = markOwnerType(owner, type); | ||
| const id = markNodeID(owner); | ||
| const name = getNodeName(owner); | ||
| observeComputation(owner, id); | ||
| if (type === 0 /* Component */ && TrackComponents) { | ||
| const resolved = resolveElements(owner.value); | ||
| if (resolved) | ||
| Components.push({ name, resolved }); | ||
| } | ||
| const mapped = { | ||
| id, | ||
| name, | ||
| type, | ||
| signals: mapOwnerSignals(owner), | ||
| children: mapChildren(owner), | ||
| sources: markNodesID(owner.sources) | ||
| }; | ||
| return type === 3 /* Memo */ ? mapMemo(mapped, owner) : mapped; | ||
| } | ||
| function mapChildren({ owned, ownedRoots }) { | ||
| const children = []; | ||
| if (owned) | ||
| children.push.apply( | ||
| children, | ||
| owned.map((child) => mapOwner(child)) | ||
| ); | ||
| if (ownedRoots) | ||
| children.push.apply( | ||
| children, | ||
| [...ownedRoots].map((child) => mapOwner(child, 7 /* Root */)) | ||
| ); | ||
| return children; | ||
| } | ||
| function walkSolidTree(owner, config) { | ||
| RootID = config.rootId; | ||
| OnSignalUpdate = config.onSignalUpdate; | ||
| OnComputationUpdate = config.onComputationUpdate; | ||
| TrackSignals = config.trackSignals; | ||
| TrackBatchedUpdates = config.trackBatchedUpdates; | ||
| TrackComponents = config.trackComponents; | ||
| if (TrackComponents) | ||
| Components = []; | ||
| return { tree: mapOwner(owner), components: Components }; | ||
| } | ||
| // src/plugin.ts | ||
| import { createSignal as createSignal2, getOwner as getOwner2, runWithOwner as runWithOwner2 } from "solid-js"; | ||
| import { createSimpleEmitter } from "@solid-primitives/event-bus"; | ||
| import { push, splice } from "@solid-primitives/immutable"; | ||
| import { createLazyMemo } from "@solid-primitives/memo"; | ||
| var api = createInternalRoot(() => { | ||
| const owner = getOwner2(); | ||
| const [onUpdate2, triggerUpdate2] = createSimpleEmitter(); | ||
| const [onForceUpdate2, forceTriggerUpdate2] = createSimpleEmitter(); | ||
| const [enabled2, addDebuggerConsumer] = createConsumers(); | ||
| const [trackSignals, addTrackSignalsConsumer] = createConsumers(); | ||
| const [trackBatchedUpdates, addTrackBatchedUpdatesConsumer] = createConsumers(); | ||
| const [trackComponents, addTrackComponentsConsumer] = createConsumers(); | ||
| const [roots2, setRoots2] = createSignal2([]); | ||
| const components = createLazyMemo( | ||
| () => roots2().reduce((arr, root) => { | ||
| arr.push.apply(arr, root.components); | ||
| return arr; | ||
| }, []) | ||
| ); | ||
| const serialisedRoots = createLazyMemo( | ||
| () => roots2().map((root) => ({ | ||
| id: root.id, | ||
| tree: root.tree | ||
| })) | ||
| ); | ||
| const debuggerConfig2 = { | ||
| get enabled() { | ||
| return enabled2(); | ||
| }, | ||
| get trackSignals() { | ||
| return trackSignals(); | ||
| }, | ||
| get trackBatchedUpdates() { | ||
| return trackBatchedUpdates(); | ||
| }, | ||
| get trackComponents() { | ||
| return trackComponents(); | ||
| } | ||
| }; | ||
| function registerDebuggerPlugin2(factory) { | ||
| runWithOwner2(owner, () => { | ||
| const { enabled: enabled3, trackBatchedUpdates: trackBatchedUpdates2, trackComponents: trackComponents2, trackSignals: trackSignals2 } = factory({ | ||
| makeBatchUpdateListener, | ||
| roots: roots2, | ||
| components, | ||
| triggerUpdate: triggerUpdate2, | ||
| forceTriggerUpdate: forceTriggerUpdate2, | ||
| serialisedRoots | ||
| }); | ||
| enabled3 && addDebuggerConsumer(enabled3); | ||
| trackBatchedUpdates2 && addTrackBatchedUpdatesConsumer(trackBatchedUpdates2); | ||
| trackComponents2 && addTrackComponentsConsumer(trackComponents2); | ||
| trackSignals2 && addTrackSignalsConsumer(trackSignals2); | ||
| }); | ||
| } | ||
| return { | ||
| onUpdate: onUpdate2, | ||
| onForceUpdate: onForceUpdate2, | ||
| triggerUpdate: triggerUpdate2, | ||
| forceTriggerUpdate: forceTriggerUpdate2, | ||
| enabled: enabled2, | ||
| debuggerConfig: debuggerConfig2, | ||
| roots: roots2, | ||
| setRoots: setRoots2, | ||
| registerDebuggerPlugin: registerDebuggerPlugin2, | ||
| updateRoot(root) { | ||
| setRoots2((arr) => { | ||
| const index = arr.findIndex((o) => o.id === root.id); | ||
| return index !== -1 ? splice(arr, index, 1, root) : push(arr, root); | ||
| }); | ||
| }, | ||
| removeRoot(rootId) { | ||
| setRoots2((arr) => { | ||
| const index = arr.findIndex((o) => o.id === rootId); | ||
| return splice(arr, index, 1); | ||
| }); | ||
| } | ||
| }; | ||
| }); | ||
| var { | ||
| onUpdate, | ||
| onForceUpdate, | ||
| triggerUpdate, | ||
| forceTriggerUpdate, | ||
| enabled, | ||
| debuggerConfig, | ||
| roots, | ||
| setRoots, | ||
| registerDebuggerPlugin, | ||
| updateRoot, | ||
| removeRoot | ||
| } = api; | ||
| // src/primitives.ts | ||
| function createGraphRoot(owner) { | ||
| createInternalRoot((dispose) => { | ||
| onOwnerCleanup(owner, dispose); | ||
| const rootId = getNewSdtId(); | ||
| const onComputationUpdate = (payload) => { | ||
| if (!debuggerConfig.trackBatchedUpdates || owner.isDisposed) | ||
| return; | ||
| if (enabled()) | ||
| triggerRootUpdate(); | ||
| batchUpdate({ type: 1 /* Computation */, payload }); | ||
| }; | ||
| const onSignalUpdate = (payload) => { | ||
| if (!debuggerConfig.trackBatchedUpdates || owner.isDisposed) | ||
| return; | ||
| batchUpdate({ type: 0 /* Signal */, payload }); | ||
| }; | ||
| const forceRootUpdate = () => { | ||
| if (owner.isDisposed) | ||
| return; | ||
| const { tree, components } = untrack( | ||
| walkSolidTree.bind(void 0, owner, { | ||
| ...debuggerConfig, | ||
| onComputationUpdate, | ||
| onSignalUpdate, | ||
| rootId | ||
| }) | ||
| ); | ||
| updateRoot({ id: rootId, tree, components }); | ||
| }; | ||
| const triggerRootUpdate = throttle(forceRootUpdate, 350); | ||
| onUpdate(triggerRootUpdate); | ||
| onForceUpdate(forceRootUpdate); | ||
| createEffect(() => enabled() && forceRootUpdate()); | ||
| setDebuggerContext(owner, { rootId, triggerRootUpdate, forceRootUpdate }); | ||
| onCleanup2(() => { | ||
| removeDebuggerContext(owner); | ||
| removeRoot(rootId); | ||
| owner.isDisposed = true; | ||
| }); | ||
| }); | ||
| } | ||
| function attachDebugger(_owner = getOwner()) { | ||
| let owner = _owner; | ||
| if (!owner) | ||
| return console.warn( | ||
| "reatachOwner helper should be used synchronously inside createRoot callback body." | ||
| ); | ||
| forEachLookupRoot(owner, (root, ctx) => { | ||
| root.sdtAttached = true; | ||
| markOwnerType(root, 7 /* Root */); | ||
| if (ctx === INTERNAL) | ||
| return; | ||
| if (ctx) { | ||
| ctx.triggerRootUpdate(); | ||
| let parent = findClosestAliveParent(root); | ||
| if (!parent.owner) | ||
| return console.warn("PARENT_SHOULD_BE_ALIVE"); | ||
| let removeFromOwned = addRootToOwnedRoots(parent.owner, root); | ||
| const onParentCleanup2 = () => { | ||
| const newParent = findClosestAliveParent(root); | ||
| if (newParent.owner) { | ||
| parent = newParent; | ||
| removeFromOwned(); | ||
| removeFromOwned = addRootToOwnedRoots(parent.owner, root); | ||
| onOwnerCleanup(parent.root, onParentCleanup2); | ||
| } else { | ||
| removeFromOwned(); | ||
| removeOwnCleanup(); | ||
| createGraphRoot(root); | ||
| } | ||
| }; | ||
| const removeParentCleanup = onOwnerCleanup(parent.root, onParentCleanup2); | ||
| const removeOwnCleanup = onOwnerCleanup(root, () => { | ||
| root.isDisposed = true; | ||
| removeFromOwned(); | ||
| removeParentCleanup(); | ||
| ctx.triggerRootUpdate(); | ||
| }); | ||
| } else | ||
| createGraphRoot(root); | ||
| }); | ||
| } | ||
| function findClosestAliveParent(owner) { | ||
| let disposed = null; | ||
| let closestAliveRoot = null; | ||
| let current = owner; | ||
| while (current.owner && !closestAliveRoot) { | ||
| current = current.owner; | ||
| if (isSolidRoot(current)) { | ||
| if (current.isDisposed) | ||
| disposed = current; | ||
| else | ||
| closestAliveRoot = current; | ||
| } | ||
| } | ||
| if (!closestAliveRoot) | ||
| return { owner: null, root: null }; | ||
| return { owner: (disposed == null ? void 0 : disposed.owner) ?? owner.owner, root: closestAliveRoot }; | ||
| } | ||
| function forEachLookupRoot(owner, callback) { | ||
| const roots2 = []; | ||
| let ctx; | ||
| do { | ||
| if (isSolidRoot(owner)) { | ||
| if (owner.sdtAttached) { | ||
| if (!ctx) | ||
| ctx = getDebuggerContext(owner); | ||
| break; | ||
| } | ||
| if (owner.sdtContext === INTERNAL) { | ||
| ctx = INTERNAL; | ||
| break; | ||
| } | ||
| roots2.push(owner); | ||
| } | ||
| owner = owner.owner; | ||
| } while (owner); | ||
| for (let i = roots2.length - 1; i >= 0; i--) { | ||
| const root = roots2[i]; | ||
| callback(root, ctx); | ||
| if (root.sdtContext) | ||
| ctx = root.sdtContext; | ||
| } | ||
| } | ||
| // src/index.ts | ||
| var Debugger = (props) => { | ||
| attachDebugger(); | ||
| return props.children; | ||
| }; | ||
| export { | ||
| UNNAMED, | ||
| isSolidComputation, | ||
| isSolidMemo, | ||
| isSolidOwner, | ||
| isSolidRoot, | ||
| getNodeName, | ||
| getNodeType, | ||
| getOwnerType, | ||
| getSafeValue, | ||
| lookupOwner, | ||
| onOwnerCleanup, | ||
| onParentCleanup, | ||
| createUnownedRoot, | ||
| getFunctionSources, | ||
| createInternalRoot, | ||
| makeSolidUpdateListener, | ||
| makeCreateRootListener, | ||
| makeStoreObserver, | ||
| observeComputationUpdate, | ||
| interceptComputationRerun, | ||
| observeValueUpdate, | ||
| registerDebuggerPlugin, | ||
| attachDebugger, | ||
| Debugger | ||
| }; |
+28
-15
@@ -40,2 +40,3 @@ "use strict"; | ||
| makeSolidUpdateListener: () => makeSolidUpdateListener, | ||
| makeStoreObserver: () => makeStoreObserver, | ||
| observeComputationUpdate: () => observeComputationUpdate, | ||
@@ -50,3 +51,3 @@ observeValueUpdate: () => observeValueUpdate, | ||
| // src/primitives.ts | ||
| var import_solid_js6 = require("solid-js"); | ||
| var import_solid_js5 = require("solid-js"); | ||
| var import_scheduled = require("@solid-primitives/scheduled"); | ||
@@ -88,2 +89,3 @@ | ||
| // ../shared/variables.ts | ||
| var WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore"; | ||
| var UNNAMED = "(unnamed)"; | ||
@@ -259,3 +261,4 @@ var INTERNAL = Symbol("internal"); | ||
| // src/update.ts | ||
| var import_solid_js4 = require("solid-js"); | ||
| var import_utils5 = require("@solid-primitives/utils"); | ||
| var import_object_observer = require("object-observer"); | ||
| var GraphUpdateListeners = /* @__PURE__ */ new Set(); | ||
@@ -271,5 +274,5 @@ { | ||
| GraphUpdateListeners.add(onUpdate2); | ||
| const unsub = () => GraphUpdateListeners.delete(onUpdate2); | ||
| getOwner() && (0, import_solid_js4.onCleanup)(unsub); | ||
| return unsub; | ||
| return (0, import_utils5.onRootCleanup)(() => { | ||
| GraphUpdateListeners.delete(onUpdate2); | ||
| }); | ||
| } | ||
@@ -290,6 +293,15 @@ var CreateRootListeners = /* @__PURE__ */ new Set(); | ||
| CreateRootListeners.add(onUpdate2); | ||
| const unsub = () => CreateRootListeners.delete(onUpdate2); | ||
| getOwner() && (0, import_solid_js4.onCleanup)(unsub); | ||
| return unsub; | ||
| return (0, import_utils5.onRootCleanup)(() => CreateRootListeners.delete(onUpdate2)); | ||
| } | ||
| window[WINDOW_WRAP_STORE_PROPERTY] = (init) => { | ||
| return import_object_observer.Observable.from(init); | ||
| }; | ||
| function makeStoreObserver(state, onUpdate2) { | ||
| if (!import_object_observer.Observable.isObservable(state)) { | ||
| console.warn(`Object ${state} is not wrapped`); | ||
| return import_utils5.noop; | ||
| } | ||
| import_object_observer.Observable.observe(state, onUpdate2); | ||
| return (0, import_utils5.onRootCleanup)(() => import_object_observer.Observable.unobserve(state, onUpdate2)); | ||
| } | ||
| function observeComputationUpdate(owner, onRun) { | ||
@@ -425,3 +437,3 @@ if (owner.onComputationUpdate) | ||
| // src/plugin.ts | ||
| var import_solid_js5 = require("solid-js"); | ||
| var import_solid_js4 = require("solid-js"); | ||
| var import_event_bus = require("@solid-primitives/event-bus"); | ||
@@ -431,3 +443,3 @@ var import_immutable = require("@solid-primitives/immutable"); | ||
| var api = createInternalRoot(() => { | ||
| const owner = (0, import_solid_js5.getOwner)(); | ||
| const owner = (0, import_solid_js4.getOwner)(); | ||
| const [onUpdate2, triggerUpdate2] = (0, import_event_bus.createSimpleEmitter)(); | ||
@@ -439,3 +451,3 @@ const [onForceUpdate2, forceTriggerUpdate2] = (0, import_event_bus.createSimpleEmitter)(); | ||
| const [trackComponents, addTrackComponentsConsumer] = createConsumers(); | ||
| const [roots2, setRoots2] = (0, import_solid_js5.createSignal)([]); | ||
| const [roots2, setRoots2] = (0, import_solid_js4.createSignal)([]); | ||
| const components = (0, import_memo.createLazyMemo)( | ||
@@ -468,3 +480,3 @@ () => roots2().reduce((arr, root) => { | ||
| function registerDebuggerPlugin2(factory) { | ||
| (0, import_solid_js5.runWithOwner)(owner, () => { | ||
| (0, import_solid_js4.runWithOwner)(owner, () => { | ||
| const { enabled: enabled3, trackBatchedUpdates: trackBatchedUpdates2, trackComponents: trackComponents2, trackSignals: trackSignals2 } = factory({ | ||
@@ -542,3 +554,3 @@ makeBatchUpdateListener, | ||
| return; | ||
| const { tree, components } = (0, import_solid_js6.untrack)( | ||
| const { tree, components } = (0, import_solid_js5.untrack)( | ||
| walkSolidTree.bind(void 0, owner, { | ||
@@ -556,5 +568,5 @@ ...debuggerConfig, | ||
| onForceUpdate(forceRootUpdate); | ||
| (0, import_solid_js6.createEffect)(() => enabled() && forceRootUpdate()); | ||
| (0, import_solid_js5.createEffect)(() => enabled() && forceRootUpdate()); | ||
| setDebuggerContext(owner, { rootId, triggerRootUpdate, forceRootUpdate }); | ||
| (0, import_solid_js6.onCleanup)(() => { | ||
| (0, import_solid_js5.onCleanup)(() => { | ||
| removeDebuggerContext(owner); | ||
@@ -674,2 +686,3 @@ removeRoot(rootId); | ||
| makeSolidUpdateListener, | ||
| makeStoreObserver, | ||
| observeComputationUpdate, | ||
@@ -676,0 +689,0 @@ observeValueUpdate, |
+11
-1
| import { Accessor, ParentComponent } from 'solid-js'; | ||
| import { Many } from '@solid-primitives/utils'; | ||
| import * as solid_js_types_reactive_signal from 'solid-js/types/reactive/signal'; | ||
| import { Observer } from 'object-observer'; | ||
| export { Observer as ObjectObserver } from 'object-observer'; | ||
@@ -16,2 +18,3 @@ declare type SafeValue = number | null | undefined | string | boolean; | ||
| declare const WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore"; | ||
| declare const INTERNAL: unique symbol; | ||
@@ -189,2 +192,9 @@ | ||
| declare function makeCreateRootListener(onUpdate: AfterCrateRoot): VoidFunction; | ||
| declare global { | ||
| interface Window { | ||
| [WINDOW_WRAP_STORE_PROPERTY]?: <T extends object>(init: T) => T; | ||
| } | ||
| } | ||
| declare function makeStoreObserver(state: object, onUpdate: Observer): VoidFunction; | ||
| /** | ||
@@ -243,2 +253,2 @@ * Wraps the fn prop of owner object to trigger handler whenever the computation is executed. | ||
| export { AfterCrateRoot, Debugger, PluginFactory, TargetIDE, TargetURLFunction, attachDebugger, createInternalRoot, createUnownedRoot, getFunctionSources, getNodeName, getNodeType, getOwnerType, getSafeValue, interceptComputationRerun, isSolidComputation, isSolidMemo, isSolidOwner, isSolidRoot, lookupOwner, makeCreateRootListener, makeSolidUpdateListener, observeComputationUpdate, observeValueUpdate, onOwnerCleanup, onParentCleanup, registerDebuggerPlugin }; | ||
| export { AfterCrateRoot, Debugger, PluginFactory, TargetIDE, TargetURLFunction, attachDebugger, createInternalRoot, createUnownedRoot, getFunctionSources, getNodeName, getNodeType, getOwnerType, getSafeValue, interceptComputationRerun, isSolidComputation, isSolidMemo, isSolidOwner, isSolidRoot, lookupOwner, makeCreateRootListener, makeSolidUpdateListener, makeStoreObserver, observeComputationUpdate, observeValueUpdate, onOwnerCleanup, onParentCleanup, registerDebuggerPlugin }; |
+3
-1
@@ -19,2 +19,3 @@ import { | ||
| makeSolidUpdateListener, | ||
| makeStoreObserver, | ||
| observeComputationUpdate, | ||
@@ -25,3 +26,3 @@ observeValueUpdate, | ||
| registerDebuggerPlugin | ||
| } from "./chunk-WCV7QBER.js"; | ||
| } from "./chunk-XVGGDZNY.js"; | ||
| export { | ||
@@ -45,2 +46,3 @@ Debugger, | ||
| makeSolidUpdateListener, | ||
| makeStoreObserver, | ||
| observeComputationUpdate, | ||
@@ -47,0 +49,0 @@ observeValueUpdate, |
+3
-0
@@ -40,2 +40,3 @@ "use strict"; | ||
| makeSolidUpdateListener: () => makeSolidUpdateListener, | ||
| makeStoreObserver: () => makeStoreObserver, | ||
| observeComputationUpdate: () => observeComputationUpdate, | ||
@@ -80,2 +81,3 @@ observeValueUpdate: () => observeValueUpdate, | ||
| var makeCreateRootListener = () => import_utils4.noop; | ||
| var makeStoreObserver = () => import_utils4.noop; | ||
| var observeComputationUpdate = import_utils4.noop; | ||
@@ -115,2 +117,3 @@ var observeValueUpdate = () => import_utils4.noop; | ||
| makeSolidUpdateListener, | ||
| makeStoreObserver, | ||
| observeComputationUpdate, | ||
@@ -117,0 +120,0 @@ observeValueUpdate, |
+3
-1
@@ -5,3 +5,3 @@ import { | ||
| getSafeValue | ||
| } from "./chunk-WCV7QBER.js"; | ||
| } from "./chunk-XVGGDZNY.js"; | ||
@@ -16,2 +16,3 @@ // src/server.ts | ||
| var makeCreateRootListener = () => noop; | ||
| var makeStoreObserver = () => noop; | ||
| var observeComputationUpdate = noop; | ||
@@ -50,2 +51,3 @@ var observeValueUpdate = () => noop; | ||
| makeSolidUpdateListener, | ||
| makeStoreObserver, | ||
| observeComputationUpdate, | ||
@@ -52,0 +54,0 @@ observeValueUpdate, |
+6
-2
| { | ||
| "name": "@solid-devtools/debugger", | ||
| "version": "0.2.3", | ||
| "version": "0.3.0", | ||
| "description": "Debugger of the Solid's reactivity graph — a cornerstone of all solid-devtools.", | ||
@@ -61,3 +61,4 @@ "license": "MIT", | ||
| "@solid-primitives/scheduled": "^1.0.0", | ||
| "@solid-primitives/utils": "^3.0.1" | ||
| "@solid-primitives/utils": "^3.0.1", | ||
| "object-observer": "^5.0.4" | ||
| }, | ||
@@ -67,2 +68,5 @@ "peerDependencies": { | ||
| }, | ||
| "optionalDependencies": { | ||
| "@solid-devtools/transform": "^0.4.0" | ||
| }, | ||
| "packageManager": "pnpm@7.7.0", | ||
@@ -69,0 +73,0 @@ "scripts": { |
| // src/primitives.ts | ||
| import { createEffect, onCleanup as onCleanup3, untrack } from "solid-js"; | ||
| import { throttle } from "@solid-primitives/scheduled"; | ||
| // ../shared/graph.ts | ||
| import { getOwner as _getOwner } from "solid-js"; | ||
| var getOwner = _getOwner; | ||
| // ../shared/messanger.ts | ||
| import { isServer } from "@solid-primitives/utils"; | ||
| // src/batchUpdates.ts | ||
| import { onCleanup } from "solid-js"; | ||
| import { chain, createMicrotask } from "@solid-primitives/utils"; | ||
| var updateBatchQueue = []; | ||
| var batchUpdateListeners = /* @__PURE__ */ new Set(); | ||
| var callBatchUpdateListeners = chain(batchUpdateListeners); | ||
| var emitBatchUpdates = createMicrotask(() => { | ||
| callBatchUpdateListeners([...updateBatchQueue]); | ||
| updateBatchQueue = []; | ||
| }); | ||
| function batchUpdate(update) { | ||
| updateBatchQueue.push(update); | ||
| emitBatchUpdates(); | ||
| } | ||
| function makeBatchUpdateListener(listener) { | ||
| batchUpdateListeners.add(listener); | ||
| return onCleanup(() => batchUpdateListeners.delete(listener)); | ||
| } | ||
| // src/walker.ts | ||
| import { resolveElements } from "@solid-primitives/refs"; | ||
| // src/utils.ts | ||
| import { | ||
| createComputed, | ||
| createMemo, | ||
| createRoot, | ||
| createSignal, | ||
| runWithOwner | ||
| } from "solid-js"; | ||
| import { noop, warn } from "@solid-primitives/utils"; | ||
| // ../shared/variables.ts | ||
| var UNNAMED = "(unnamed)"; | ||
| var INTERNAL = Symbol("internal"); | ||
| // ../shared/utils.ts | ||
| function trimString(str, maxLength) { | ||
| if (str.length <= maxLength) | ||
| return str; | ||
| return str.slice(0, maxLength) + "\u2026"; | ||
| } | ||
| // src/utils.ts | ||
| var isSolidComputation = (o) => "fn" in o; | ||
| var isSolidMemo = (o) => _isMemo(o); | ||
| var isSolidOwner = (o) => "owned" in o; | ||
| var isSolidRoot = (o) => o.sdtType === 7 /* Root */ || !isSolidComputation(o); | ||
| var _isComponent = (o) => "componentName" in o; | ||
| var _isMemo = (o) => "value" in o && "comparator" in o && o.pure === true; | ||
| var fnMatchesRefresh = (fn) => (fn + "").replace(/[\n\t]/g, "").replace(/ +/g, " ") === "() => { const c = source(); if (c) { return untrack(() => c(props)); } return undefined; }"; | ||
| function getOwnerName(owner) { | ||
| const { name, componentName: component } = owner; | ||
| if (component && typeof component === "string") | ||
| return component.startsWith("_Hot$$") ? component.slice(6) : component; | ||
| return name || UNNAMED; | ||
| } | ||
| function getSignalName(signal) { | ||
| return signal.name || UNNAMED; | ||
| } | ||
| function getNodeName(o) { | ||
| const name = isSolidOwner(o) ? getOwnerName(o) : getSignalName(o); | ||
| return trimString(name, 20); | ||
| } | ||
| function getNodeType(o) { | ||
| if (isSolidOwner(o)) | ||
| return getOwnerType(o); | ||
| return 6 /* Signal */; | ||
| } | ||
| var getOwnerType = (o) => { | ||
| if (typeof o.sdtType !== "undefined") | ||
| return o.sdtType; | ||
| if (!isSolidComputation(o)) | ||
| return 7 /* Root */; | ||
| if (_isComponent(o)) | ||
| return 0 /* Component */; | ||
| if (isSolidMemo(o)) { | ||
| if (fnMatchesRefresh(o.fn)) | ||
| return 5 /* Refresh */; | ||
| return 3 /* Memo */; | ||
| } | ||
| if (o.pure === false) { | ||
| if (o.user === true) | ||
| return 1 /* Effect */; | ||
| return 2 /* Render */; | ||
| } | ||
| return 4 /* Computation */; | ||
| }; | ||
| var literalTypes = ["bigint", "number", "boolean", "string", "undefined"]; | ||
| function getSafeValue(value) { | ||
| if (literalTypes.includes(typeof value)) | ||
| return value; | ||
| return value + ""; | ||
| } | ||
| function lookupOwner(owner, predicate) { | ||
| do { | ||
| if (predicate(owner)) | ||
| return owner; | ||
| owner = owner.owner; | ||
| } while (owner.owner); | ||
| return null; | ||
| } | ||
| function setDebuggerContext(owner, ctx) { | ||
| owner.sdtContext = ctx; | ||
| } | ||
| function getDebuggerContext(owner) { | ||
| while (!owner.sdtContext && owner.owner) | ||
| owner = owner.owner; | ||
| return owner.sdtContext; | ||
| } | ||
| function removeDebuggerContext(owner) { | ||
| delete owner.sdtContext; | ||
| } | ||
| function onOwnerCleanup(owner, fn, prepend = false) { | ||
| if (owner.cleanups === null) | ||
| owner.cleanups = [fn]; | ||
| else if (prepend) | ||
| owner.cleanups.splice(0, 0, fn); | ||
| else | ||
| owner.cleanups.push(fn); | ||
| return () => { | ||
| var _a; | ||
| return (_a = owner.cleanups) == null ? void 0 : _a.splice(owner.cleanups.indexOf(fn), 1); | ||
| }; | ||
| } | ||
| function onParentCleanup(owner, fn, prepend = false) { | ||
| if (owner.owner) | ||
| return onOwnerCleanup(owner.owner, fn, prepend); | ||
| return noop; | ||
| } | ||
| var DISPOSE_ID = Symbol("Dispose ID"); | ||
| function createUnownedRoot(fn) { | ||
| return runWithOwner(null, () => createRoot(fn)); | ||
| } | ||
| function getFunctionSources(fn) { | ||
| let nodes; | ||
| let init = true; | ||
| runWithOwner( | ||
| null, | ||
| () => createRoot( | ||
| (dispose) => createComputed(() => { | ||
| if (!init) | ||
| return; | ||
| init = false; | ||
| fn(); | ||
| const sources = getOwner().sources; | ||
| if (sources) | ||
| nodes = [...sources]; | ||
| dispose(); | ||
| }) | ||
| ) | ||
| ); | ||
| return nodes ?? []; | ||
| } | ||
| var LAST_ID = 0; | ||
| var getNewSdtId = () => LAST_ID++; | ||
| function markOwnerType(o, type) { | ||
| if (o.sdtType !== void 0) | ||
| return o.sdtType; | ||
| else | ||
| return o.sdtType = type ?? getOwnerType(o); | ||
| } | ||
| function markNodeID(o) { | ||
| if (o.sdtId !== void 0) | ||
| return o.sdtId; | ||
| else | ||
| return o.sdtId = getNewSdtId(); | ||
| } | ||
| function markNodesID(nodes) { | ||
| if (!nodes || !nodes.length) | ||
| return []; | ||
| return nodes.map(markNodeID); | ||
| } | ||
| function addRootToOwnedRoots(parent, root) { | ||
| const ownedRoots = parent.ownedRoots ?? (parent.ownedRoots = /* @__PURE__ */ new Set()); | ||
| ownedRoots.add(root); | ||
| return () => void ownedRoots.delete(root); | ||
| } | ||
| function createConsumers() { | ||
| const [consumers, setConsumers] = createSignal([], { name: "consumers" }); | ||
| const enabled2 = createMemo(() => consumers().some((consumer) => consumer())); | ||
| return [enabled2, (consumer) => setConsumers((p) => [...p, consumer])]; | ||
| } | ||
| var SkipInternalRoot = null; | ||
| function createInternalRoot(fn, detachedOwner) { | ||
| SkipInternalRoot = fn; | ||
| const v = createRoot((dispose) => { | ||
| const owner = getOwner(); | ||
| setDebuggerContext(owner, INTERNAL); | ||
| return fn(dispose); | ||
| }, detachedOwner); | ||
| if (SkipInternalRoot === fn) | ||
| SkipInternalRoot = null; | ||
| return v; | ||
| } | ||
| var skipInternalRoot = () => { | ||
| const skip = !!SkipInternalRoot; | ||
| if (skip) | ||
| SkipInternalRoot = null; | ||
| return skip; | ||
| }; | ||
| // src/update.ts | ||
| import { onCleanup as onCleanup2 } from "solid-js"; | ||
| var GraphUpdateListeners = /* @__PURE__ */ new Set(); | ||
| { | ||
| const runListeners = () => GraphUpdateListeners.forEach((f) => f()); | ||
| if (typeof window._$afterUpdate === "function") { | ||
| GraphUpdateListeners.add(window._$afterUpdate); | ||
| } | ||
| window._$afterUpdate = runListeners; | ||
| } | ||
| function makeSolidUpdateListener(onUpdate2) { | ||
| GraphUpdateListeners.add(onUpdate2); | ||
| const unsub = () => GraphUpdateListeners.delete(onUpdate2); | ||
| getOwner() && onCleanup2(unsub); | ||
| return unsub; | ||
| } | ||
| var CreateRootListeners = /* @__PURE__ */ new Set(); | ||
| { | ||
| const runListeners = (root) => { | ||
| if (skipInternalRoot()) | ||
| return; | ||
| CreateRootListeners.forEach((f) => f(root)); | ||
| }; | ||
| if (typeof window._$afterCreateRoot === "function") { | ||
| CreateRootListeners.add(window._$afterCreateRoot); | ||
| } | ||
| window._$afterCreateRoot = runListeners; | ||
| } | ||
| function makeCreateRootListener(onUpdate2) { | ||
| CreateRootListeners.add(onUpdate2); | ||
| const unsub = () => CreateRootListeners.delete(onUpdate2); | ||
| getOwner() && onCleanup2(unsub); | ||
| return unsub; | ||
| } | ||
| function observeComputationUpdate(owner, onRun) { | ||
| if (owner.onComputationUpdate) | ||
| return void (owner.onComputationUpdate = onRun); | ||
| owner.onComputationUpdate = onRun; | ||
| interceptComputationRerun(owner, (fn) => { | ||
| owner.onComputationUpdate(); | ||
| fn(); | ||
| }); | ||
| } | ||
| function interceptComputationRerun(owner, onRun) { | ||
| const _fn = owner.fn; | ||
| let v; | ||
| let prev; | ||
| const fn = () => v = _fn(prev); | ||
| owner.fn = !!owner.fn.length ? (p) => { | ||
| onRun(fn, prev = p); | ||
| return v; | ||
| } : () => { | ||
| onRun(fn, void 0); | ||
| return v; | ||
| }; | ||
| } | ||
| function observeValueUpdate(node, onUpdate2, symbol) { | ||
| const remove = () => delete node.onValueUpdate[symbol]; | ||
| if (node.onValueUpdate) { | ||
| node.onValueUpdate[symbol] = onUpdate2; | ||
| return remove; | ||
| } | ||
| const map = node.onValueUpdate = { [symbol]: onUpdate2 }; | ||
| let value = node.value; | ||
| Object.defineProperty(node, "value", { | ||
| get: () => value, | ||
| set: (newValue) => { | ||
| for (let sym of Object.getOwnPropertySymbols(map)) | ||
| map[sym](newValue, value); | ||
| value = newValue; | ||
| } | ||
| }); | ||
| return remove; | ||
| } | ||
| // src/walker.ts | ||
| var RootID; | ||
| var OnSignalUpdate; | ||
| var OnComputationUpdate; | ||
| var TrackSignals; | ||
| var TrackBatchedUpdates; | ||
| var TrackComponents; | ||
| var Components = []; | ||
| var WALKER = Symbol("walker"); | ||
| function observeComputation(owner, id) { | ||
| if (TrackBatchedUpdates && isSolidComputation(owner)) | ||
| observeComputationUpdate(owner, OnComputationUpdate.bind(void 0, id)); | ||
| } | ||
| function observeValue(node, id) { | ||
| const handler = OnSignalUpdate; | ||
| if (TrackBatchedUpdates) | ||
| observeValueUpdate(node, (value, oldValue) => handler({ id, value, oldValue }), WALKER); | ||
| } | ||
| function createSignalNode(raw) { | ||
| return { | ||
| name: raw.name ?? "(anonymous)", | ||
| id: raw.id, | ||
| observers: markNodesID(raw.observers), | ||
| value: getSafeValue(raw.value) | ||
| }; | ||
| } | ||
| function mapOwnerSignals(owner) { | ||
| if (!owner.sourceMap || !TrackSignals) | ||
| return []; | ||
| return Object.values(owner.sourceMap).map((raw) => { | ||
| const id = markNodeID(raw); | ||
| observeValue(raw, id); | ||
| return createSignalNode({ ...raw, id }); | ||
| }); | ||
| } | ||
| function mapMemo(mapped, owner) { | ||
| const { id, name } = mapped; | ||
| observeValue(owner, id); | ||
| return Object.assign(mapped, { | ||
| signal: createSignalNode({ id, name, value: owner.value, observers: owner.observers }) | ||
| }); | ||
| } | ||
| function mapOwner(owner, type) { | ||
| type = markOwnerType(owner, type); | ||
| const id = markNodeID(owner); | ||
| const name = getNodeName(owner); | ||
| observeComputation(owner, id); | ||
| if (type === 0 /* Component */ && TrackComponents) { | ||
| const resolved = resolveElements(owner.value); | ||
| if (resolved) | ||
| Components.push({ name, resolved }); | ||
| } | ||
| const mapped = { | ||
| id, | ||
| name, | ||
| type, | ||
| signals: mapOwnerSignals(owner), | ||
| children: mapChildren(owner), | ||
| sources: markNodesID(owner.sources) | ||
| }; | ||
| return type === 3 /* Memo */ ? mapMemo(mapped, owner) : mapped; | ||
| } | ||
| function mapChildren({ owned, ownedRoots }) { | ||
| const children = []; | ||
| if (owned) | ||
| children.push.apply( | ||
| children, | ||
| owned.map((child) => mapOwner(child)) | ||
| ); | ||
| if (ownedRoots) | ||
| children.push.apply( | ||
| children, | ||
| [...ownedRoots].map((child) => mapOwner(child, 7 /* Root */)) | ||
| ); | ||
| return children; | ||
| } | ||
| function walkSolidTree(owner, config) { | ||
| RootID = config.rootId; | ||
| OnSignalUpdate = config.onSignalUpdate; | ||
| OnComputationUpdate = config.onComputationUpdate; | ||
| TrackSignals = config.trackSignals; | ||
| TrackBatchedUpdates = config.trackBatchedUpdates; | ||
| TrackComponents = config.trackComponents; | ||
| if (TrackComponents) | ||
| Components = []; | ||
| return { tree: mapOwner(owner), components: Components }; | ||
| } | ||
| // src/plugin.ts | ||
| import { createSignal as createSignal2, getOwner as getOwner2, runWithOwner as runWithOwner2 } from "solid-js"; | ||
| import { createSimpleEmitter } from "@solid-primitives/event-bus"; | ||
| import { push, splice } from "@solid-primitives/immutable"; | ||
| import { createLazyMemo } from "@solid-primitives/memo"; | ||
| var api = createInternalRoot(() => { | ||
| const owner = getOwner2(); | ||
| const [onUpdate2, triggerUpdate2] = createSimpleEmitter(); | ||
| const [onForceUpdate2, forceTriggerUpdate2] = createSimpleEmitter(); | ||
| const [enabled2, addDebuggerConsumer] = createConsumers(); | ||
| const [trackSignals, addTrackSignalsConsumer] = createConsumers(); | ||
| const [trackBatchedUpdates, addTrackBatchedUpdatesConsumer] = createConsumers(); | ||
| const [trackComponents, addTrackComponentsConsumer] = createConsumers(); | ||
| const [roots2, setRoots2] = createSignal2([]); | ||
| const components = createLazyMemo( | ||
| () => roots2().reduce((arr, root) => { | ||
| arr.push.apply(arr, root.components); | ||
| return arr; | ||
| }, []) | ||
| ); | ||
| const serialisedRoots = createLazyMemo( | ||
| () => roots2().map((root) => ({ | ||
| id: root.id, | ||
| tree: root.tree | ||
| })) | ||
| ); | ||
| const debuggerConfig2 = { | ||
| get enabled() { | ||
| return enabled2(); | ||
| }, | ||
| get trackSignals() { | ||
| return trackSignals(); | ||
| }, | ||
| get trackBatchedUpdates() { | ||
| return trackBatchedUpdates(); | ||
| }, | ||
| get trackComponents() { | ||
| return trackComponents(); | ||
| } | ||
| }; | ||
| function registerDebuggerPlugin2(factory) { | ||
| runWithOwner2(owner, () => { | ||
| const { enabled: enabled3, trackBatchedUpdates: trackBatchedUpdates2, trackComponents: trackComponents2, trackSignals: trackSignals2 } = factory({ | ||
| makeBatchUpdateListener, | ||
| roots: roots2, | ||
| components, | ||
| triggerUpdate: triggerUpdate2, | ||
| forceTriggerUpdate: forceTriggerUpdate2, | ||
| serialisedRoots | ||
| }); | ||
| enabled3 && addDebuggerConsumer(enabled3); | ||
| trackBatchedUpdates2 && addTrackBatchedUpdatesConsumer(trackBatchedUpdates2); | ||
| trackComponents2 && addTrackComponentsConsumer(trackComponents2); | ||
| trackSignals2 && addTrackSignalsConsumer(trackSignals2); | ||
| }); | ||
| } | ||
| return { | ||
| onUpdate: onUpdate2, | ||
| onForceUpdate: onForceUpdate2, | ||
| triggerUpdate: triggerUpdate2, | ||
| forceTriggerUpdate: forceTriggerUpdate2, | ||
| enabled: enabled2, | ||
| debuggerConfig: debuggerConfig2, | ||
| roots: roots2, | ||
| setRoots: setRoots2, | ||
| registerDebuggerPlugin: registerDebuggerPlugin2, | ||
| updateRoot(root) { | ||
| setRoots2((arr) => { | ||
| const index = arr.findIndex((o) => o.id === root.id); | ||
| return index !== -1 ? splice(arr, index, 1, root) : push(arr, root); | ||
| }); | ||
| }, | ||
| removeRoot(rootId) { | ||
| setRoots2((arr) => { | ||
| const index = arr.findIndex((o) => o.id === rootId); | ||
| return splice(arr, index, 1); | ||
| }); | ||
| } | ||
| }; | ||
| }); | ||
| var { | ||
| onUpdate, | ||
| onForceUpdate, | ||
| triggerUpdate, | ||
| forceTriggerUpdate, | ||
| enabled, | ||
| debuggerConfig, | ||
| roots, | ||
| setRoots, | ||
| registerDebuggerPlugin, | ||
| updateRoot, | ||
| removeRoot | ||
| } = api; | ||
| // src/primitives.ts | ||
| function createGraphRoot(owner) { | ||
| createInternalRoot((dispose) => { | ||
| onOwnerCleanup(owner, dispose); | ||
| const rootId = getNewSdtId(); | ||
| const onComputationUpdate = (payload) => { | ||
| if (!debuggerConfig.trackBatchedUpdates || owner.isDisposed) | ||
| return; | ||
| if (enabled()) | ||
| triggerRootUpdate(); | ||
| batchUpdate({ type: 1 /* Computation */, payload }); | ||
| }; | ||
| const onSignalUpdate = (payload) => { | ||
| if (!debuggerConfig.trackBatchedUpdates || owner.isDisposed) | ||
| return; | ||
| batchUpdate({ type: 0 /* Signal */, payload }); | ||
| }; | ||
| const forceRootUpdate = () => { | ||
| if (owner.isDisposed) | ||
| return; | ||
| const { tree, components } = untrack( | ||
| walkSolidTree.bind(void 0, owner, { | ||
| ...debuggerConfig, | ||
| onComputationUpdate, | ||
| onSignalUpdate, | ||
| rootId | ||
| }) | ||
| ); | ||
| updateRoot({ id: rootId, tree, components }); | ||
| }; | ||
| const triggerRootUpdate = throttle(forceRootUpdate, 350); | ||
| onUpdate(triggerRootUpdate); | ||
| onForceUpdate(forceRootUpdate); | ||
| createEffect(() => enabled() && forceRootUpdate()); | ||
| setDebuggerContext(owner, { rootId, triggerRootUpdate, forceRootUpdate }); | ||
| onCleanup3(() => { | ||
| removeDebuggerContext(owner); | ||
| removeRoot(rootId); | ||
| owner.isDisposed = true; | ||
| }); | ||
| }); | ||
| } | ||
| function attachDebugger(_owner = getOwner()) { | ||
| let owner = _owner; | ||
| if (!owner) | ||
| return console.warn( | ||
| "reatachOwner helper should be used synchronously inside createRoot callback body." | ||
| ); | ||
| forEachLookupRoot(owner, (root, ctx) => { | ||
| root.sdtAttached = true; | ||
| markOwnerType(root, 7 /* Root */); | ||
| if (ctx === INTERNAL) | ||
| return; | ||
| if (ctx) { | ||
| ctx.triggerRootUpdate(); | ||
| let parent = findClosestAliveParent(root); | ||
| if (!parent.owner) | ||
| return console.warn("PARENT_SHOULD_BE_ALIVE"); | ||
| let removeFromOwned = addRootToOwnedRoots(parent.owner, root); | ||
| const onParentCleanup2 = () => { | ||
| const newParent = findClosestAliveParent(root); | ||
| if (newParent.owner) { | ||
| parent = newParent; | ||
| removeFromOwned(); | ||
| removeFromOwned = addRootToOwnedRoots(parent.owner, root); | ||
| onOwnerCleanup(parent.root, onParentCleanup2); | ||
| } else { | ||
| removeFromOwned(); | ||
| removeOwnCleanup(); | ||
| createGraphRoot(root); | ||
| } | ||
| }; | ||
| const removeParentCleanup = onOwnerCleanup(parent.root, onParentCleanup2); | ||
| const removeOwnCleanup = onOwnerCleanup(root, () => { | ||
| root.isDisposed = true; | ||
| removeFromOwned(); | ||
| removeParentCleanup(); | ||
| ctx.triggerRootUpdate(); | ||
| }); | ||
| } else | ||
| createGraphRoot(root); | ||
| }); | ||
| } | ||
| function findClosestAliveParent(owner) { | ||
| let disposed = null; | ||
| let closestAliveRoot = null; | ||
| let current = owner; | ||
| while (current.owner && !closestAliveRoot) { | ||
| current = current.owner; | ||
| if (isSolidRoot(current)) { | ||
| if (current.isDisposed) | ||
| disposed = current; | ||
| else | ||
| closestAliveRoot = current; | ||
| } | ||
| } | ||
| if (!closestAliveRoot) | ||
| return { owner: null, root: null }; | ||
| return { owner: (disposed == null ? void 0 : disposed.owner) ?? owner.owner, root: closestAliveRoot }; | ||
| } | ||
| function forEachLookupRoot(owner, callback) { | ||
| const roots2 = []; | ||
| let ctx; | ||
| do { | ||
| if (isSolidRoot(owner)) { | ||
| if (owner.sdtAttached) { | ||
| if (!ctx) | ||
| ctx = getDebuggerContext(owner); | ||
| break; | ||
| } | ||
| if (owner.sdtContext === INTERNAL) { | ||
| ctx = INTERNAL; | ||
| break; | ||
| } | ||
| roots2.push(owner); | ||
| } | ||
| owner = owner.owner; | ||
| } while (owner); | ||
| for (let i = roots2.length - 1; i >= 0; i--) { | ||
| const root = roots2[i]; | ||
| callback(root, ctx); | ||
| if (root.sdtContext) | ||
| ctx = root.sdtContext; | ||
| } | ||
| } | ||
| // src/index.ts | ||
| var Debugger = (props) => { | ||
| attachDebugger(); | ||
| return props.children; | ||
| }; | ||
| export { | ||
| UNNAMED, | ||
| isSolidComputation, | ||
| isSolidMemo, | ||
| isSolidOwner, | ||
| isSolidRoot, | ||
| getNodeName, | ||
| getNodeType, | ||
| getOwnerType, | ||
| getSafeValue, | ||
| lookupOwner, | ||
| onOwnerCleanup, | ||
| onParentCleanup, | ||
| createUnownedRoot, | ||
| getFunctionSources, | ||
| createInternalRoot, | ||
| makeSolidUpdateListener, | ||
| makeCreateRootListener, | ||
| observeComputationUpdate, | ||
| interceptComputationRerun, | ||
| observeValueUpdate, | ||
| registerDebuggerPlugin, | ||
| attachDebugger, | ||
| Debugger | ||
| }; |
61966
2.87%1749
2.4%9
28.57%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added