tomasd / statecharts

Eclipse Public License 1.0
7 stars 0 forks source link

Super simple example #1

Closed hoopes closed 6 years ago

hoopes commented 6 years ago

Hi!

I'm interested in using this library, but I can't seem to get started with it. I've seen https://github.com/tomasd/statechart-demo , but I was having a bit of a hard time following it.

I know it's asking a lot, but I was hoping you could show the usage of your library with something almost comically simple, like switching a single div from red to green or something equally dumb.

I can get the very first initial state to fire its :enter function, and I can set breakpoints in the statechart code to see that something is happening when i dispatch an event for a transition, but I'm having some problems following the internal SC code. Is there something to inspect in the app db for "These are the current state(s) you are in!" Some sort of beginner-friendly demo would be amazing.

When I was in the chrome debugger, it seemed like the configuration argument was always empty - not sure exactly what I'm doing wrong.

Thanks very much!

tomasd commented 6 years ago

Hi, thank you for your interest. I created another demo for traffic lights. I hope it's more clear than statechart-demo (it's still WIP, I'm finding out the right patterns).

Usually I'm debugging statecharts with re-frame-10x. There is tracing tab where I look for :sc/enter/:sc/exit events.

Current statecharts state is in re-frame db on path [:statecharts.re-frame/configuration :configuration]. It's a vector of paths to all active leaf nodes.

If you have any further questions or ideas for improvement, just write me.

hoopes commented 6 years ago

Awesome! Thank you so much! I think this library has a TON of potential.

Within the code, what is the configuration? It always seemed empty for me (I haven't tried this traffic lights one yet). Is configuration meant to be the "current state" of all the charts? How is that intended to interact with the context?

Thanks again for your time, truly appreciated.

tomasd commented 6 years ago

Try it with traffic lights, there were some issues in previous versions of library, that it was not initialized correctly, now it should be fixed.

db path [:statecharts.re-frame/configuration] contains current state of statecharts which consists of :configuration (list of currently active leaf node paths) and :history (memo for history object).

context is created here . As you can see it contains current :fx and :configuration. There are a lot of helper functions in statecharts.re-frame for working with context. I'd like to add :cofx in the future, but it's little bit harder than in re-frame, as there can be many different requests to cofx from transitioning statemachines. I need to come up with some other solution...

As I was preparing examples and some small applications I was not using statecharts configuration. I have used db flags/fields which were set by :enter functions of appropriate states. I don't know if that is good approach. I just wanted view layer to not know anything about statecharts.

hoopes commented 6 years ago

:100: :bowing_man: