Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added xstate visualiser popup on load #8

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Xstate React Calculator

++ Added xstate visualiser popup on load. You may need to refresh this page to re-trigger it!

Based on https://github.com/mukeshsoni/statechart-calculator, but upgraded to XState 4.x and refactored by moving all logic to the xstate's machine.

* [XState 4.x](https://xstate.js.org/docs/)
* [Reactjs](https://reactjs.org/)
* [@xstate/react add on](https://xstate.js.org/docs/packages/xstate-react/)
- [XState 4.x](https://xstate.js.org/docs/)
- [Reactjs](https://reactjs.org/)
- [@xstate/react add on](https://xstate.js.org/docs/packages/xstate-react/)

[![Edit xstate-react-calculator](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/GiancarlosIO/xstate-react-calculator)

Expand Down
29 changes: 28 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/><title>xstate</title><link href="/main.beb84cf5b30dbf623934.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/runtime~main.df2ccd1f669bd045e12b.min.js"></script><script type="text/javascript" src="/vendors~main.ea81954a2eac746e389f.chunk.js"></script><script type="text/javascript" src="/main.960d4ebe8fd1e12cb3d1.chunk.js"></script></body></html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>XSTATE</title>
<link href="/main.beb84cf5b30dbf623934.css" rel="stylesheet" />
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script
type="text/javascript"
src="/runtime~main.df2ccd1f669bd045e12b.min.js"
></script>
<script
type="text/javascript"
src="/vendors~main.ea81954a2eac746e389f.chunk.js"
></script>
<script
type="text/javascript"
src="/main.960d4ebe8fd1e12cb3d1.chunk.js"
></script>
</body>
</html>
11,279 changes: 0 additions & 11,279 deletions package-lock.json

This file was deleted.

14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"name": "react-xstate",
"name": "xstate-react-calculator-viz",
"version": "0.0.1",
"description": "",
"keywords": [
"webpack",
"react",
"styled-components",
"react-dom"
],
"keywords": [],
"main": "src/index.tsx",
"author": "",
"license": "MIT",
Expand All @@ -20,13 +15,14 @@
"@types/react": "16.9.5",
"@types/react-dom": "16.9.1",
"@types/styled-components": "4.1.19",
"@xstate/inspect": "^0.4.1",
"@xstate/react": "0.8.1",
"nexus-scripts": "1.3.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"styled-components": "4.4.0",
"typescript-styled-plugin": "^0.15.0",
"xstate": "4.11.0"
"xstate": "4.29.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.5.0",
Expand All @@ -45,4 +41,4 @@
"prettier": "^1.19.1",
"typescript": "^3.9.5"
}
}
}
2 changes: 1 addition & 1 deletion src/Calculator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function isOperator(text) {
}

const Calculator = () => {
const [state, sendMachine] = useMachine(machine, {});
const [state, sendMachine] = useMachine(machine, { devTools: true});

function send(event, payload) {
console.log('Event - Payload', { event, payload });
Expand Down
7 changes: 5 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
<title>xstate</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>XSTATE</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div class="viz">
<!-- <iframe id="viz" src="" ><iframe> -->
</div>
</body>
</html>
19 changes: 19 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ import ReactDOM from 'react-dom';

import App from './App';

import { inspect } from '@xstate/inspect';


const useIframe = true;

if(useIframe){
inspect({
// options
iframe: ()=>document.getElementById("viz") as HTMLIFrameElement,
url: "https://stately.ai/viz?inspect"
});
} else {
inspect({
// options
iframe: false,
url: "https://stately.ai/viz?inspect"
});
}

ReactDOM.render(
<React.StrictMode>
<App />
Expand Down
Binary file modified xstate-vis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.