Comments (13)
For this issue I'm going to allow you to define a named guard or action without assigning a value like so:
action log
guard isValidCard
state idle {
purchase => isValidCard => log => purchasing
}
state purchasing {}
In #34 we can talk about what an inline form would look like.
from liblucy.
Ah and then you define those by extending? Makes sense, think I can add this.
from liblucy.
@matthewp I 100% agree. I also think Lucy would benefit from not exporting a machine, but exporting a createMachine
function. I.e:
import createToggleMachine from './toggle.lucy';
interface Context {}
type Event = { type: "EVENT" }
const machine = createToggleMachine<Context, Event>({ actions: {}, services: {} });
This is both more flexible in terms of Typescript (allows for generics) and provides first-class typings for actions/services/guards etc.
EDIT:
And also could make Lucy's syntax a lot simpler by removing/discouraging the use of 'use'.
from liblucy.
@mattpocock Can you open a separate issue to discuss your idea for changing what gets exported? I'm intrigued by the idea but want to keep this one focused on allowing unimplemented named guards and actions.
from liblucy.
For this issue I'm going to allow you to define a named guard or action without assigning a value like so:
action log guard isValidCard state idle { purchase => isValidCard => log => purchasing } state purchasing {}
In #34 we can talk about what an inline form would look like.
This is great, I was just about to open an issue for a feature request allowing action
s and guard
s to be injected, instead of imported and this solves the issue neatly
from liblucy.
@reaktivo you might want to look at #34 where this is better explained. Essentially we are changing machine signatures to be a function that takes in actions/guards, etc. and returns a StateMachine. The :name
syntax signifies something that needs to be passed in. So the above example could be either:
action log = :log
guard isValidCard = :isValidCard
state idle {
purchase => isValidCard => log => purchasing
}
state purchasing {}
Or with an inline form:
state idle {
purchase => guard(:isValidCard) => action(:log) => purchasing
}
state purchasing {}
from liblucy.
Is there an example of what this would compile to? I haven't seen a XState machine like this I don't think.
from liblucy.
const machine = createMachine({
entry: ['helloWorld'],
});
In normal XState, you don't need to define every action that the machine describes. This is an important tool for leaving the implementation up to the 'consumer' of the machine, and I use it all the time
from liblucy.
Yeah you can define these when you interpret
the machine or run useMachine
/useInterpret
on it
from liblucy.
I really like this idea. It overcomes one of the awkward things about Lucy at the moment, the interface between Lucy and JavaScript. This idea sidesteps the issue by making Lucy files purely descriptive. I'm wondering if we should maybe even encourage this pattern over importing JS. Will see how it looks once it's done.
from liblucy.
@oliverturner curious to hear your thoughts on this, if you have any.
from liblucy.
Perfeito
from liblucy.
Closed by #41 41
from liblucy.
Related Issues (20)
- Allow comments HOT 1
- Allow for stopping spawned actors HOT 5
- Guards for immediate transitions HOT 1
- 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.