General statechart chat only - for XState discussions: https://github.com/davidkpiano/xstate/discussions
Just trying out @xstate/inspect - always get a weird error:
TypeScript error in /Users/********/repos/realyse-platform/node_modules/@xstate/inspect/lib/browser.d.ts(3,13):
'=' expected. TS1005
1 | import { Interpreter, EventObject } from 'xstate';
2 | import { XStateDevInterface } from 'xstate/lib/devTools';
> 3 | import type { Inspector, InspectorOptions, InspectReceiver, WebSocketReceiverOptions, WindowReceiverOptions } from './types';
| ^
4 | export declare const serviceMap: Map<string, Interpreter<any, any, EventObject, {
5 | value: any;
6 | context: any;
Have updated to latest xstate version to exclude this being the reason. Any idea what could be happening?
inspect
call to the highest level in the code, as per the instructions.
import type
syntax was added with 3.8 (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html)
resolveState
with a running machine in React.resolveState
to hydrate a new machine. Any suggestions on how best to apply a state to a machine that's interpreted using useMachine
?// Use machine.resolveState() to resolve the state definition to a new State instance relative to the machine
const resolvedState = myMachine.resolveState(previousState);
OK, I feel like I'm very close. I've updated my example: https://codesandbox.io/s/dry-frog-u3prr?file=/src/App.js
Now I'm attempting to restart the service with the history state.
useHashChange(() => {
const hash = window.location.hash.slice(2);
const stateFromHistory = stateHistory.get(hash);
service.stop();
service.start(simpleMachine.resolveState(stateFromHistory));
});
It seems to be working, however, React is not reacting to this restart :-)
Any suggestions on how best to let React know that the service has changed?
"These guys knew what they were doing. And boy, when you look at this, I think 'why did the internet turn out so well, and why can't we do regular software that way?' Because you could imagine taking the internet as a model for doing software modules. Why don't people do it?"
--Alan Kay
Actor model :D