Giter Club home page Giter Club logo

xstate-ninja's Introduction

XState Ninja

logo

A dedicated devtool for XState state machines.

GitHub Workflow Status Support Ukraine code style: prettier PRs Welcome


Screenshots

screenshot

Quick Start

  1. Install the browser extension from the Chrome Web Store or Firefox Add-ons.
  2. Install the xstate-ninja package in your project:
npm install --save xstate-ninja xstate
  1. Interpret your state machine with the provided interpret function:
import { interpret } from 'xstate-ninja'
const actor = interpret(machine, { devTools: true })

For React integration, check the @xstate-ninja/react library. For Vue integration, check the @xstate-ninja/vue library.

How it works

The interpret function is just a thin wrapper around the core interpreter provided by the XState library. It accepts the same argument as the XState's interpret function. It observes your state machines and sends updates to the XState Ninja browser extension.

Configuration

To change default settings, import the XState Ninja instance in your project's index file:

// in your index.ts
import { configure, LogLevels } from 'xstate-ninja'

configure({
  enabled: process.env.NODE_ENV !== 'production',
  logLevel: LogLevels.debug,
})

XState Ninja is a singleton, so wherever you change these settings, they will be applied throughout your application.

enabled

Type: boolean

Default: true

Turns XState Ninja on or off. By default, tracking is always on. You may want to disable tracking in the production mode to improve performance.

logLevel

Type: LogLevels enum

Default: LogLevels.error

Controls how much stuff is logged into console by XState Ninja.

Upgrading from v1 → v2

If you were using the default export to configure XState Ninja, replace it with the configure function:

// ❌ DEPRECATED xstate-ninja v1
import XStateNinja from 'xstate-ninja'
XStateNinja({ enabled: false })

// ✅ xstate-ninja v2
import { configure } from 'xstate-ninja'
configure({ enabled: false })

Attribution

Ninja icons created by Good Ware - Flaticon

xstate-ninja's People

Contributors

rlaffers avatar zehir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xstate-ninja's Issues

Prevent new state frames when finite state not changed

If an event did not change current finite state (only actions are executed, or the transition was internal) a new state frame might not be needed.
Make sure we visualize entry/exit events correctly even if the finite state did not change.

Does this work with React Native?

Hi!

I just found this great looking tool and I'd love to use it with React Native. However, my attempts so far have failed with:

TypeError: Cannot read property 'useMachine' of undefined

Would we expect the library to work with React Native?

Updates on @xstate-ninja/vue

Hello,

This extension seems really good for debuging xstate, is there any eta about the @xstate-ninja/vue package ?
I notice it on npm but he has no code

Thanks

Not picking up XState machine on reload

Thanks for this great tool!

I'm developing a React app using webpack-dev-server. The first time I start the server, Ninja works as expected. However, if I reload the page, I get the 'No state machines were found on the current page' screen, and I need to restart the dev server to get Ninja working again.

Redux dev tools pick up the transitions regardless.

Circular structure in context crash the machine

Hello,

I have a machine where I store a rest client inside the context but it's seems to have circular structure and this crash the xstate-ninja and then the machine;

Uncaught (in promise) TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Client'
    |     property 'admins' -> object with constructor 'AdminService'
    --- property 'client' closes the circle
    at JSON.stringify (<anonymous>)
    at new H (xstate-ninja.js:181:36)
    at xstate-ninja.js:398:17
    at Interpreter2.update (interpreter.js:452:9)
    at interpreter.js:106:15
    at Scheduler2.process (scheduler.js:65:7)
    at Scheduler2.schedule (scheduler.js:44:10)
    at Interpreter2.send (interpreter.js:100:23)
    at _a2.id.id (interpreter.js:1135:15)
H @ xstate-ninja.js:181
(anonyme) @ xstate-ninja.js:398
Interpreter2.update @ interpreter.js:452
(anonyme) @ interpreter.js:106
Scheduler2.process @ scheduler.js:65
Scheduler2.schedule @ scheduler.js:44
Interpreter2.send @ interpreter.js:100
_a2.id.id @ interpreter.js:1135

Machine used ;

import { assign, createMachine } from 'xstate'
import PocketBase from 'pocketbase'
import { produce } from 'immer'

export interface StoreContext {
  pocketBaseUrl: string
  pocketBase?: PocketBase
}

export const storeMachine = createMachine({
  id: 'store',

  predictableActionArguments: true,
  tsTypes: {} as import('./store.typegen').Typegen0,

  schema: {
    context: {} as StoreContext,
    events: {} as {
      type: 'Add gateway'
    },
    services: {} as {
      connectToPocketBase: {
        data: PocketBase
      }
    },
  },

  context: {
    pocketBaseUrl: import.meta.env.VITE_POCKETBASE_URL,
  },

  states: {
    init: {
      after: {
        500: 'connecting',
      },
    },

    connecting: {
      invoke: {
        src: 'connectToPocketBase',
        onDone: {
          target: 'online',
          actions: 'usePocketBase',
        },
        onError: 'offline',
      },
    },

    online: {},
    offline: {},
  },

  initial: 'init',
},
{
  actions: {
    usePocketBase: assign({
      pocketBase: (context, event) => produce(context.pocketBase, (draft) => {
        draft = event.data
      }),
    }),
  },
  services: {
    connectToPocketBase: async (context) => {
      const client = new PocketBase(context.pocketBaseUrl)
      const health = await client.health.check()
      if (health.code === 200)
        return client
      else
        throw new Error('Could not connect to PocketBase')
    },
  },
})

With XStateNinja registred I am stuck in the connecting state and without I get to the online state

SolidStart / SolidJS - `ReferenceError: CustomEvent is not defined`

Just putting:

  • import { interpret } from 'xstate-ninja'

Into a page triggers this.

    at C:\GitHub\solidstart-08\node_modules\xstate-ninja\dist\xstate-ninja.umd.cjs:1:4193
    at C:\GitHub\solidstart-08\node_modules\xstate-ninja\dist\xstate-ninja.umd.cjs:1:60
    at Object.<anonymous> (C:\GitHub\solidstart-08\node_modules\xstate-ninja\dist\xstate-ninja.umd.cjs:1:233)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
    at async nodeImport (file:///C:/GitHub/solidstart-08/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:53137:21)
    at async eval (/src/routes/xstate.tsx:24:31)
    at async instantiateModule (file:///C:/GitHub/solidstart-08/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:53058:9```

[question] xstate@5 and xstate-ninja/react

Hey!

Recently migrated away from xstate@4 to xstate@5. Due to a breaking change in xstate5 we now need to use useActorRef instead of useInterpret. This creates an actor for a given machine logic. Does xstate-ninja/react offer a similar hook? Based on TypeScript inference there isn't. So I wonder if there is support for xstate5 in xstate-ninja/react?

ReferenceError: CustomEvent is not defined

When trying to use xstate-ninja in a react/nextjs app, I am getting the following error:

event - compiled client and server successfully in 275 ms (522 modules)
error - ReferenceError: CustomEvent is not defined
    at file:///home/user/app/node_modules/xstate-ninja/dist/xstate-ninja.js:139:17
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15) {
  page: '/p/[rulesId]'
}

Actor of type machine is not a state machine

Hello,

I have a beavior that I don't understand, the extention tell that my machine is not a state machine but why ? But after changing it back it's now a state machine.

On initial loading :

image

Then I select the invocation
It's not an machine so the message is ok
image

Then I select back the machine
Now the context and stuff is displayed
image

Dispatch events

Add an interface for dispatching arbitrary events to arbitrary actors.

Detect xstate-ninja version

Detect what version of xstate-ninja is used on the page and display compatibility warnings in the extension.

The 'xstate-ninja' library may need to update its package.json or typings

working on a typescript project with vscode and vite, I got this vscode error :

Could not find a declaration file for module 'xstate-ninja'. '/project/node_modules/xstate-ninja/dist/xstate-ninja.js' implicitly has an 'any' type.
  There are types at '/project/node_modules/xstate-ninja/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'xstate-ninja' library may need to update its package.json or typings.ts(7016)

what should I do to fixed this issue? or this library may need to update the package.json?

Here's I found similar issue on SO https://stackoverflow.com/a/76212193

Display assign actions

Assign actions are currently not reported by xstate. This may be solvable with the new Inspect API in v5.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.