Skip to content

Commit

Permalink
Merge pull request #27 from statelyai/revert-24-davidkpiano/better-se…
Browse files Browse the repository at this point in the history
…rialization

Revert "Better serialization"
  • Loading branch information
davidkpiano authored May 13, 2024
2 parents 76a599f + 39279fe commit b0b3666
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-candles-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/inspect": patch
---

Revert serialization changes
21 changes: 3 additions & 18 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import safeStringify from 'fast-safe-stringify';
import { AnyEventObject, Observer, Subscribable, toObserver } from 'xstate';
import {
InspectorOptions,
createInspector,
defaultInspectorOptions,
} from './createInspector';
import { InspectorOptions, createInspector } from './createInspector';
import { Adapter, Inspector, StatelyInspectionEvent } from './types';
import { UselessAdapter } from './useless';

Expand Down Expand Up @@ -169,14 +165,7 @@ export class BrowserAdapter implements Adapter {
) {
this.status = 'connected';
this.deferredEvents.forEach((event) => {
const preSerializedEvent = defaultInspectorOptions.serialize(
event,
event
);
const serializedEvent = this.options.serialize(
preSerializedEvent,
event
);
const serializedEvent = this.options.serialize(event);
this.targetWindow?.postMessage(serializedEvent, '*');
});
}
Expand All @@ -195,11 +184,7 @@ export class BrowserAdapter implements Adapter {
if (this.options.send) {
this.options.send(event);
} else if (this.status === 'connected') {
const preSerializedEvent = defaultInspectorOptions.serialize(
event,
event
);
const serializedEvent = this.options.serialize(preSerializedEvent, event);
const serializedEvent = this.options.serialize(event);
this.targetWindow?.postMessage(serializedEvent, '*');
}

Expand Down
2 changes: 1 addition & 1 deletion src/createInspector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('Creates an inspector for a state machine', async () => {
},
{
"event": {
"input": null,
"input": undefined,
"type": "xstate.init",
},
"sessionId": "x:0",
Expand Down
16 changes: 5 additions & 11 deletions src/createInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { AnyActorRef, InspectionEvent, Snapshot } from 'xstate';
import pkg from '../package.json';
import { idleCallback } from './idleCallback';
import safeStringify from 'safe-stable-stringify';
import { serialize } from 'superjson';

function getRoot(actorRef: AnyActorRef) {
let marker: AnyActorRef | undefined = actorRef;
Expand All @@ -34,10 +33,7 @@ function getRootId(actorRefOrId: AnyActorRef | string): string | undefined {

export interface InspectorOptions {
filter?: (event: StatelyInspectionEvent) => boolean;
serialize?: (
event: StatelyInspectionEvent,
originalEvent: StatelyInspectionEvent
) => StatelyInspectionEvent;
serialize?: (event: StatelyInspectionEvent) => StatelyInspectionEvent;
/**
* Whether to automatically start the inspector.
*
Expand All @@ -48,8 +44,7 @@ export interface InspectorOptions {

export const defaultInspectorOptions: Required<InspectorOptions> = {
filter: () => true,
serialize: (event) =>
serialize(event).json as unknown as StatelyInspectionEvent,
serialize: (event) => event,
autoStart: true,
};

Expand All @@ -62,11 +57,10 @@ export function createInspector<TAdapter extends Adapter>(
// Event filtered out
return;
}
const preSerializedEvent = defaultInspectorOptions.serialize(event, event);
const serializedEvent =
options?.serialize?.(preSerializedEvent, event) ?? preSerializedEvent;

const serializedEvent = options?.serialize?.(event) ?? event;
// idleCallback(() => {
adapter.send(serializedEvent);
// })
}
const inspector: Inspector<TAdapter> = {
adapter,
Expand Down

0 comments on commit b0b3666

Please sign in to comment.