Comments (9)
@davidkpiano I mean, I understand that portion - and I know my knowledge about statecharts is lesser than yours - but it kind of doesn't make sense.
If we're talking about an action that executes while entering a state, shouldn't said action be able to consult the statechart's active state?
And if that holds true, shouldn't the active state (value) be the same state it was entered and not the one before transitioning?
from xstate.
@crls-dray Would you want something like this?
// PSEUDOCODE
const myAction = assign(({ stateNode }) => {
console.log(stateNode.id); // e.g. "someMachine.loading"
return {};
})
from xstate.
This is working as expected. The snapshot isn't committed until all of the actions have been executed.
from xstate.
Yes, that might work - not sure how'd that translate for parallel states, that's why I thought the actual value would be the same as the snapshot.value
. I'm not using parallel states, just mentioning it.
My use-case is that I have an action which is loading some data into the context, and such data is active-state specific.
The statechart is being defined in Stately Studio, the main purpose is to allow non-dev coworkers of mine to model the statechart with minimal overhead due to implementation specifics - thus why I can take away the implementation specifics if I'm able to load the info based on the current/active state.
from xstate.
I have the same use case as @cris-dray. I have a state property in my context loadingStatus.text
that I want to be updated every time a state transition occurs.
from xstate.
Based on vck3000's response, I can see this has been the current implementation for a long while, I would like to understand but it doesn't make sense as for me, anytime you add an entry
action property to a state, we expect it to match the current state value where the action is placed.
from xstate.
My current implementation looks like this but I have plenty of actions and state transitions (to notify the user, to update timestamp, etc):
import { setup, assign } from 'xstate';
const createDogMachine = (contextFromDB) => {
return setup({
actions: {
updateContext: assign({
state: (_, params) => params.state,
}),
}
}).createMachine({
id: 'dog',
initial: contextFromDB.state || 'asleep',
context: contextFromDB,
states: {
asleep: {
entry: [
{
type: 'updateContext',
params: {
state: 'asleep', // current state
}
}
],
on: {
'wakes up': 'awake',
}
},
awake: {
entry: [
{
type: 'updateContext',
params: {
state: 'awake', // current state
}
}
],
on: {
'falls asleep': 'asleep',
}
},
//...
}
});
}
gist: https://gist.github.com/carlosbensant/21adcd22373d16f1388f283a9b53a17f
from xstate.
cc. @Andarist - I know that you had opinions/thoughts on this
from xstate.
I think giving the user access to the state node that triggers the action would be nice, something like in #4217
from xstate.
Related Issues (20)
- Bug: Actor<T> cannot be assigned to ActorRef<T>. The options also seem wrongly typed. HOT 5
- Bug: clearTimeout being called with argument 'undefined'
- Bug: https://stately.ai/docs/xstate - Docs site is not working HOT 2
- Bug: 5.17.0 Property `"(machine)"` is missing in type...
- Bug: Sending an event with unserializable data to stopped actor throws an error (in development)
- Bug: [Typescript] Failing to declare first parameter of guard breaks type inference in enqueueActions if another guard accepts dynamic parameters HOT 1
- Bug: SpawnChild input does not see current event
- Mark events internal to a machine
- Bug: [Typescript] EventFrom helper type returning `never` since 5.17.0 HOT 1
- Example claims subscribe listener can be async HOT 3
- Bug: Emit cannot infer type HOT 1
- Bug: action objects returned by invoke.onDone.actions functions don't execute HOT 2
- Bug: guard helper typings may be broken HOT 3
- Bug: SendTo doesn't see local actors when combined with "target" transition HOT 1
- Bug: "An inline child actor cannot be persisted." error. HOT 2
- feat: Subscribe to emitted events from an actor
- Bug: Guard Logical Operator Functions Have Type Limitations
- Bug: @xstate/react system.get("actorSystemID") returns undefined on <StrictMode>
- Bug: Recreating a machine with children after getPersistedSnapshot results in an inability to persist it again
- Bug: spawn actor on logger be alive after throwing an js error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xstate.