A familiar game implemented using Big-Bang, a ClojureScript library inspired by Racket's big-bang. It abstracts the GUI event-loop into a component based system, allowing self-contained big-bang 'worlds' to communicate over core.async channels, in a reactive CSP style.
In this example, the main file builds some DOM elements and fetches various SVG assets for inclusion on the page. Then, three big-bang components are initialized:
-
The referee is responsible for kicking the opponent into making a choice, and for collating responses as well as keeping track of the score and who won each round.
-
The human component listens for events delivered from the SVG, and propagates the choice onto the referee. The choice is extracted from the event target payload (each clickable element has a "data-type='...' attribute).
-
An opponent just randomly picks one of Rock, Paper or Scissors when it is notified to choose by the referee. After which, it sends its choice back to the referee
They communicate with a notification channel outbound from the referee, mult(iplied) with taps to the human and opponent. Presently, only the opponent does anything with the notification events, and althought the human is wired in, it ignores them. A shared results channel between the human and opponent delivers choice messages back to referee.
State transitions inside each big-bang component are entirely free of side effects (even the apparent randomness inside the opponent). The render operations however will mutate the DOM.