SlideShare a Scribd company logo
1 of 41
Download to read offline
ENJOYABLEFRONT-END DEVELOPMENT
WITH
REAGENT
@TH1AGOFM
@TH1AGOFM
@TH1AGOFM
A tale of excitement in Clojure
@TH1AGOFM
~2010
1.2
1 (defn factorial
2 ([n]
3 (factorial n 1))
4 ([n acc]
5 (if (= n 0) acc
6 (recur (dec n) (* acc n)))))
got inspired by the beauty of a factorial
implementation.
( )
@TH1AGOFM
Hped
@TH1AGOFM
got hyped by node.js and completely
forgot about clojure for a while
@TH1AGOFM
2013
(datomic: an awesome database)
Hped
@TH1AGOFM
hyped by elixir
@TH1AGOFM
2014
CLJS
FINALLY!
hyped by david nolen's talk about cljs
and Om, but felt it was too hard, so
tried reagent and enjoyed it!
@TH1AGOFM
KILLER APP FOR
CLOJURE
WHAT I WAS LOOKING FOR?
@TH1AGOFM
ENJOYMENT.
WHAT I’VE GOT INSTEAD:
Reagent(or Om) have to mature way
more to be a killer app, for this we
need a nice community around it.

But it’s very enjoyable to work with.
@TH1AGOFM
@TH1AGOFM
“You believe that, by early 2015, ReactJS had won
the JavaScript framework wars and you are curious
about the bigger implications. Is the combination of
reactive programming, functional programming and
immutable data going to completely change
everything? And, if so, what would that look like in
a language that embraces those paradigms?”
— Re-frame (Reagent framework for writing SPAs)
So, in this bold statement by re-frame
you can guess react.js is a great thing.
@TH1AGOFM
WHY REACT?
PROBLEM:
DOM WASN’T CREATED TO CREATE UI’S THAT ARE TOO DYNAMIC.
MOVING 1000 DIVS AROUND TAKES A LOT OF TIME.
SOLUTION:
INSTEAD OF MOVING ALL THOSE 1000 DIVS, ONE BY ONE, WE CAN COMPUTE THE NEW
STATE AND REPLACE IT ALL WITH THIS NEW STATE WITH THE SMALLEST AMOUNT OF
PERMUTATIONS.
1 BIG INSERT VS. 1000 SMALL INSERTS.
Here I show a project called memcached-
manager in angular.js(very old version) that I
do create trying to render 1000 divs/
memcached keys and completely freezing
the browser for a couple of seconds.

This is the problem that React tries to solve.
@TH1AGOFM
WHY REACT?
REACT SOLVES THIS PROBLEM BY
USING SOMETHING CALLED VIRTUAL
DOM.
@TH1AGOFM
THE ANATOMY OF A REACT
COMPONENT
1 React.createClass({
2 getInitialState: function() {
3 return {secondsElapsed: 0};
4 },
5 tick: function() {
6 this.setState({secondsElapsed: this.state.
7 secondsElapsed + 1});
8 },
9 componentDidMount: function() {
10 this.interval = setInterval(this.tick, 1000)
11 ;
12 },
13 componentWillUnmount: function() {
14 clearInterval(this.interval);
15 },
16 render: function() {
17 return (
18 <div>Seconds Elapsed: {this.state.
19 secondsElapsed}<
20 /div>
21 );
22 }
23 });
24
25 React.render(<Timer />, mountNode);
DECLARATIVE,
BUT TONS OF BOILERPLATE.
@TH1AGOFM
REACT ONLY TAKES CARE ABOUT THE V
OF THE MVC. IT’S JUST A LIBRARY.
@TH1AGOFM
SO, IT MAKES SENSE TO USE IT WITH
SOMETHING ELSE…
@TH1AGOFM
clojure(script) has a lot of power to
create powerful dsl’s
react has a declarative way to do
frontend development, is very fast but
have too much boilerplate.
REAGENT
reagent explores this nice spot with
both
@TH1AGOFM
IF YOU KNOW CLOJURE, YOU KNOW
REAGENT. (AND CLOJURESCRIPT)
@TH1AGOFM
IF YOU DON’T, IT’S A GOOD
PLAYGROUND TO BEGIN.
Here I show a demo of a project I wrote
specially for this talk, the demo link is in
the last slides, you can see for yourself.
FIGWHEEL, THE CLJS BROWSER REPL.
figwheel does:

cljs -> js

gives you a browser REPL
Here there’s a video where you see that
you can interact with the frontend you
build through this REPL
@TH1AGOFM
THE 2048 GAME WAS MADE USING THE
REAGENT-TEMPLATE.
(VERY EASY TO SET UP!)
@TH1AGOFM
247 (defn application-layout [rest]
248 [:div {:class "container"}
249 (heading-component)
250 [:p {:class "game-intro"} "Join the numbers
251 and get to the "
252 [:strong "2048 tile!"]]
253 [:div {:class "game-container"}
254 (when @game-over
255 [:div {:class "game-message game-over"}
256 [:p "Game over!" ]
257 [:div {:class "lower"}
258 [:a {:class "retry-button" :href "/"}
259 "Try again"]]])
260 rest]
261 (game-explanation-component)
262 [:hr]
263 (footer-component)])
272 (tile-component)]))







COMPONENTS
Components looks like HTML with
some clojure. Syntax is hiccup style.

Pretty simple.
@TH1AGOFM
COMPONENTS






224
225 (defn game-explanation-component []
226 [:p {:class "game-explanation"}
227 [:strong {:class "important"} "How to play:"]
228 " Use your "
229 [:strong "arrow keys"] " to move the tiles.
230 When two tiles with the same number touch,
231 they "
232 [:strong "merge into one!"]])
233
234 (defn footer-component []
235 [:p "n Created by "
236 [:a {:href "http://gabrielecirulli.com", :
237 target "_blank"} "Gabriele Cirulli."] "
238 Based on "
239 [:a {:href "https://itunes.apple.
240 com/us/app/1024!/id823499224", :target
241 "_blank"} "1024 by Veewo Studio"] " and
242 conceptually similar to "
243 [:a {:href "http://asherv.com/threes/", :
244 target "_blank"} "Threes by Asher
245 Vollmer."]])
246 

html, for real
@TH1AGOFM
TILES COMPONENT














215 (defn tile-component []
216 [:div {:class "tile-container"}
217 (remove nil? (map-indexed
218 (fn[y row-of-tiles]
219 (map-indexed
220 (fn[x tile]
221 (when (> tile 0)
222 [:div {:class (str
223 "tile tile-" tile " tile-position-
224 " (inc x) "-" (inc y))} tile]))
225 row-of-tiles))
226 @tiles))])

















15 (def empty-tiles
16 [[0 0 0 0]
17 [0 0 0 0]
18 [0 0 0 0]
19 [0 0 0 0]])
how does the game display the tiles
@TH1AGOFM
ROUTING
263 (footer-component)])
264
265 ;; -------------------------
266 ;; Pages
267
268 (defn start-game-page []
269 (application-layout
270 [:div
271 (grid-component)
272 (tile-component)]))
273
274 (defn current-page []
275 [:div [(session/get :current-page)]])
276
277 ;; -------------------------
278 ;; Routes
279 (secretary/set-config! :prefix "#")
280 (secretary/defroute "/" []
281 (session/put! :current-page #'start-game-page)
282 )
283
284 ;; -------------------------
285 ;; History
286 ;; must be called after routes have been
287 defined
288 (defn hook-browser-navigation! []
289 (doto (History.)
290 (events/listen
whenever you access /, it calls start-
game-page function.

game uses only this page, so this is
straightforward.
@TH1AGOFM
OK, THIS LOOKS PRETTY STATIC.
HOW DO I CHANGE A COMPONENT STATE?
@TH1AGOFM
(SOMETHING THAT HOLDS STATE)
@TH1AGOFM
247 (defn application-layout [rest]
248 [:div {:class "container"}
249 (heading-component)
250 [:p {:class "game-intro"} "Join the numbers
251 and get to the "
252 [:strong "2048 tile!"]]
253 [:div {:class "game-container"}
254 (when @game-over
255 [:div {:class "game-message game-over"}
256 [:p "Game over!" ]
257 [:div {:class "lower"}
258 [:a {:class "retry-button" :href "/"}
259 "Try again"]]])
260 rest]
261 (game-explanation-component)
262 [:hr]
263 (footer-component)])
272 (tile-component)]))







ATOMS
game-over is a atom/state, and using
the @ means we are reading it’s
content. This is called derefing in clojure

whenever game-over = true, it would
show what is nested inside it. a view
telling the game is over with the option
to retry.
@TH1AGOFM
(R)ATOMS
11
12 ;; -------------------------
13 ;; Definitions
14
15 (def empty-tiles
16 [[0 0 0 0]
17 [0 0 0 0]
18 [0 0 0 0]
19 [0 0 0 0]])
20 (def no-score-addition
21 0)
31
32 ;; -------------------------
33 ;; Atoms
34
35 (defonce score (atom 0))
36 (defonce score-addition (atom 0))
37 (defonce tiles (atom empty-tiles))
38 (defonce game-over (atom false))
39 











here I play with the atoms of the
game, seeing it update in the
browser(right side).

reagent atoms behave exactly as
clojure atoms so you can call swap!
and reset! on them, for more info
about that, read the docs from the
reagent project provided in the last
slide. (pst: it’s easy)
@TH1AGOFM
COMPONENTS + ATOMS = ALL YOU NEED.
not much secret to write the game
beyond that, check the readme of my
version of the game in github how I build
it having subpar clojure skills and
learned some stuff in the way.
@TH1AGOFM
1 React.createClass({
2 getInitialState: function() {
3 return {secondsElapsed: 0};
4 },
5 tick: function() {
6 this.setState({secondsElapsed: this.state.
7 secondsElapsed + 1});
8 },
9 componentDidMount: function() {
10 this.interval = setInterval(this.tick, 1000)
11 ;
12 },
13 componentWillUnmount: function() {
14 clearInterval(this.interval);
15 },
16 render: function() {
17 return (
18 <div>Seconds Elapsed: {this.state.
19 secondsElapsed}<
20 /div>
21 );
22 }
23 });
24
25 React.render(<Timer />, mountNode);
we don’t need that boilerplate, just use
reagent :)
@TH1AGOFM
IS MAGIC
@TH1AGOFM
THAT’S ALL FOLKS!
READ THE GUIDE:
http://reagent-project.github.io
USE THE TEMPLATE:
https://github.com/reagent-project/reagent-template
CHECK THE COOKBOOKS:
https://github.com/reagent-project/reagent-cookbook
MAKE YOUR OWN 2048:
https://github.com/thiagofm/reagent-2048
&& HAVE FUN!
shoot me an e-mail if you play with it
and have some kind of trouble,
thiagown@gmail.com

thanks!

More Related Content

What's hot

Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in JavaDoug Hawkins
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185Mahmoud Samir Fayed
 
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)mmisono
 
E-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server AttacksE-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server Attacksphanleson
 
Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?tvaleev
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Chih-Hsuan Kuo
 
How To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification SystemHow To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification SystemJay Corrales
 
From Zero to Application Delivery with NixOS
From Zero to Application Delivery with NixOSFrom Zero to Application Delivery with NixOS
From Zero to Application Delivery with NixOSSusan Potter
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoChih-Hsuan Kuo
 
communication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualcommunication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualamirhosseinozgoli
 
Cinemàtica directa e inversa de manipulador
Cinemàtica directa e inversa de manipuladorCinemàtica directa e inversa de manipulador
Cinemàtica directa e inversa de manipuladorc3stor
 
How to recover malare assembly codes
How to recover malare assembly codesHow to recover malare assembly codes
How to recover malare assembly codesFACE
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31Mahmoud Samir Fayed
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語Kiyotaka Oku
 
The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88Mahmoud Samir Fayed
 
Concurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfConcurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfDenys Goldiner
 

What's hot (20)

Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in Java
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
 
E-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server AttacksE-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server Attacks
 
Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
How To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification SystemHow To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification System
 
From Zero to Application Delivery with NixOS
From Zero to Application Delivery with NixOSFrom Zero to Application Delivery with NixOS
From Zero to Application Delivery with NixOS
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
communication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualcommunication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manual
 
Cinemàtica directa e inversa de manipulador
Cinemàtica directa e inversa de manipuladorCinemàtica directa e inversa de manipulador
Cinemàtica directa e inversa de manipulador
 
How to recover malare assembly codes
How to recover malare assembly codesHow to recover malare assembly codes
How to recover malare assembly codes
 
Gilat_ch05.pdf
Gilat_ch05.pdfGilat_ch05.pdf
Gilat_ch05.pdf
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
 
The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88
 
Concurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfConcurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdf
 
bluespec talk
bluespec talkbluespec talk
bluespec talk
 
Explain this!
Explain this!Explain this!
Explain this!
 

Viewers also liked

The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...
The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...
The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...Search Engine Land
 
Oh CSS! - 5 Quick Things
Oh CSS! - 5 Quick ThingsOh CSS! - 5 Quick Things
Oh CSS! - 5 Quick ThingsVishu Singh
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programmingExotel
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentMaty Fedak
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in ClojureTroy Miles
 
Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)Lifeparticle
 
The Truth About: Black People and Their Place in World History, by Dr. Leroy ...
The Truth About: Black People and Their Place in World History, by Dr. Leroy ...The Truth About: Black People and Their Place in World History, by Dr. Leroy ...
The Truth About: Black People and Their Place in World History, by Dr. Leroy ...RBG Communiversity
 
Why Game Developers Should Care About HTML5
Why Game Developers Should Care About HTML5Why Game Developers Should Care About HTML5
Why Game Developers Should Care About HTML5Bramus Van Damme
 
Top 15 Expert Tech Predictions for 2015
Top 15 Expert Tech Predictions for 2015Top 15 Expert Tech Predictions for 2015
Top 15 Expert Tech Predictions for 2015Experts Exchange
 
Building offline web applications
Building offline web applicationsBuilding offline web applications
Building offline web applicationsThoughtworks
 
The Future of Wearable Fitness
The Future of Wearable FitnessThe Future of Wearable Fitness
The Future of Wearable FitnessAnne Chen
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaCODE WHITE GmbH
 
Understanding Information Architecture
Understanding Information ArchitectureUnderstanding Information Architecture
Understanding Information ArchitectureDan Klyn
 
Internet Hall of Fame: Things to Know about the World of Internet Companies
Internet Hall of Fame: Things to Know about the World of Internet CompaniesInternet Hall of Fame: Things to Know about the World of Internet Companies
Internet Hall of Fame: Things to Know about the World of Internet CompaniesWorld Startup Report
 
Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015
Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015
Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015Sara Lerén
 
3D 프린터 종류와 특징에 관한 리포트
3D 프린터 종류와 특징에 관한 리포트3D 프린터 종류와 특징에 관한 리포트
3D 프린터 종류와 특징에 관한 리포트규호 이
 

Viewers also liked (20)

The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...
The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...
The Growth of Google Direct Answers - A Dreamforce14 Presentation by Danny Su...
 
Oh CSS! - 5 Quick Things
Oh CSS! - 5 Quick ThingsOh CSS! - 5 Quick Things
Oh CSS! - 5 Quick Things
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programming
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)
 
The Truth About: Black People and Their Place in World History, by Dr. Leroy ...
The Truth About: Black People and Their Place in World History, by Dr. Leroy ...The Truth About: Black People and Their Place in World History, by Dr. Leroy ...
The Truth About: Black People and Their Place in World History, by Dr. Leroy ...
 
Reagents
ReagentsReagents
Reagents
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
Why Game Developers Should Care About HTML5
Why Game Developers Should Care About HTML5Why Game Developers Should Care About HTML5
Why Game Developers Should Care About HTML5
 
Top 15 Expert Tech Predictions for 2015
Top 15 Expert Tech Predictions for 2015Top 15 Expert Tech Predictions for 2015
Top 15 Expert Tech Predictions for 2015
 
Building offline web applications
Building offline web applicationsBuilding offline web applications
Building offline web applications
 
The Future of Wearable Fitness
The Future of Wearable FitnessThe Future of Wearable Fitness
The Future of Wearable Fitness
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in Java
 
Understanding Information Architecture
Understanding Information ArchitectureUnderstanding Information Architecture
Understanding Information Architecture
 
Internet Hall of Fame: Things to Know about the World of Internet Companies
Internet Hall of Fame: Things to Know about the World of Internet CompaniesInternet Hall of Fame: Things to Know about the World of Internet Companies
Internet Hall of Fame: Things to Know about the World of Internet Companies
 
Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015
Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015
Impact-driven Scrum Delivery at Scrum gathering Phoenix 2015
 
Barely Enough Design
Barely Enough DesignBarely Enough Design
Barely Enough Design
 
Is your data on the cloud at risk?
Is your data on the cloud at risk?Is your data on the cloud at risk?
Is your data on the cloud at risk?
 
3D 프린터 종류와 특징에 관한 리포트
3D 프린터 종류와 특징에 관한 리포트3D 프린터 종류와 특징에 관한 리포트
3D 프린터 종류와 특징에 관한 리포트
 

Similar to Enjoyable Front-end Development with Reagent

The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210Mahmoud Samir Fayed
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon RunMaja Kraljič
 
Throttle and Debounce Patterns in Web Apps
Throttle and Debounce Patterns in Web AppsThrottle and Debounce Patterns in Web Apps
Throttle and Debounce Patterns in Web AppsAlmir Filho
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184Mahmoud Samir Fayed
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon runMaja Kraljič
 
Obscure Go Optimisations
Obscure Go OptimisationsObscure Go Optimisations
Obscure Go OptimisationsBryan Boreham
 
Just in time (series) - KairosDB
Just in time (series) - KairosDBJust in time (series) - KairosDB
Just in time (series) - KairosDBVictor Anjos
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded ProgrammingSri Prasanna
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with SpockAlexander Tarlinder
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupBadoo Development
 
Do snow.rwn
Do snow.rwnDo snow.rwn
Do snow.rwnARUN DN
 
The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196Mahmoud Samir Fayed
 
Introduction to Cassandra
Introduction to CassandraIntroduction to Cassandra
Introduction to CassandraGokhan Atil
 
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and GasUsing Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and GasSorin Peste
 
Tensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentTensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentjeongok1
 
Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaRobot Media
 

Similar to Enjoyable Front-end Development with Reagent (20)

The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
 
Throttle and Debounce Patterns in Web Apps
Throttle and Debounce Patterns in Web AppsThrottle and Debounce Patterns in Web Apps
Throttle and Debounce Patterns in Web Apps
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
Obscure Go Optimisations
Obscure Go OptimisationsObscure Go Optimisations
Obscure Go Optimisations
 
Just in time (series) - KairosDB
Just in time (series) - KairosDBJust in time (series) - KairosDB
Just in time (series) - KairosDB
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with Spock
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
Do snow.rwn
Do snow.rwnDo snow.rwn
Do snow.rwn
 
The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196
 
Introduction to Cassandra
Introduction to CassandraIntroduction to Cassandra
Introduction to Cassandra
 
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and GasUsing Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and Gas
 
ECMAScript 2015 Tips & Traps
ECMAScript 2015 Tips & TrapsECMAScript 2015 Tips & Traps
ECMAScript 2015 Tips & Traps
 
D3.js workshop
D3.js workshopD3.js workshop
D3.js workshop
 
Tensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentTensor flow description of ML Lab. document
Tensor flow description of ML Lab. document
 
Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon Galicia
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

Enjoyable Front-end Development with Reagent

  • 4. A tale of excitement in Clojure
  • 6. 1 (defn factorial 2 ([n] 3 (factorial n 1)) 4 ([n acc] 5 (if (= n 0) acc 6 (recur (dec n) (* acc n))))) got inspired by the beauty of a factorial implementation.
  • 8. Hped @TH1AGOFM got hyped by node.js and completely forgot about clojure for a while
  • 11. @TH1AGOFM 2014 CLJS FINALLY! hyped by david nolen's talk about cljs and Om, but felt it was too hard, so tried reagent and enjoyed it!
  • 13. @TH1AGOFM ENJOYMENT. WHAT I’VE GOT INSTEAD: Reagent(or Om) have to mature way more to be a killer app, for this we need a nice community around it. But it’s very enjoyable to work with.
  • 15. @TH1AGOFM “You believe that, by early 2015, ReactJS had won the JavaScript framework wars and you are curious about the bigger implications. Is the combination of reactive programming, functional programming and immutable data going to completely change everything? And, if so, what would that look like in a language that embraces those paradigms?” — Re-frame (Reagent framework for writing SPAs) So, in this bold statement by re-frame you can guess react.js is a great thing.
  • 16. @TH1AGOFM WHY REACT? PROBLEM: DOM WASN’T CREATED TO CREATE UI’S THAT ARE TOO DYNAMIC. MOVING 1000 DIVS AROUND TAKES A LOT OF TIME. SOLUTION: INSTEAD OF MOVING ALL THOSE 1000 DIVS, ONE BY ONE, WE CAN COMPUTE THE NEW STATE AND REPLACE IT ALL WITH THIS NEW STATE WITH THE SMALLEST AMOUNT OF PERMUTATIONS. 1 BIG INSERT VS. 1000 SMALL INSERTS.
  • 17. Here I show a project called memcached- manager in angular.js(very old version) that I do create trying to render 1000 divs/ memcached keys and completely freezing the browser for a couple of seconds. This is the problem that React tries to solve.
  • 18. @TH1AGOFM WHY REACT? REACT SOLVES THIS PROBLEM BY USING SOMETHING CALLED VIRTUAL DOM.
  • 19. @TH1AGOFM THE ANATOMY OF A REACT COMPONENT 1 React.createClass({ 2 getInitialState: function() { 3 return {secondsElapsed: 0}; 4 }, 5 tick: function() { 6 this.setState({secondsElapsed: this.state. 7 secondsElapsed + 1}); 8 }, 9 componentDidMount: function() { 10 this.interval = setInterval(this.tick, 1000) 11 ; 12 }, 13 componentWillUnmount: function() { 14 clearInterval(this.interval); 15 }, 16 render: function() { 17 return ( 18 <div>Seconds Elapsed: {this.state. 19 secondsElapsed}< 20 /div> 21 ); 22 } 23 }); 24 25 React.render(<Timer />, mountNode); DECLARATIVE, BUT TONS OF BOILERPLATE.
  • 20. @TH1AGOFM REACT ONLY TAKES CARE ABOUT THE V OF THE MVC. IT’S JUST A LIBRARY.
  • 21. @TH1AGOFM SO, IT MAKES SENSE TO USE IT WITH SOMETHING ELSE…
  • 22. @TH1AGOFM clojure(script) has a lot of power to create powerful dsl’s react has a declarative way to do frontend development, is very fast but have too much boilerplate. REAGENT reagent explores this nice spot with both
  • 23. @TH1AGOFM IF YOU KNOW CLOJURE, YOU KNOW REAGENT. (AND CLOJURESCRIPT)
  • 24. @TH1AGOFM IF YOU DON’T, IT’S A GOOD PLAYGROUND TO BEGIN.
  • 25. Here I show a demo of a project I wrote specially for this talk, the demo link is in the last slides, you can see for yourself.
  • 26. FIGWHEEL, THE CLJS BROWSER REPL. figwheel does: cljs -> js gives you a browser REPL
  • 27. Here there’s a video where you see that you can interact with the frontend you build through this REPL
  • 28. @TH1AGOFM THE 2048 GAME WAS MADE USING THE REAGENT-TEMPLATE. (VERY EASY TO SET UP!)
  • 29. @TH1AGOFM 247 (defn application-layout [rest] 248 [:div {:class "container"} 249 (heading-component) 250 [:p {:class "game-intro"} "Join the numbers 251 and get to the " 252 [:strong "2048 tile!"]] 253 [:div {:class "game-container"} 254 (when @game-over 255 [:div {:class "game-message game-over"} 256 [:p "Game over!" ] 257 [:div {:class "lower"} 258 [:a {:class "retry-button" :href "/"} 259 "Try again"]]]) 260 rest] 261 (game-explanation-component) 262 [:hr] 263 (footer-component)]) 272 (tile-component)]))
 
 
 
 COMPONENTS Components looks like HTML with some clojure. Syntax is hiccup style. Pretty simple.
  • 30. @TH1AGOFM COMPONENTS 
 
 
 224 225 (defn game-explanation-component [] 226 [:p {:class "game-explanation"} 227 [:strong {:class "important"} "How to play:"] 228 " Use your " 229 [:strong "arrow keys"] " to move the tiles. 230 When two tiles with the same number touch, 231 they " 232 [:strong "merge into one!"]]) 233 234 (defn footer-component [] 235 [:p "n Created by " 236 [:a {:href "http://gabrielecirulli.com", : 237 target "_blank"} "Gabriele Cirulli."] " 238 Based on " 239 [:a {:href "https://itunes.apple. 240 com/us/app/1024!/id823499224", :target 241 "_blank"} "1024 by Veewo Studio"] " and 242 conceptually similar to " 243 [:a {:href "http://asherv.com/threes/", : 244 target "_blank"} "Threes by Asher 245 Vollmer."]]) 246 
 html, for real
  • 31. @TH1AGOFM TILES COMPONENT 
 
 
 
 
 
 
 215 (defn tile-component [] 216 [:div {:class "tile-container"} 217 (remove nil? (map-indexed 218 (fn[y row-of-tiles] 219 (map-indexed 220 (fn[x tile] 221 (when (> tile 0) 222 [:div {:class (str 223 "tile tile-" tile " tile-position- 224 " (inc x) "-" (inc y))} tile])) 225 row-of-tiles)) 226 @tiles))])
 
 
 
 
 
 
 
 
 15 (def empty-tiles 16 [[0 0 0 0] 17 [0 0 0 0] 18 [0 0 0 0] 19 [0 0 0 0]]) how does the game display the tiles
  • 32. @TH1AGOFM ROUTING 263 (footer-component)]) 264 265 ;; ------------------------- 266 ;; Pages 267 268 (defn start-game-page [] 269 (application-layout 270 [:div 271 (grid-component) 272 (tile-component)])) 273 274 (defn current-page [] 275 [:div [(session/get :current-page)]]) 276 277 ;; ------------------------- 278 ;; Routes 279 (secretary/set-config! :prefix "#") 280 (secretary/defroute "/" [] 281 (session/put! :current-page #'start-game-page) 282 ) 283 284 ;; ------------------------- 285 ;; History 286 ;; must be called after routes have been 287 defined 288 (defn hook-browser-navigation! [] 289 (doto (History.) 290 (events/listen whenever you access /, it calls start- game-page function. game uses only this page, so this is straightforward.
  • 33. @TH1AGOFM OK, THIS LOOKS PRETTY STATIC. HOW DO I CHANGE A COMPONENT STATE?
  • 35. @TH1AGOFM 247 (defn application-layout [rest] 248 [:div {:class "container"} 249 (heading-component) 250 [:p {:class "game-intro"} "Join the numbers 251 and get to the " 252 [:strong "2048 tile!"]] 253 [:div {:class "game-container"} 254 (when @game-over 255 [:div {:class "game-message game-over"} 256 [:p "Game over!" ] 257 [:div {:class "lower"} 258 [:a {:class "retry-button" :href "/"} 259 "Try again"]]]) 260 rest] 261 (game-explanation-component) 262 [:hr] 263 (footer-component)]) 272 (tile-component)]))
 
 
 
 ATOMS game-over is a atom/state, and using the @ means we are reading it’s content. This is called derefing in clojure whenever game-over = true, it would show what is nested inside it. a view telling the game is over with the option to retry.
  • 36. @TH1AGOFM (R)ATOMS 11 12 ;; ------------------------- 13 ;; Definitions 14 15 (def empty-tiles 16 [[0 0 0 0] 17 [0 0 0 0] 18 [0 0 0 0] 19 [0 0 0 0]]) 20 (def no-score-addition 21 0) 31 32 ;; ------------------------- 33 ;; Atoms 34 35 (defonce score (atom 0)) 36 (defonce score-addition (atom 0)) 37 (defonce tiles (atom empty-tiles)) 38 (defonce game-over (atom false)) 39 
 
 
 
 
 

  • 37. here I play with the atoms of the game, seeing it update in the browser(right side). reagent atoms behave exactly as clojure atoms so you can call swap! and reset! on them, for more info about that, read the docs from the reagent project provided in the last slide. (pst: it’s easy)
  • 38. @TH1AGOFM COMPONENTS + ATOMS = ALL YOU NEED. not much secret to write the game beyond that, check the readme of my version of the game in github how I build it having subpar clojure skills and learned some stuff in the way.
  • 39. @TH1AGOFM 1 React.createClass({ 2 getInitialState: function() { 3 return {secondsElapsed: 0}; 4 }, 5 tick: function() { 6 this.setState({secondsElapsed: this.state. 7 secondsElapsed + 1}); 8 }, 9 componentDidMount: function() { 10 this.interval = setInterval(this.tick, 1000) 11 ; 12 }, 13 componentWillUnmount: function() { 14 clearInterval(this.interval); 15 }, 16 render: function() { 17 return ( 18 <div>Seconds Elapsed: {this.state. 19 secondsElapsed}< 20 /div> 21 ); 22 } 23 }); 24 25 React.render(<Timer />, mountNode); we don’t need that boilerplate, just use reagent :)
  • 41. @TH1AGOFM THAT’S ALL FOLKS! READ THE GUIDE: http://reagent-project.github.io USE THE TEMPLATE: https://github.com/reagent-project/reagent-template CHECK THE COOKBOOKS: https://github.com/reagent-project/reagent-cookbook MAKE YOUR OWN 2048: https://github.com/thiagofm/reagent-2048 && HAVE FUN! shoot me an e-mail if you play with it and have some kind of trouble, thiagown@gmail.com thanks!