rlaffers / xstate-ninja

Devtool for XState state machines
ISC License
68 stars 3 forks source link

Implement xstate-ninja-vue #8

Closed Zehir closed 10 months ago

Zehir commented 10 months ago

Contribution for #7

@rlaffers Should I add my name as author for the @xstate-ninja/vue package ?

Zehir commented 10 months ago

Some screenshot of the example image image image

rlaffers commented 10 months ago

Contribution for #7

@rlaffers Should I add my name as author for the @xstate-ninja/vue package ?

Yes please.

Zehir commented 10 months ago

Contribution for #7 @rlaffers Should I add my name as author for the @xstate-ninja/vue package ?

Yes please.

Done @rlaffers thanks

Zehir commented 10 months ago

Could you publish it on npm ?

Zehir commented 10 months ago

What do you think about a more generic way to register Ninja ?

import type { AnyInterpreter } from 'xstate'

import createXStateNinjaSingleton from 'xstate-ninja'

const ninja = createXStateNinjaSingleton()

export function registerNinja(actor: AnyInterpreter) {
  return watchEffect((onCleanup) => {
    if (actor.options?.devTools) {
      ninja.register(actor)
      onCleanup(() => ninja.unregister(actor))
    }
  })
}
const machine = useMachine(gatewayMachine, {
  id: `${gatewayMachine.id}-${id.value}`,
  devTools: true,
})

onScopeDispose(registerNinja(machine.service))

The onScopeDispose is a vue method to auto call the method when the vue who started the machine get deleted

There is still some vue related method in the register method but we can extract them out too