Comments (7)
Hi Konstantin,
I am still using it in my Android apps plus I recently created a similar library for Node.js (as I do Web dev as well). I personally, like the pattern for it's code clarity. It's very easy to come back to your code after long break and update the logic if required.
I use it for: handling UI events in some cases, handling application start up logic (it's quite complex in my case, has many async calls) and handling sync logic (multiple http calls, re-login when required, etc). I never used it for high-performance apps though.
I don't actively develop it as it's got all what I need.
For example, here's my start up logic. I have no idea how I would handle it w/o EasyFlow.
One advice - don't use maven version. It's well outdated. Build it from the sources.
flow = from(CHECK_SIGNED_UP).transit(
true,
on(no).to(SIGNING_UP).transit(
on(ok).to(VALIDATING_LOCAL_DB),
on(fail).to(SIGNING_UP),
on(cancel).finish(EXIT)
),
on(yes).to(VALIDATING_LOCAL_DB).transit(
on(fail).to(SEARCHING_OLD_DB).transit(
on(yes).to(CHECK_LEGACY_SIGNED_UP).transit(
on(yes).to(CLEANING_UP_OLD_DB),
on(no).to(UPLOADING_OLD_DB).transit(
on(fail).finish(EXIT),
on(retry).to(UPLOADING_OLD_DB),
on(ok).to(CLEANING_UP_OLD_DB).transit(
on(done).to(RESTORING_DB_FROM_CLOUD)
)
)
),
on(no).to(RESTORING_DB_FROM_CLOUD).transit(
on(fail).finish(EXIT),
on(retry).to(RESTORING_DB_FROM_CLOUD),
on(ok).to(VALIDATING_LOCAL_DB)
)
),
on(ok).to(INITIALIZING_POLICY).transit(
on(done).to(CHECKING_AUTO_UNLOCK).transit(
on(yes).to(VALIDATING_PASSWORD).transit(
on(yes).to(INITIALIZING_UI),
on(yes_skip_init).to(CHECKING_DAILY_TASK),
on(no).to(CHECKING_AUTO_UNLOCK),
on(cancel).finish(EXIT)
),
on(no_skip_init).to(CHECKING_DAILY_TASK),
on(no).to(INITIALIZING_UI).transit(
on(done).to(CHECKING_IMPORT_START).transit(
on(yes).to(IMPORTING).transit(
on(done).finish(COMPLETED)
),
on(no).to(CHECKING_JUST_UPDATED).transit(
on(yes).to(SHOWING_INFO).transit(
on(done).finish(COMPLETED)
),
on(no).to(CHECKING_DAILY_TASK).transit(
on(yes).to(RUNNING_DAILY_TASK).transit(
on(remind_premium).to(REMINDING_PREMIUM).transit(
on(done).finish(COMPLETED)
),
on(remind_review).to(REMINDING_REVIEW).transit(
on(done).finish(COMPLETED)
),
on(no).finish(COMPLETED)
),
on(no).finish(COMPLETED)
)
)
)
)
)
)
)
)
from easyflow.
This looks pretty clean. Like a higher-level language without all of the implemenation details.
Thaks for the answer, I will think how I could use your library! :)
from easyflow.
Yet another question.
How do you deal with configuration changes?
In example, a user presses a button and switches the state to "showing item selection fragment". Then, a config change occurs, the flow will be reset but the fragment will still be shown.
In your example you're just starting the new flow from the beginning every time the user flips the screen.
from easyflow.
Konstantin,
I am not sure that I understand correctly what you mean by "config change occurs". If you mean that your app will restart and, thus, reset status of your FSM, there are at least 2 ways to avoid it.
First, you can make activity not restart on config change (I believe, it's controlled by some flag in Android manifest). Second, you can put your FSM + context (which holds FSM state) into a singleton, so it will survive app config change.
from easyflow.
There is no way you can prevent Android from destroying your activity, the only reliable way you can use is to save/restore all states that activities have.
from easyflow.
That's right. However, it doesn't meant that all app's memory will be released. Even with activity "destroyed" application normally stays in "cached" state with all singletons alive and happy (for as long as there's enough RAM).
Anyways, if I was to design a new application with EasyFlow, I would keep all application's status in StatefulContext, then I would serialise / deserialise it as required. From the StatefulContext object I would be able to restore status of the entire application.
from easyflow.
There is no way you can prevent Android from clearing singletons as well.
OK, StatefulContext looks good. Thanks! :)
from easyflow.
Related Issues (20)
- StateHandler for whenEnter never invokes HOT 6
- Race condition during flow starting. HOT 1
- JavaDoc HOT 1
- Handlers fired multiple times for same transition HOT 1
- Easyflow never terminates its threads HOT 4
- Duplicated depending - slf4j-api
- Support possibility to create flow in a step by step manner HOT 3
- What the right way to "clean up" after exception during state process? HOT 2
- Adding terminate() method? HOT 1
- Support for non-deterministic FSM HOT 1
- Paper
- This is no longer working HOT 3
- In which package or library can I fine the "StatefulContext" class?
- The "on" method cannot be called HOT 1
- non-android example HOT 1
- Support of forks
- Some events are not triggered in a consistent manner
- Does SyncExecutor assumed to have a concurrent access HOT 4
- StateHandler for whenEnter never invokes
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 easyflow.