3.0.0 • Published 5 months ago
pinia-xstate v3.0.0
pinia-xstate
Put your xstate state machines into a global pinia store.
Installation
npm install xstate pinia-xstate
Usage
import { defineStore } from 'pinia'
import { xstate } from 'pinia-xstate'
import { createMachine } from 'xstate'
export const toggleMachine = createMachine({
id: 'toggle',
initial: 'inactive',
states: {
inactive: {
on: { TOGGLE: 'active' }
},
active: {
on: { TOGGLE: 'inactive' }
}
}
})
// create a store using the xstate middleware
export const useToggleStore = defineStore(
toggleMachine.id,
xstate(toggleMachine)
)
<script setup>
import { useToggleStore } from './store/toggle'
const store = useToggleStore()
</script>
<template>
<button @click="store.send({ type: 'TOGGLE' })">
{{ store.state.value === 'inactive'
? 'Click to activate'
: 'Active! Click to deactivate' }}
</button>
</template>
License
MIT
3.0.0
5 months ago
2.2.1
7 months ago
2.2.0
8 months ago
2.1.0
8 months ago
2.0.2
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
2.0.0-beta.1
2 years ago
2.0.0-beta.0
2 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago