This is a fork from bhauman's dotster. Dotster is a game implemented in ClojureScript using the Core.async library.
See the blog post explaining the game
This fork contains bug fixes and major code refactors that helps beginner to understand core.async patterns.
- use the latest core.async and clojurescript to make code work
- refactor chan related code into chan module and use go-loop macro.
- refactor render related code into render module.
- misc
To compile:
lein cljsbuild once
open resources/public/dots.html
Rich gave a talk of core.async at InfoQ SF 2013. Following are some philosophies and patterns based on my understanding.
Function call chains are tight coupling. You can not split function calls across web workers. In distributed system, we use rabbitmq or alike to scale up. Here we use CSP style channel to connect in process components.
Event callback cause logic fragmentation because your logic is scattered around inside different event handlers. It is IOC because you have no control when your event handler got called.
Event callback forces pain intimacy due to tight coupling. There are composition problems with event callbacks. Though promise and futures lessen the problem. Callback still hard to reason about and is IOC.
Event handler should be don't do too much event handler.
Event handlers read events from input chan, simple filter or dispatch based on predicates, and put the event data into output channel. After storing event into output channel, event handler returns the output channel. The next stage event handlers will do the same. This eventually creates a chain that connects all components through channels.
With channel, you basic communication is not calling anymore, it is data !!!
We can split the chain and distribute the work across webworkers. Think about it, with today's function call chain, you can not split your call chains across webworkers. With channel, you connect components through data and you can distribute your work across webworkers. Data based communication is easy to distribute, scale, and reason about.
Copyright © 2013
Distributed under the Eclipse Public License, the same as Clojure.