Skip to content

Please allow for stateless rule sets #15

Open
@jeaye

Description

@jeaye

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions