Comments (5)
Normally you would call context.actorRef.stop()
in an action, right? You an currently do that, I think. But it might be nice to have a lucy native way. Maybe:
machine todoItem {
state idle {}
}
machine app {
state idle {
new => assign(todo, spawn(todoItem))
delete => stop(todo)
}
}
from liblucy.
This looks cool. One thing which might affect spawn in general is how we represent arrays of spawned actors? Though perhaps this should be the topic for another issue.
from liblucy.
Yeah lists are going to be needed eventually, I intentionally avoided that so far.
from liblucy.
Normally you would call
context.actorRef.stop()
in an action, right?
Unfortunately, no. The proper way to stop a spawned child is this:
{
on: {
STOP: actions.pure((ctx) => {
const assignAction = assign({ actorRef: null })
const stopAction = actions.stop(ctx.actorRef)
return [assignAction, stopAction]
})
}
}
XState v5 should improve this, but for now, the above code is the only way to stop a child actor without leaking memory. Simply calling ctx.actorRef.stop()
still leaves a dangling reference in machine.children
, while actions.stop()
will properly clean up all references.
Because assign()
executes before all other actions, you can't simply have:
actions: [
// doesn't work, assign() will execute before stop(), and `ctx.actorRef` will be null, so nothing will be stopped.
actions.stop(ctx => ctx.actorRef),
assign({ actorRef: null })
]
It must be wrapped in actions.pure()
.
from liblucy.
@VanTanev Thank you! Seems like something Lucy can do the gross part for you.
from liblucy.
Related Issues (20)
- Allow comments HOT 1
- Guards for immediate transitions HOT 1
- Allow for unimplemented actions/services/guards HOT 13
- Change the generated code to export a function, not a static machine definition HOT 18
- Add option for outputting to JSON HOT 4
- Add node/browser lib for Lucy HOT 2
- Incorrect indentation when a reference follows an inline assign
- Named actions/guards get shared with sibling machines
- [IDEA] XState JSON to Lucy? HOT 8
- Parallel states
- Nested states without nested machines HOT 2
- Compile hangs if too many repeated event definitions HOT 1
- Actions in nested machines HOT 2
- Target a nested state with an event HOT 2
- spawning should be done with a callback
- dts not created for entry actions
- Sending to an actor should include parent event data
- Invoking "use reference" is incorrectly referenced in services property HOT 2
- Why not javascript? HOT 1
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 liblucy.