-
Notifications
You must be signed in to change notification settings - Fork 74
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
Vue 2 docs not clear nor complete #278
Comments
Found this docs Now Im guessing the docs it misinformed but it is right at some point, if the dev doest work with |
@allestaire Yep, good shout - the recipes/vue docs need updating. Do these docs help? |
Sorry, but the docs you shared seems like specific for composition-api only. There are still old projects that uses or may not use xstate and as for me xstate is a great package for long forms and it helps me alot. This helps me to manage codes, easy maintained, easy tracking, less component variable. But if I want to implement this, of course I'll go to the site and find the east setup for such version. By the way, thanks to this great package 😄 👍 |
For Vue 2 there is this alternative package: https://www.npmjs.com/package/xstate-vue2 . We probably should call this out in the docs. |
I created an example repository of how basic usage looks like, I'll be expanding it to include more detail and use cases: https://github.com/amypellegrini/xstate-vue-example/blob/main/src/App.vue It's worth noticing that the setup code in the Packages section of the docs is now deprecated according to latest Vue. Using this code: export default {
setup() {
const { state, send } = useMachine(toggleMachine);
return {
state,
send
};
}
}; Triggers the linter rule vue/no-export-in-script-setup. The good news (if I understand correctly) is that now this is no longer needed, and you can declare and use the constants directly: <script setup>
import { useMachine } from '@xstate/vue'
import { createMachine } from 'xstate'
const toggleMachine = createMachine({
id: 'toggle',
initial: 'inactive',
states: {
inactive: {
on: { TOGGLE: 'active' }
},
active: {
on: { TOGGLE: 'inactive' }
}
}
})
const { state, send } = useMachine(toggleMachine)
</script>
<template>
<button @click="send('TOGGLE')">state is: {{ state.value }}</button>
</template> I verified this works with the following packages:
I'll be adding more examples with usages of |
Ok, I bootstrapped another example for Vue 2: https://github.com/amypellegrini/xstate-vue2-example Interestingly enough, the same lint rule applies even for Vue version 2: https://eslint.vuejs.org/rules/no-export-in-script-setup.html Which makes everything more confusing and harder to understand, at least for me (not being familiar with Vue nor its composition API). So far I see the need for distinct usage examples of Vue 2 and Vue 3, with and without composition API for Vue 3. Topic aside, I'm trying to also understand the format and expectations around |
Sorry for the confusion; recipes were originally "how to use XState with X" before we added official integrations. |
Thanks @davidkpiano for the clarification. I opened a draft PR and I'll be adding changes over the next few days: Now that I understand better I think there are two main use cases to consider:
It looks like for Vue 3 the recommended usage is via hook, so it makes sense to include examples with |
I've check this documentation but it seems like not too clear for as wanted a to go example in setting it up
The documentation only shows how to setup states but Im wondering why not include on how to include
services
,guards
and so when creating statehttps://xstate.js.org/docs/recipes/vue.html
Though upon checking the
createMachine
docs it provides optionsBut not seeing clear information in making through on non-composition-api.
In composition-api version is easy and clear.
createMachine
thenuserMachine
which dev can injectservices
,actions
, andguards
in to.Can you provide other example which we can see on how do we inject those options?
Or are there already existing example but hidden or not accessible on the site?
The text was updated successfully, but these errors were encountered: