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

Please allow for stateless rule sets #15

Open
jeaye opened this issue Dec 21, 2017 · 0 comments
Open

Please allow for stateless rule sets #15

jeaye opened this issue Dec 21, 2017 · 0 comments

Comments

@jeaye
Copy link

jeaye commented Dec 21, 2017

I think this could reasonably be done with an additional value in the rule set which looks like :stateful? true or similar. For example:

{:id ::my-flow
 :rules [...]
 :stateful? true}

The reasoning for this is allowing truly declarative rule sets, where the order does not matter, cycles may occur, and rules may be skipped. This is essential for representing anything like a game loop or anything more complex than "first this, then this, then this."

I have a working version of the declarative-only rules here: https://github.com/jeaye/re-frame-rules/blob/36811b3dfc3f56079209ed0f9341cb99fa79fa36/src/com/jeaye/re_frame_rules.cljs#L111

With lots of respect, I simply have no need for state tracking, so I ripped out what re-frame-async-flow-fx was doing with it and kept only the part which applies in my code: binding rules that say "when this happens, do this," rather than "first this, then this."

Login example

To outline a real-world example of how this is used, here's a high-level view of my login flow.

  1. Try to load credentials from cache
  2. If no credentials were found, show the login screen
  3. Once the credentials were found or the login screen was navigated, talk to the server

If the credentials were loaded properly, but they're invalid (expired or malicious), the server will then give us an error, which shows the login screen. At which point, the rules should loop back so that, when the user logs in, rule number 3 is triggered and the process starts over.

Concurrent example

Given :first-dispatch-n, as described in ticket #14, these declarative rules can handle multiple flows concurrently. You first dispatch 5 events, say, and then, as each finishes, the flow is orchestrated by the declarative rules.

@jeaye jeaye changed the title Please allow for non-stateful rule sets Please allow for stateless rule sets Jan 13, 2018
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

1 participant