Comments (10)
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.
Hi, I added your above example as a XCTestCase in cc6bc8f.
Is this what you are looking for?
from swiftstate.
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.
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.
Yes! Thanks!
from swiftstate.
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.
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.
Thanks:)
from swiftstate.
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.
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)
- Example in Readme lacks MyEvent. HOT 3
- Allow Swift 2.0 code to be used by CocoaPods HOT 1
- Whats meaning of nil => .State2 ? Got an error HOT 2
- Can't use event handler by itself HOT 9
- Can't build with Swift 2.0 on XCode7 beta5 HOT 5
- Machine.addHandler(transition: order: handler:) -> Disposable not working ? HOT 6
- Request for improvement HOT 2
- SwiftLint config error on carthage build HOT 2
- iOS 7 support HOT 4
- Swift 3.0 compatible? HOT 7
- Arrow pointing the wrong direction for sending events? HOT 2
- onEntry and onExit handlers? HOT 3
- Swift 4.0 compatible? HOT 2
- Carthage Build failed with exit code 65 HOT 3
- CocoaPod doens't compile with Xcode 9.2 HOT 1
- Would be really helpful if you version it better with each commit to master or swift/4.0
- Version 4.1.0 - doesnt compile HOT 3
- How to use with a Vapor3 project HOT 1
- State & Event enums with associated values complete example
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 swiftstate.