Comments (9)
Hi, thanks for feedback :)
Actually, adding routes
and handlers
are totally different concepts.
You should register all routes
first to characterize the StateMachine
's transition flow before adding any side-effects i.e. handlers
.
So, it is meaningless to just add handlers without declaring what routes are available.
In your case, if you want to invoke an "event handler" by .SomeEvent
from any states without changing current one, you can add a route that is only available for .SomeEvent
:
// add route for "anywhere to anywhere" but only valid when `.SomeEvent` is called
machine.addRouteEvent(.SomeEvent, transitions: [ nil => nil ])
// or, attach eventHandler all together
machine.addRouteEvent(.SomeEvent, transitions: [ nil => nil ], handler: { ... } )
Important thing here is: Adding routes are more important. Handlers are secondary.
(Also, please also note that you can't attach route
by addHandler()
/addEventHandler()
although you can attach handler
in addRoute()
/addEventRoute()
)
from swiftstate.
Ah, sorry. There seems to have a bug when I do the above (finished state will be .AnyState
).
I will fix this soon.
from swiftstate.
Great, thanks! Let me know if I can help.
And thank you for your feedback. Actually, I use a state machine paradigm for just states and would enjoy the idea of passing events to states -- e.g., machine.addEventHandler(.SomeState, { ... } )
.
The state for me is a greater view idea than a button being on / off do you know what I mean? It's in a Loading
state or a Showing
state or a Searching
state etc.. I certainly don't overload the view controller here, but instead employ the VIPER
pattern across these major components. I employ a state machine paradigm at the V
or view level, whereas the P
or presenter is the main director of the view. The view is dumb and merely just moves things around in response to state changes OR events. This makes communication between P
and V
well-defined with clear-cut split responsibilities.
from swiftstate.
My above mentioned is fixed in #29.
Please check StateMachineEventTests.swift#L89-L112 for more information.
from swiftstate.
Maybe you are only interested in current state and not transition.
But actually, you can create the stay-still route i.e. .SomeState => .SomeState
and attach handlers to it.
Also, Event
is used for grouping state transitons, so it's good idea not to mix with State
.
from swiftstate.
Hmm.. I'm not sure what you mean by grouping state transitions. My idea stems from seeing states as templates. These templates can have activity spawned on them via events. Take for example a simple photo editor in which you have an ADD TEXT state. From within that state, you can change fonts by sending events VC ! ("CHANGE_FONT", fontToChangeTo)
. I'm not too sure what your alternative is? Sure, I can send the same state with some new refresh data embedded within userInfo, but that's not as clean as sending events tightly coupled with their corresponding data.
from swiftstate.
Sorry, I couldn't understand your question...
Is your above question related to the first one?
from swiftstate.
Code looks good. I'm just explaining my paradigm and how your library fits into it. Let me know if you have any questions. Thanks again.
from swiftstate.
All right.
You can create a new issue and explain your idea a bit more detailed,
for example, using StateMachine diagram like
https://en.wikipedia.org/wiki/Finite-state_machine.
Anyway! Thanks for your feedback 😊
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 build with Swift 2.0 on XCode7 beta5 HOT 5
- suggestion on transition and condition, which should include Event HOT 10
- 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.