{"name":"xstate","version":"4.27.0-pr2674-2021926101023","keywords":["statechart","state machine","finite state machine","finite automata","scxml","state","interpreter"],"author":{"name":"David Khourshid","email":"davidkpiano@gmail.com"},"license":"MIT","_id":"xstate@4.27.0-pr2674-2021926101023","maintainers":[{"name":"davidkpiano","email":"davidkpiano@gmail.com"},{"name":"andarist","email":"mateuszburzynski@gmail.com"}],"homepage":"https://github.com/davidkpiano/xstate/tree/main/packages/core#readme","bugs":{"url":"https://github.com/davidkpiano/xstate/issues"},"dist":{"shasum":"2e0d666af42d914758735b91308c76a429aa4f6e","tarball":"http://registry-npm.ywwl.com/xstate/download/xstate-4.27.0-pr2674-2021926101023.tgz","fileCount":126,"integrity":"sha512-8PSKUBLo2/COiCEWkINDfk5OQoHNyPBjoyC8jowjSG69CSvfF20DduBc+ZePA6lhthGDqHYdhKQjjKq18arkQw==","signatures":[{"sig":"MEYCIQC0Fj7KabtBuIXLBTBzLuAqH6zPY+pLNPh9oDEAnwXJagIhAMtLRels3/ki/3R+fyDDAE3qjwdXKOJ1dBJEEJXPefmx","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":770382,"size":153713,"noattachment":false,"key":"/xstate/-/xstate-4.27.0-pr2674-2021926101023.tgz"},"main":"lib/index.js","types":"lib/index.d.ts","module":"es/index.js","readme":"<p align=\"center\">\n  <a href=\"https://xstate.js.org\">\n  <br />\n  <img src=\"https://i.imgur.com/FshbFOv.png\" alt=\"XState\" width=\"100\"/>\n  <br />\n    <sub><strong>JavaScript state machines and statecharts</strong></sub>\n  <br />\n  <br />\n  </a>\n</p>\n\n[![npm version](https://badge.fury.io/js/xstate.svg)](https://badge.fury.io/js/xstate)\n[![Statecharts gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/statecharts/statecharts)\n<img src=\"https://opencollective.com/xstate/tiers/backer/badge.svg?label=sponsors&color=brightgreen\" />\n\nJavaScript and TypeScript [finite state machines](https://en.wikipedia.org/wiki/Finite-state_machine) and [statecharts](https://www.sciencedirect.com/science/article/pii/0167642387900359/pdf) for the modern web.\n\n📖 [Read the documentation](https://xstate.js.org/docs)\n📑 Adheres to the [SCXML specification](https://www.w3.org/TR/scxml/).\n\n## Packages\n\n- 🤖 `xstate` - Core finite state machine and statecharts library + interpreter\n- [🔬 `@xstate/fsm`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-fsm) - Minimal finite state machine library\n- [📉 `@xstate/graph`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-graph) - Graph traversal utilities for XState\n- [⚛️ `@xstate/react`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-react) - React hooks and utilities for using XState in React applications\n- [✅ `@xstate/test`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-test) - Model-based testing utilities for XState\n\n## Super quick start\n\n```bash\nnpm install xstate\n```\n\n```js\nimport { createMachine, interpret } from 'xstate';\n\n// Stateless machine definition\n// machine.transition(...) is a pure function used by the interpreter.\nconst toggleMachine = createMachine({\n  id: 'toggle',\n  initial: 'inactive',\n  states: {\n    inactive: { on: { TOGGLE: 'active' } },\n    active: { on: { TOGGLE: 'inactive' } }\n  }\n});\n\n// Machine instance with internal state\nconst toggleService = interpret(toggleMachine)\n  .onTransition((state) => console.log(state.value))\n  .start();\n// => 'inactive'\n\ntoggleService.send('TOGGLE');\n// => 'active'\n\ntoggleService.send('TOGGLE');\n// => 'inactive'\n```\n\n- [Visualizer](#visualizer)\n- [Why? (info about statecharts)](#why)\n- [Installation](https://xstate.js.org/docs/guides/installation.html)\n- [Finite State Machines](#finite-state-machines)\n- [Hierarchical (Nested) State Machines](#hierarchical-nested-state-machines)\n- [Parallel State Machines](#parallel-state-machines)\n- [History States](#history-states)\n\n## Visualizer\n\n**[Visualize, simulate, and share your statecharts in XState Viz!](https://stately.ai/viz)**\n\n<a href=\"https://stately.ai/viz\" title=\"xstate visualizer\"><img src=\"https://i.imgur.com/3pEB0B3.png\" alt=\"xstate visualizer\" width=\"300\" /></a>\n\n## Why?\n\nStatecharts are a formalism for modeling stateful, reactive systems. This is useful for declaratively describing the _behavior_ of your application, from the individual components to the overall application logic.\n\nRead [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) ([🎥 video](https://www.youtube.com/watch?v=VU1NKX6Qkxc)) or check out these resources for learning about the importance of finite state machines and statecharts in user interfaces:\n\n- [Statecharts - A Visual Formalism for Complex Systems](https://www.sciencedirect.com/science/article/pii/0167642387900359/pdf) by David Harel\n- [The World of Statecharts](https://statecharts.github.io/) by Erik Mogensen\n- [Pure UI](https://rauchg.com/2015/pure-ui) by Guillermo Rauch\n- [Pure UI Control](https://medium.com/@asolove/pure-ui-control-ac8d1be97a8d) by Adam Solove\n- [Spectrum - Statecharts Community](https://spectrum.chat/statecharts) (For XState specific questions, please use the [GitHub Discussions](https://github.com/davidkpiano/xstate/discussions))\n\n## Finite State Machines\n\n<img src=\"https://imgur.com/rqqmkJh.png\" alt=\"Light Machine\" width=\"300\" />\n\n```js\nimport { createMachine } from 'xstate';\n\nconst lightMachine = createMachine({\n  id: 'light',\n  initial: 'green',\n  states: {\n    green: {\n      on: {\n        TIMER: 'yellow'\n      }\n    },\n    yellow: {\n      on: {\n        TIMER: 'red'\n      }\n    },\n    red: {\n      on: {\n        TIMER: 'green'\n      }\n    }\n  }\n});\n\nconst currentState = 'green';\n\nconst nextState = lightMachine.transition(currentState, 'TIMER').value;\n\n// => 'yellow'\n```\n\n## Hierarchical (Nested) State Machines\n\n<img src=\"https://imgur.com/GDZAeB9.png\" alt=\"Hierarchical Light Machine\" width=\"300\" />\n\n```js\nimport { createMachine } from 'xstate';\n\nconst pedestrianStates = {\n  initial: 'walk',\n  states: {\n    walk: {\n      on: {\n        PED_TIMER: 'wait'\n      }\n    },\n    wait: {\n      on: {\n        PED_TIMER: 'stop'\n      }\n    },\n    stop: {}\n  }\n};\n\nconst lightMachine = createMachine({\n  id: 'light',\n  initial: 'green',\n  states: {\n    green: {\n      on: {\n        TIMER: 'yellow'\n      }\n    },\n    yellow: {\n      on: {\n        TIMER: 'red'\n      }\n    },\n    red: {\n      on: {\n        TIMER: 'green'\n      },\n      ...pedestrianStates\n    }\n  }\n});\n\nconst currentState = 'yellow';\n\nconst nextState = lightMachine.transition(currentState, 'TIMER').value;\n// => {\n//   red: 'walk'\n// }\n\nlightMachine.transition('red.walk', 'PED_TIMER').value;\n// => {\n//   red: 'wait'\n// }\n```\n\n**Object notation for hierarchical states:**\n\n```js\n// ...\nconst waitState = lightMachine.transition({ red: 'walk' }, 'PED_TIMER').value;\n\n// => { red: 'wait' }\n\nlightMachine.transition(waitState, 'PED_TIMER').value;\n\n// => { red: 'stop' }\n\nlightMachine.transition({ red: 'stop' }, 'TIMER').value;\n\n// => 'green'\n```\n\n## Parallel State Machines\n\n<img src=\"https://imgur.com/GKd4HwR.png\" width=\"300\" alt=\"Parallel state machine\" />\n\n```js\nconst wordMachine = createMachine({\n  id: 'word',\n  type: 'parallel',\n  states: {\n    bold: {\n      initial: 'off',\n      states: {\n        on: {\n          on: { TOGGLE_BOLD: 'off' }\n        },\n        off: {\n          on: { TOGGLE_BOLD: 'on' }\n        }\n      }\n    },\n    underline: {\n      initial: 'off',\n      states: {\n        on: {\n          on: { TOGGLE_UNDERLINE: 'off' }\n        },\n        off: {\n          on: { TOGGLE_UNDERLINE: 'on' }\n        }\n      }\n    },\n    italics: {\n      initial: 'off',\n      states: {\n        on: {\n          on: { TOGGLE_ITALICS: 'off' }\n        },\n        off: {\n          on: { TOGGLE_ITALICS: 'on' }\n        }\n      }\n    },\n    list: {\n      initial: 'none',\n      states: {\n        none: {\n          on: { BULLETS: 'bullets', NUMBERS: 'numbers' }\n        },\n        bullets: {\n          on: { NONE: 'none', NUMBERS: 'numbers' }\n        },\n        numbers: {\n          on: { BULLETS: 'bullets', NONE: 'none' }\n        }\n      }\n    }\n  }\n});\n\nconst boldState = wordMachine.transition('bold.off', 'TOGGLE_BOLD').value;\n\n// {\n//   bold: 'on',\n//   italics: 'off',\n//   underline: 'off',\n//   list: 'none'\n// }\n\nconst nextState = wordMachine.transition(\n  {\n    bold: 'off',\n    italics: 'off',\n    underline: 'on',\n    list: 'bullets'\n  },\n  'TOGGLE_ITALICS'\n).value;\n\n// {\n//   bold: 'off',\n//   italics: 'on',\n//   underline: 'on',\n//   list: 'bullets'\n// }\n```\n\n## History States\n\n<img src=\"https://imgur.com/I4QsQsz.png\" width=\"300\" alt=\"Machine with history state\" />\n\n```js\nconst paymentMachine = createMachine({\n  id: 'payment',\n  initial: 'method',\n  states: {\n    method: {\n      initial: 'cash',\n      states: {\n        cash: { on: { SWITCH_CHECK: 'check' } },\n        check: { on: { SWITCH_CASH: 'cash' } },\n        hist: { type: 'history' }\n      },\n      on: { NEXT: 'review' }\n    },\n    review: {\n      on: { PREVIOUS: 'method.hist' }\n    }\n  }\n});\n\nconst checkState = paymentMachine.transition('method.cash', 'SWITCH_CHECK');\n\n// => State {\n//   value: { method: 'check' },\n//   history: State { ... }\n// }\n\nconst reviewState = paymentMachine.transition(checkState, 'NEXT');\n\n// => State {\n//   value: 'review',\n//   history: State { ... }\n// }\n\nconst previousState = paymentMachine.transition(reviewState, 'PREVIOUS').value;\n\n// => { method: 'check' }\n```\n\n## Sponsors\n\nHuge thanks to the following companies for sponsoring `xstate`. You can sponsor further `xstate` development [on OpenCollective](https://opencollective.com/xstate).\n\n<a href=\"https://tipe.io\" title=\"Tipe.io\"><img src=\"https://cdn.tipe.io/tipe/tipe-logo.svg?w=240\" style=\"background:#613DEF\" /></a>\n<a href=\"https://webflow.com\" title=\"Webflow\"><img src=\"https://uploads-ssl.webflow.com/583347ca8f6c7ee058111b3b/5b03bde0971fdd75d75b5591_webflow.png\" height=\"100\" /></a>\n","funding":{"url":"https://opencollective.com/xstate","type":"opencollective"},"scripts":{"test":"jest","build":"rollup -c","clean":"rm -rf lib es dist tsconfig.tsbuildinfo","version":"npm run build","preversion":"npm run test","postversion":"git push --follow-tags","publish:next":"npm version prerelease && npm publish --tag next","prepublishOnly":"npm run build"},"_npmUser":{"name":"andarist","email":"mateuszburzynski@gmail.com"},"repository":{"url":"git+https://github.com/davidkpiano/xstate.git","type":"git"},"_npmVersion":"7.1.0","description":"Finite State Machines and Statecharts for the Modern Web.","directories":{},"sideEffects":false,"_nodeVersion":"12.20.0","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^26.6.3","rxjs":"^7.1.0","jsdom":"^14.0.0","tslib":"^2.2.0","pkg-up":"^3.1.0","rollup":"^2.35.1","xml-js":"^1.6.11","ts-jest":"^26.5.6","@babel/cli":"^7.10.5","typescript":"^4.3.5","@babel/core":"^7.10.5","lerna-alias":"3.0.3-0","jsdom-global":"^3.0.2","@rollup/plugin-babel":"^5.3.0","rollup-plugin-terser":"^5.1.2","rollup-plugin-uglify":"^6.0.2","rollup-plugin-replace":"^2.2.0","rollup-plugin-filesize":"^6.2.1","rollup-plugin-typescript2":"^0.30.0","@scion-scxml/test-framework":"^2.0.15","babel-plugin-annotate-pure-calls":"^0.4.0"},"_npmOperationalInternal":{"tmp":"tmp/xstate_4.27.0-pr2674-2021926101023_1635243201964_0.8636484787461802","host":"s3://npm-registry-packages"},"publish_time":1635243202105,"_cnpm_publish_time":1635243202105,"dist-tags":{"alpha":"6.0.0-alpha.73","beta":"6.0.0-beta.3","latest":"5.33.4"}}