Book Image

Clojure Reactive Programming

Book Image

Clojure Reactive Programming

Overview of this book

Table of Contents (19 chapters)
Clojure Reactive Programming
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Bibliography
Index

Exercises


In this exercise, we will modify the om-pm project we created in the previous section. The objective is to add keyboard shortcuts so that power users can operate the agile board more efficiently.

The shortcuts to be supported are:

  • The up, down, left, and right arrow keys: These allow the user to navigate through the cards, highlighting the current one

  • The n and p keys: These are used to move the current card to the next (right) or previous (left) column, respectively

The key insight here is to create a new core.async channel, which will contain key press events. These events will then trigger the actions outlined previously. We can use the Google closure library to listen for events. Just add the following require to the application namespace:

(:require [goog.events :as events])

Then, use this function to create a channel from DOM events:

 (defn listen [el type]
  (let [c (chan)]
    (events/listen el type #(put! c %))
    c))

The actual logic of moving the cards around based on keyboard...