Git Product home page Git Product logo

Comments (5)

thebluefish avatar thebluefish commented on August 16, 2024 1

If we're asking the user to insert a resource to transition, I would personally expect the existence of the NextState resource to indicate that a transition should occur. IMO we should simply not insert this resource by default, and remove it once the transition has processed.

from iyes_loopless.

inodentry avatar inodentry commented on August 16, 2024 1

OK, reverted back to the 0.1 states behavior, except now without the next != current check (transitioning to the same state as the current is allowed). The NextState behaves as you described: insert it to trigger a transition, and it gets auto-removed when the transition is performed.

I consider this bug important enough that I decided to release a 0.3.0 immediately, just for this.

from iyes_loopless.

tjamaan avatar tjamaan commented on August 16, 2024

Ways to fix this:

  1. Treat switching a state to itself as an edge-case and require users to set another resource (e.g. insert_resource(NextState(same_state)) + insert_resource(SameStateSwitch(true))) in order to execute exit and enter stages.
    1.1. Pros: Only need to check for resource SameStateSwitch(true) if current and new state are equal.
    1.2. Cons: Clunky if you need to switch state to itself intentionally. New users need to discover the need for SameStateSwitch resource.
  2. Turn NextState<T>(pub T) into NextState<T>(pub Option<T>).
    2.1. Pros: Simple to use.
    2.2. Cons: Matching an Option is not free. (It doesn't cost much though)

from iyes_loopless.

inodentry avatar inodentry commented on August 16, 2024

That was the behavior in 0.1. I changed it, because "repeatedly inserting and removing a resource" (effectively "using a resource as an event") felt weird to me. But you are right, why not, it makes sense. In retrospect, if we are gonna use a resource to trigger a transition, that makes more sense. I guess I should bring it back.

from iyes_loopless.

tjamaan avatar tjamaan commented on August 16, 2024

I confirmed that the fix works. Only the initial state's enter stage is run at the start, and it only ran once.

from iyes_loopless.

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.