Recently at a Clojure Barcelona Developers event, we had a refactoring session in which we introduced Stuart Sierra's component library in a code that was already done: our previous solution to the Lights out kata.
First, we put the code in charge of talking to the back end and updating the lights atom in a separated component, ApiLightsGateway:
Then, we did the same for the lights code which was put in the Lights component:
This component provided a place to create and close the channel we used to communicate
lights data between the Lights and the ApiLightsGateway components.
Next, we used the Lights component from the view code:
And, finally, we put everything together in the lights core name space:
This was a nice practice to learn more about component and what it might take to introduce it in an existing code base.
You can find the code we produced in these two GitHub repositories: the server and the client (see the componentization branch).
You can check the changes we made to componentize the code here (see the commits made on Aug 30, 2016).
As usual it was a great pleasure to do mob programming and learn with the members of Clojure Developers Barcelona.