Git Product home page Git Product logo

Comments (13)

matthewp avatar matthewp commented on June 26, 2024 3

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.

matthewp avatar matthewp commented on June 26, 2024 1

Ah and then you define those by extending? Makes sense, think I can add this.

from liblucy.

mattpocock avatar mattpocock commented on June 26, 2024 1

@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.

matthewp avatar matthewp commented on June 26, 2024 1

@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.

reaktivo avatar reaktivo commented on June 26, 2024 1

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 actions and guards to be injected, instead of imported and this solves the issue neatly

from liblucy.

matthewp avatar matthewp commented on June 26, 2024 1

@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.

matthewp avatar matthewp commented on June 26, 2024

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.

mattpocock avatar mattpocock commented on June 26, 2024
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.

mattpocock avatar mattpocock commented on June 26, 2024

Yeah you can define these when you interpret the machine or run useMachine/useInterpret on it

from liblucy.

matthewp avatar matthewp commented on June 26, 2024

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.

matthewp avatar matthewp commented on June 26, 2024

@oliverturner curious to hear your thoughts on this, if you have any.

from liblucy.

mattpocock avatar mattpocock commented on June 26, 2024

Perfeito

from liblucy.

matthewp avatar matthewp commented on June 26, 2024

Closed by #41 41

from liblucy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.