Skip to content

salesforce-misc/Hydra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Hydra 🐙

States, Events, Actions

This is a library to expose DSL, which can be used to create State machines.

Example: Configure a Time-machine

Time Machine

We have 3 States PAST, PRESENT, FUTURE. These can be represented as plain simple Strings:

static final class State {
  public static final String PAST = "Past";
  public static final String PRESENT = "Present";
  public static final String FUTURE = "Future";
}

There are 4 actions that let you change from one state to another:

static final class Action {
  public static final String FORWARD = "Forward";
  public static final String BACKWARD = "Backward";
  public static final String FAST_FORWARD = "FastForward";
  public static final String FAST_BACKWARD = "FastBackward";
}

Now weave these States and Actions into a Graph using this DSL:

final Hydra<String, String, ?> timeMachine = Hydra.create(mb -> {
  mb.initialState(PRESENT);
  mb.state(PRESENT, String.class, sb -> {
    sb.on(FORWARD, String.class, (currentState, action) -> sb.transitionTo(FUTURE));
    sb.on(BACKWARD, String.class, (currentState, action) -> sb.transitionTo(PAST));
  });
  mb.state(FUTURE, String.class, sb -> {
    sb.on(BACKWARD, String.class, (currentState, action) -> sb.transitionTo(PRESENT));
    sb.on(FAST_BACKWARD, String.class, (currentState, action) -> sb.transitionTo(PAST));
  });
  mb.state(PAST, String.class, sb -> {
    sb.on(FORWARD, String.class, (currentState, action) -> sb.transitionTo(PRESENT));
    sb.on(FAST_FORWARD, String.class, (currentState, action) -> sb.transitionTo(FUTURE));
  });
});

Full-blown Applications

Refer to these applications for full-blown apps using this library:

🙌🏼 Consume-Collaborate-Contribute

  • This CONTRIBUTING doc has all the information to set up this library on your local and get hands-on.

  • Any issues or PRs are welcome! ♥️

  • Join this Slack Community to discuss issues or PRs related to Consumption-Collaboration-Contribution

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published