Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current pattern/library status #23

Open
konmik opened this issue Aug 27, 2015 · 7 comments
Open

Current pattern/library status #23

konmik opened this issue Aug 27, 2015 · 7 comments

Comments

@konmik
Copy link

konmik commented Aug 27, 2015

Hi, Andrey.

The library looks promising to me, but I am a little bit confused that it was not updated for years. Did you switch off Android development, or decided that the pattern does not work well / there are better ways to structure the screen logic? Or you're just using it as a proven tool and do not have a need to make it better?

Can you please elaborate on the effectiveness of the pattern. Do you use it in every app/on every screen, or it fits only some cases?

@Beh01der
Copy link
Owner

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)
                                                                )
                                                        )
                                                )
                                        )
                                )
                        )
                )
        )

@konmik
Copy link
Author

konmik commented Aug 27, 2015

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! :)

@konmik
Copy link
Author

konmik commented Aug 27, 2015

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.

@Beh01der
Copy link
Owner

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.

@konmik
Copy link
Author

konmik commented Aug 29, 2015

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.

@Beh01der
Copy link
Owner

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.

@konmik
Copy link
Author

konmik commented Aug 31, 2015

There is no way you can prevent Android from clearing singletons as well.

OK, StatefulContext looks good. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants