xstate 中 { actions: "" } 和 { entry: "" } 之间的区别?
Difference between { actions: "" } and { entry: "" } in xstate?
在我看来,您可以通过以下方式之一启动操作:
明确
{
...
states: {
foo: {
on: {
BAR: {
actions: "performSomeAction",
target: "bar",
},
},
},
bar: {},
},
...
}
隐式地与 "entry"
{
...
states: {
foo: {
on: {
BAR: "bar",
}
},
bar: {
entry: "performSomeAction",
},
},
...
}
在什么情况下你会选择其中之一?
David Kourshid(xstate 的创建者)answered Spectrum 上的这个:
They mean different things.
- Transition actions mean "execute this action only on this transition"
- Entry/exit actions mean "execute this action on any transition that enters/exits this state"
在我看来,您可以通过以下方式之一启动操作:
明确
{
...
states: {
foo: {
on: {
BAR: {
actions: "performSomeAction",
target: "bar",
},
},
},
bar: {},
},
...
}
隐式地与 "entry"
{
...
states: {
foo: {
on: {
BAR: "bar",
}
},
bar: {
entry: "performSomeAction",
},
},
...
}
在什么情况下你会选择其中之一?
David Kourshid(xstate 的创建者)answered Spectrum 上的这个:
They mean different things.
- Transition actions mean "execute this action only on this transition"
- Entry/exit actions mean "execute this action on any transition that enters/exits this state"