SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
OM (CONT.)
@TAKUFUKUSHIMA
PRISMATIC
OM SWEET OM: (HIGH-)FUNCTIONAL
FRONTEND ENGINEERING WITH
CLOJURESCRIPT AND REACT
CONCLUSION:
SIMPLICITY WINS
PLUMBING
OM-TOOLS
THE REGULAR OM COMPNENTS ARE
VERBOSE
(defn topology-viewer [app owner]
(reify
om/IRender
(render [_]
(dom/div
(dom/svg #js {:width 200 :height 200
:style {:backgoundColor "grey"}}
(dom/circle #js {:cx 30 :cy 30 :r 25 :stroke "grey"
:strokeWidth 1 :fill "wheat"})
(dom/rect #js {:width 50 :height 50 :x 60 :y 10
:style {:fill "red" :stroke "black"
:strokeWidth 5 :opacity 0.5}})))))
OM-TOOLS PROVIDES USEFUL MACROS
(defcomponent topology-viewer [app owner]
(render [_]
(dom/div
(dom/svg {:width 200 :height 200
:style {:backgound-color "grey"}}
(dom/circle {:cx 30 :cy 30 :r 25 :stroke "grey"
:stroke-width 1 :fill "wheat"})
(dom/rect {:width 50 :height 50 :x 60 :y 10
:style {:fill "red" :stroke "black"
:stroke-width 5 :opacity 0.5}})))))
DATASCRIPT
AN IMMUTABLE IN-MEMORY
DATABASE AND DATALOG QUERY
ENGINE IN CLOJURESCRIPT.
DATOMIC
DATALOG
(require '[datascript :as d])
;; Implicit join, multi-valued attribute
(let [schema {:aka {:db/cardinality :db.cardinality/many}}
conn (d/create-conn schema)]
(d/transact! conn [ { :db/id -1
:name "Maksim"
:age 45
:aka ["Maks Otto von Stirlitz", "Jack Ryan"] } ])
(d/q '[ :find ?n ?a
:where [?e :aka "Maks Otto von Stirlitz"]
[?e :name ?n]
[?e :age ?a] ]
@conn))
;; => #{ ["Maksim" 45] }
(d/q '[ :find ?k ?x
:in [[?k [?min ?max]] ...] ?range
:where [(?range ?min ?max) [?x ...]]
[(even? ?x)] ]
{ :a [1 7], :b [2 4] }
range)
;; => #{ [:a 2] [:a 4] [:a 6] [:b 2] }
;; Recursive rule
(d/q '[ :find ?u1 ?u2
:in $ %
:where (follows ?u1 ?u2) ]
[ [1 :follows 2]
[2 :follows 3]
[3 :follows 4] ]
'[ [(follows ?e1 ?e2)
[?e1 :follows ?e2]]
[(follows ?e1 ?e2)
[?e1 :follows ?t]
(follows ?t ?e2)] ])
;; => #{ [1 2] [1 3] [1 4]
;; [2 3] [2 4]
;; [3 4] }
;; Aggregates
(d/q '[ :find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount ]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
3)
;; => [[:red [30 40 50] [10 20 30]]
;; [:blue [7 8] [7 8]]]
FLIGHTDECK
GOAL: CREATE AN IN
MEMORY QUERYABLE
DB FROM THE REST API
RETRIEVE JSON DATA RECURSIVELY
;; Retrieve endpoints for resources
(defn- build-db-helper [conn endpoint]
(let [done (go
(let [res (<! (http/get endpoint {:with-credentials? false}))
rs (json-decode (res :body))]
(if (not (nil? rs))
(d/transact! conn rs))
(doseq [r rs
[k v] r :when (valid-resource? k v)]
(<! (build-db-helper conn v)))))]
done))
BUILD IN-MEMORY DATABASE
POPULATING DATA RETRIEVED FROM
THE API SERVER
(defn build-db [root]
(let [schema {}
conn (d/create-conn schema)
c (chan)
db (chan)]
;; Prevent cursor-ification. Borrowed from the following page:
;; https://gist.github.com/swannodette/11308901
(extend-type d/DB
om/IToCursor
(-to-cursor
([this _] this)
([this _ _] this)))
...))
(go
(let [res (<! (http/get root {:with-credentials? false}))]
(reset! api-endpoints (json-decode (res :body)))
(>! c @api-endpoints)))
(let [db-init (chan)]
(go
(let [endpoints (<! c)
ks (for [[k v] endpoints
:when (valid-resource? k v)] k)
m (select-keys endpoints ks)]
(doseq [[k v] m] (<! (build-db-helper conn v)))
(>! db-init :ok)))
(go
(log :info "waiting for the db initialized...")
(<! db-init)
(log :info "done.")
(prn (d/q '[:find ?id ?rid
:where
[_ :id ?id]]
@conn))
(>! db @conn)))
THE END OF
SLIDES; ANY
QUESTION?
REFERENCES
▸ Prismatic: http://getprismatic.com/home
▸ Om sweet Om: (high-)functional frontend engineering
with ClojureScript and React: http://
blog.getprismatic.com/om-sweet-om-high-functional-
frontend-engineering-with-clojurescript-and-react/
▸ Prismatic/schema https://github.com/Prismatic/
schema
REFERENCES
▸ Prismatic/plumbing https://github.com/prismatic/
plumbing
▸ Prismatic/om-tools https://github.com/Prismatic/
om-tools
▸ tonsky/datascript https://github.com/tonsky/
datascript
REFERENCES
▸ Unofficial guide to Datomic internals http://
tonsky.me/blog/unofficial-guide-to-datomic-
internals/
Other pictures are distributed under © Taku Fukushima

Mais conteúdo relacionado

Mais procurados

20090622 Vimm4
20090622 Vimm420090622 Vimm4
20090622 Vimm4
id774
 

Mais procurados (15)

Sol10
Sol10Sol10
Sol10
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
20090622 Vimm4
20090622 Vimm420090622 Vimm4
20090622 Vimm4
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
 
1
11
1
 
Rumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai PersamaanRumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai Persamaan
 
Coding with Vim
Coding with VimCoding with Vim
Coding with Vim
 
Schema Design by Chad Tindel, Solution Architect, 10gen
Schema Design  by Chad Tindel, Solution Architect, 10genSchema Design  by Chad Tindel, Solution Architect, 10gen
Schema Design by Chad Tindel, Solution Architect, 10gen
 
Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.
 
XIX PUG-PE - Pygame game development
XIX PUG-PE - Pygame game developmentXIX PUG-PE - Pygame game development
XIX PUG-PE - Pygame game development
 
openCypher: Technology Compatibility Kit (TCK) and Vendor Extensions
openCypher: Technology Compatibility Kit (TCK) and Vendor ExtensionsopenCypher: Technology Compatibility Kit (TCK) and Vendor Extensions
openCypher: Technology Compatibility Kit (TCK) and Vendor Extensions
 
Vcs23
Vcs23Vcs23
Vcs23
 
Program to sort array using insertion sort
Program to sort array using insertion sortProgram to sort array using insertion sort
Program to sort array using insertion sort
 

Semelhante a Om (Cont.)

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Semelhante a Om (Cont.) (20)

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
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
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
A Tour of Building Web Applications with R Shiny
A Tour of Building Web Applications with R Shiny A Tour of Building Web Applications with R Shiny
A Tour of Building Web Applications with R Shiny
 
R programming language
R programming languageR programming language
R programming language
 
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
 
Big Data Analytics with Scala at SCALA.IO 2013
Big Data Analytics with Scala at SCALA.IO 2013Big Data Analytics with Scala at SCALA.IO 2013
Big Data Analytics with Scala at SCALA.IO 2013
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Anthony Starks - deck
Anthony Starks - deckAnthony Starks - deck
Anthony Starks - deck
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Deck: A Go Package for Presentations
Deck: A Go Package for PresentationsDeck: A Go Package for Presentations
Deck: A Go Package for Presentations
 
Generic Functional Programming with Type Classes
Generic Functional Programming with Type ClassesGeneric Functional Programming with Type Classes
Generic Functional Programming with Type Classes
 
20151224-games
20151224-games20151224-games
20151224-games
 

Mais de Taku Fukushima (7)

Container Orchestration Integration: OpenStack Kuryr
Container Orchestration Integration: OpenStack KuryrContainer Orchestration Integration: OpenStack Kuryr
Container Orchestration Integration: OpenStack Kuryr
 
rtnetlink
rtnetlinkrtnetlink
rtnetlink
 
Introduction to MidoNet
Introduction to MidoNetIntroduction to MidoNet
Introduction to MidoNet
 
MidoNet deep dive
MidoNet deep diveMidoNet deep dive
MidoNet deep dive
 
Gunosy.go#7 reflect
Gunosy.go#7 reflectGunosy.go#7 reflect
Gunosy.go#7 reflect
 
Om
OmOm
Om
 
Gunosy.go #4 go
Gunosy.go #4 goGunosy.go #4 go
Gunosy.go #4 go
 

Último

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Último (20)

HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 

Om (Cont.)

  • 3. OM SWEET OM: (HIGH-)FUNCTIONAL FRONTEND ENGINEERING WITH CLOJURESCRIPT AND REACT
  • 5.
  • 6.
  • 9. THE REGULAR OM COMPNENTS ARE VERBOSE (defn topology-viewer [app owner] (reify om/IRender (render [_] (dom/div (dom/svg #js {:width 200 :height 200 :style {:backgoundColor "grey"}} (dom/circle #js {:cx 30 :cy 30 :r 25 :stroke "grey" :strokeWidth 1 :fill "wheat"}) (dom/rect #js {:width 50 :height 50 :x 60 :y 10 :style {:fill "red" :stroke "black" :strokeWidth 5 :opacity 0.5}})))))
  • 10. OM-TOOLS PROVIDES USEFUL MACROS (defcomponent topology-viewer [app owner] (render [_] (dom/div (dom/svg {:width 200 :height 200 :style {:backgound-color "grey"}} (dom/circle {:cx 30 :cy 30 :r 25 :stroke "grey" :stroke-width 1 :fill "wheat"}) (dom/rect {:width 50 :height 50 :x 60 :y 10 :style {:fill "red" :stroke "black" :stroke-width 5 :opacity 0.5}})))))
  • 12. AN IMMUTABLE IN-MEMORY DATABASE AND DATALOG QUERY ENGINE IN CLOJURESCRIPT.
  • 13.
  • 15.
  • 17. (require '[datascript :as d]) ;; Implicit join, multi-valued attribute (let [schema {:aka {:db/cardinality :db.cardinality/many}} conn (d/create-conn schema)] (d/transact! conn [ { :db/id -1 :name "Maksim" :age 45 :aka ["Maks Otto von Stirlitz", "Jack Ryan"] } ]) (d/q '[ :find ?n ?a :where [?e :aka "Maks Otto von Stirlitz"] [?e :name ?n] [?e :age ?a] ] @conn)) ;; => #{ ["Maksim" 45] }
  • 18. (d/q '[ :find ?k ?x :in [[?k [?min ?max]] ...] ?range :where [(?range ?min ?max) [?x ...]] [(even? ?x)] ] { :a [1 7], :b [2 4] } range) ;; => #{ [:a 2] [:a 4] [:a 6] [:b 2] }
  • 19. ;; Recursive rule (d/q '[ :find ?u1 ?u2 :in $ % :where (follows ?u1 ?u2) ] [ [1 :follows 2] [2 :follows 3] [3 :follows 4] ] '[ [(follows ?e1 ?e2) [?e1 :follows ?e2]] [(follows ?e1 ?e2) [?e1 :follows ?t] (follows ?t ?e2)] ]) ;; => #{ [1 2] [1 3] [1 4] ;; [2 3] [2 4] ;; [3 4] }
  • 20. ;; Aggregates (d/q '[ :find ?color (max ?amount ?x) (min ?amount ?x) :in [[?color ?x]] ?amount ] [[:red 10] [:red 20] [:red 30] [:red 40] [:red 50] [:blue 7] [:blue 8]] 3) ;; => [[:red [30 40 50] [10 20 30]] ;; [:blue [7 8] [7 8]]]
  • 22. GOAL: CREATE AN IN MEMORY QUERYABLE DB FROM THE REST API
  • 23. RETRIEVE JSON DATA RECURSIVELY ;; Retrieve endpoints for resources (defn- build-db-helper [conn endpoint] (let [done (go (let [res (<! (http/get endpoint {:with-credentials? false})) rs (json-decode (res :body))] (if (not (nil? rs)) (d/transact! conn rs)) (doseq [r rs [k v] r :when (valid-resource? k v)] (<! (build-db-helper conn v)))))] done))
  • 24. BUILD IN-MEMORY DATABASE POPULATING DATA RETRIEVED FROM THE API SERVER (defn build-db [root] (let [schema {} conn (d/create-conn schema) c (chan) db (chan)] ;; Prevent cursor-ification. Borrowed from the following page: ;; https://gist.github.com/swannodette/11308901 (extend-type d/DB om/IToCursor (-to-cursor ([this _] this) ([this _ _] this))) ...))
  • 25. (go (let [res (<! (http/get root {:with-credentials? false}))] (reset! api-endpoints (json-decode (res :body))) (>! c @api-endpoints))) (let [db-init (chan)] (go (let [endpoints (<! c) ks (for [[k v] endpoints :when (valid-resource? k v)] k) m (select-keys endpoints ks)] (doseq [[k v] m] (<! (build-db-helper conn v))) (>! db-init :ok))) (go (log :info "waiting for the db initialized...") (<! db-init) (log :info "done.") (prn (d/q '[:find ?id ?rid :where [_ :id ?id]] @conn)) (>! db @conn)))
  • 26. THE END OF SLIDES; ANY QUESTION?
  • 27. REFERENCES ▸ Prismatic: http://getprismatic.com/home ▸ Om sweet Om: (high-)functional frontend engineering with ClojureScript and React: http:// blog.getprismatic.com/om-sweet-om-high-functional- frontend-engineering-with-clojurescript-and-react/ ▸ Prismatic/schema https://github.com/Prismatic/ schema
  • 28. REFERENCES ▸ Prismatic/plumbing https://github.com/prismatic/ plumbing ▸ Prismatic/om-tools https://github.com/Prismatic/ om-tools ▸ tonsky/datascript https://github.com/tonsky/ datascript
  • 29. REFERENCES ▸ Unofficial guide to Datomic internals http:// tonsky.me/blog/unofficial-guide-to-datomic- internals/ Other pictures are distributed under © Taku Fukushima