Git Product home page Git Product logo

Comments (10)

frogcjn avatar frogcjn commented on July 19, 2024

For example:
.LoadAction(Int) Event
.CancelAction Event

.Pending State
.Loading(Int) State

.LoadAction event has an associate integer to suggest which task it wants to trigger.
.Loading state has an associate integer to suggest which task it is loading.

when the .LoadAction triggered, and the machine on .Loading state with the same associate number, then the Event should be ignored.

from swiftstate.

inamiy avatar inamiy commented on July 19, 2024

Hi, I added your above example as a XCTestCase in cc6bc8f.
Is this what you are looking for?

from swiftstate.

frogcjn avatar frogcjn commented on July 19, 2024

Yes.

Because transition has no information on event, we should add all possible events to the machine.

        for actionId in 1...100 {
            machine.addRouteEvent(.LoadAction(actionId), transitions: [ .AnyState => .Loading(actionId) ], condition: { $0.fromState != .Loading(actionId) })
        }

if
(1) I want the Int as greater as I want, or
(2) the associate value is a generic type from subclass's enum, or
(3) the associate value is a data

then the StateMachine cannot work on this kind of situations.
These situations have the same character: event's associate value cannot be fully enumerated by current class.

from swiftstate.

inamiy avatar inamiy commented on July 19, 2024

Oh, OK I got it!
You are right, and current typealias Condition = (transition: Transition) -> Bool has too few parameters to distinguish Event and other stuffs e.g. userInfo.

I think it should be something like:

typealias ConditionContext = (event: Event, transition: Transition, userInfo: Any?)
typealias Condition = ConditionContext -> Bool

And for this enhancement, we will need a major version bump.
Let me take some time to work on this 😉

from swiftstate.

frogcjn avatar frogcjn commented on July 19, 2024

Yes! Thanks!

from swiftstate.

frogcjn avatar frogcjn commented on July 19, 2024

And another suggestion is, can you use Optional.None to represent the meaning of AnyState or AnyEvent?
Because it needs code to add an nil init for an event, and it is ugly to add one more State though the fact the machine hasn't that State.

If there is a place needs nil to represent for the meaning of "AnyState" or "AnyEvent", just put "Event?" or "State?" as the parameter's type.

from swiftstate.

inamiy avatar inamiy commented on July 19, 2024

Thanks for above feedback as well!
This will also be another big breaking change, so I will refactor existing codes for both ideas :)

from swiftstate.

frogcjn avatar frogcjn commented on July 19, 2024

Thanks:)

from swiftstate.

inamiy avatar inamiy commented on July 19, 2024

Sorry for late reply.
I just finished writing a rough draft for solving your above issues in #36.

Please check and tell me your thoughts 😉

from swiftstate.

inamiy avatar inamiy commented on July 19, 2024

This issue has been completed in #36 and ver 4.0.0.
Please see Ver 4.0.0 Release Notes for more detail.

@frogcjn Thanks again for your contribution! 🎉

from swiftstate.

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.