@statelyai/inspect
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -59,3 +59,3 @@ "use strict"; | ||
name: "@statelyai/inspect", | ||
version: "0.0.6", | ||
version: "0.0.7", | ||
description: "Inspection utilities for state, actors, workflows, and state machines.", | ||
@@ -69,3 +69,3 @@ main: "dist/index.js", | ||
"isomorphic-ws": "^5.0.0", | ||
xstate: "5.0.0" | ||
xstate: "5.1.0" | ||
}, | ||
@@ -79,2 +79,12 @@ scripts: { | ||
// src/idleCallback.ts | ||
function idleCallback(cb) { | ||
if (typeof window !== "undefined") { | ||
const raf = window.requestIdleCallback || window.requestAnimationFrame; | ||
raf(cb); | ||
} else { | ||
setTimeout(cb, 0); | ||
} | ||
} | ||
// src/createInspector.ts | ||
@@ -143,4 +153,6 @@ function getRoot(actorRef) { | ||
next: (event) => { | ||
const convertedEvent = convertXStateEvent(event); | ||
adapter.send(convertedEvent); | ||
idleCallback(function inspectNext() { | ||
const convertedEvent = convertXStateEvent(event); | ||
adapter.send(convertedEvent); | ||
}); | ||
} | ||
@@ -161,4 +173,9 @@ }, | ||
const actorRef = inspectionEvent.actorRef; | ||
const definitionObject = actorRef?.logic?.config; | ||
const definitionString = definitionObject ? JSON.stringify(definitionObject, (key, value) => { | ||
const logic = actorRef?.logic; | ||
const definitionObject = logic?.config; | ||
let name = actorRef.id; | ||
if (name === actorRef.sessionId && definitionObject) { | ||
name = definitionObject.id; | ||
} | ||
const definitionString = typeof definitionObject === "object" ? JSON.stringify(definitionObject, (key, value) => { | ||
if (typeof value === "function") { | ||
@@ -168,4 +185,5 @@ return { type: value.name }; | ||
return value; | ||
}) : void 0; | ||
const name = definitionObject ? definitionObject.id : actorRef.sessionId; | ||
}) : JSON.stringify({ | ||
id: name | ||
}); | ||
return { | ||
@@ -175,3 +193,3 @@ name, | ||
definition: definitionString, | ||
_version: "0.0.1", | ||
_version: package_default.version, | ||
createdAt: Date.now().toString(), | ||
@@ -192,3 +210,3 @@ id: null, | ||
sessionId: inspectionEvent.actorRef.sessionId, | ||
_version: "0.0.1", | ||
_version: package_default.version, | ||
createdAt: Date.now().toString(), | ||
@@ -205,3 +223,3 @@ id: null, | ||
sessionId: inspectionEvent.actorRef.sessionId, | ||
_version: "0.0.1", | ||
_version: package_default.version, | ||
createdAt: Date.now().toString(), | ||
@@ -208,0 +226,0 @@ id: null, |
@@ -11,3 +11,3 @@ { | ||
"name": "@statelyai/inspect", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Inspection utilities for state, actors, workflows, and state machines.", | ||
@@ -21,3 +21,3 @@ "main": "dist/index.js", | ||
"isomorphic-ws": "^5.0.0", | ||
"xstate": "5.0.0" | ||
"xstate": "5.1.0" | ||
}, | ||
@@ -29,2 +29,2 @@ "scripts": { | ||
} | ||
} | ||
} |
@@ -12,2 +12,3 @@ import { | ||
import pkg from '../package.json'; | ||
import { idleCallback } from './idleCallback'; | ||
@@ -106,4 +107,6 @@ function getRoot(actorRef: AnyActorRef) { | ||
next: (event) => { | ||
const convertedEvent = convertXStateEvent(event); | ||
adapter.send(convertedEvent); | ||
idleCallback(function inspectNext() { | ||
const convertedEvent = convertXStateEvent(event); | ||
adapter.send(convertedEvent); | ||
}); | ||
}, | ||
@@ -128,14 +131,23 @@ }, | ||
const actorRef = inspectionEvent.actorRef; | ||
const definitionObject = (actorRef as any)?.logic?.config; | ||
const definitionString = definitionObject | ||
? JSON.stringify(definitionObject, (key, value) => { | ||
if (typeof value === 'function') { | ||
return { type: value.name }; | ||
} | ||
const logic = (actorRef as any)?.logic; | ||
const definitionObject = logic?.config; | ||
let name = actorRef.id; | ||
return value; | ||
}) | ||
: undefined; | ||
const name = definitionObject ? definitionObject.id : actorRef.sessionId; | ||
// TODO: fix this in XState | ||
if (name === actorRef.sessionId && definitionObject) { | ||
name = definitionObject.id; | ||
} | ||
const definitionString = | ||
typeof definitionObject === 'object' | ||
? JSON.stringify(definitionObject, (key, value) => { | ||
if (typeof value === 'function') { | ||
return { type: value.name }; | ||
} | ||
return value; | ||
}) | ||
: JSON.stringify({ | ||
id: name, | ||
}); | ||
return { | ||
@@ -145,3 +157,3 @@ name, | ||
definition: definitionString, | ||
_version: '0.0.1', | ||
_version: pkg.version, | ||
createdAt: Date.now().toString(), | ||
@@ -162,3 +174,3 @@ id: null as any, | ||
sessionId: inspectionEvent.actorRef.sessionId, | ||
_version: '0.0.1', | ||
_version: pkg.version, | ||
createdAt: Date.now().toString(), | ||
@@ -175,3 +187,3 @@ id: null as any, | ||
sessionId: inspectionEvent.actorRef.sessionId, | ||
_version: '0.0.1', | ||
_version: pkg.version, | ||
createdAt: Date.now().toString(), | ||
@@ -178,0 +190,0 @@ id: null as any, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55787
20
1416
+ Addedxstate@5.1.0(transitive)
- Removedxstate@5.0.0(transitive)
Updatedxstate@5.1.0