June 1, 2015

Tetris in clojurescript and re-frame Part 10 - Missing Bits

Now that defined the basic building blocks we will put it all together and deliver the missing bits.

core.cljs

https://github.com/sveri/omtet/blob/single_player_0.1/resources/templates/tetris/index.html

Here we have the UI defined. It just draws the canvas and the score div. It is also responsible for drawing any updates to the UI.

handlers.cljs

https://github.com/sveri/omtet/blob/single_player_0.1/src/cljs/de/sveri/omtet/tetris/handlers.cljs

Here we defined all the handlers that act whenever an event occurs.
One thing I did not explain yet are these lines:

(defn grid-changed-mw [app-state]
  (minios/draw-grid (:grid-state app-state) (:ctx app-state)))
  
(register-handler
  :...
  (rf/after grid-changed-mw)

This calls the middleware function after from re-frame which will execute the given function after the register-handler was executed. In this case we will draw the grid everytime it did change, or if we assume it did change.

subs.cljs

https://github.com/sveri/omtet/blob/single_player_0.1/src/cljs/de/sveri/omtet/tetris/subs.cljs

Here you find the subcriptions for every time a specified app state changes.

tetriminios.cljs

https://github.com/sveri/omtet/blob/single_player_0.1/src/cljs/de/sveri/omtet/tetris/tetriminios.cljs

And here you can find the business logic for the tetris related stuff.

Tags: tetris clojuresrcipt