SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
Introduction to
Functional Reactive Web
by John Stevenson
@jr0cket practicalli.github.io/clojurescript
@jr0cket
Speaker, author, conference organiser & community obsessed
developer.
Love Clojure, Emacs, Cats, Cycling & Agile development.
@Heroku
@SalesforceDevs
#Trailhead
In a galaxy far, far away…
Why
Functional Reactive Web
it's not just because it's really fun...
Complex languages
… are simply not
easy to understand
@jr0cket
Josh Smith - Tweet
Original Gif
The Complexity Iceberg
- @krisajenkins
● complexity is very
dangerous when hidden
● You can't know what a
function does for certain if it
has side effects
Side Effects
Pure Functions
The results of the function are purely determined by its initial output and its own code
- no external influence, a function only uses local values
- referential transparency (the function can be replaced by its value)
Impure Functions - side causes
The results of the function are purely determined by its initial output and its own code
- behaviour externally influenced and non-deterministic
Eliminating Side Effects
Functional programming is about eliminating side effects where you can,
controlling them where you can't - @krisajenkins
The features in Functional Programming come from a
desire to reduce side effects
ClojureScript - Functional Web
Immutability & composable functions for Web Apps
jQuery over all JavaScript frameworks
Google Closure tools & libraries
ClojureScript Quickstart
Peeks under the covers of how to build and run Clojurescript generated JavaScript
Getting Started with
Clojurescript
Clojurescript Environments
Nashorn
- built into JVM, access Java classes
- Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM
Browser-REPL
- built into modern browsers (Chrome, Firefox, etc)
- commonly used for client side web apps
Node.js
- great for command line utilities and microservices!
Common Clojurescript Tooling
Figwheel (leiningen plugin)
- defacto tool for client side web apps
- live reload and so much more...
Figwheel-sidecar
- connecting Emacs to figwheel
Full-stack projects: Chestnut
https://github.com/plexus/chestnut
- leiningen template for Clojure/ClojureScript apps based
- with Om, Reagent, or Rum
- instant reloading of Clojure, ClojureScript, and CSS
- browser-connected REPL included
lein new chestnut project-name
Self-hosted Clojurescript Environments
Instant startup times, great for command line tools
Lumo (cross-platform)
- https://github.com/anmonteiro/lumo
Plank (Mac & Linux)
- http://planck-repl.org/
Understanding React
Basic concepts of React
https://facebook.github.io/react/
https://github.com/reactjs
React Basics
React provides an efficient way to update the view
What React Provides
React is only the view
You DO NOT GET any of the following:
An event system (other than vanilla DOM events)
Any AJAX capabilities whatsoever
Any form of a data layer
Promises
Any application framework at all
Any idea how implement the above
How React Works (Simplified)
Your view triggers an event
- a user types a name in a text field
That event updates a model
Then the model triggers an event
And the view responds to that model's event by
re-rendering with the latest data.
This one way data flow / decoupled observer
pattern is designed to guarantee that your source
of truth always stays in your stores / models
JSX
JSX is a preprocessor step that adds XML syntax to JavaScript.
You can definitely use React without JSX but JSX makes React a lot more elegant.
Just like XML, JSX tags have a tag name, attributes, and children.
If an attribute value is enclosed in quotes, the value is a string.
Reactive Frameworks
All the varieties of life, plus all the Javascript varieties too...
Javascript & Clojurescript frameworks
Javascript
● React.js via cljsjs
● Vue.js ???
Clojurescript
● Om / Om-next
● Reagent / Reframe
● Rum
More at https://clojurescript.org/community/libraries
Reagent
Interactive development
Reagent
Reagent provides a minimalistic interface between ClojureScript and React. It allows you to define efficient React components using
nothing but plain ClojureScript functions and data, that describe your UI using a Hiccup-like syntax.
The goal of Reagent is to make it possible to define arbitrarily complex UIs using just a couple of basic concepts, and to be fast
enough by default that you rarely have to care about performance.
Reagent Core functions
reagent.core/render
- Render a Reagent component into the DOM
- First argument is either a vector (Reagent Hiccup syntax) or a React element
reagent.core/atom
- Like clojure.core/atom, plus it tracks components that deref atom & re-renders them
Reagent Helper functions
clj->js
- convert values from clojurescript to javascript
js->clj
- transforms JavaScript arrays into ClojureScript vectors, and JavaScript objects
into ClojureScript maps
Reframe
A micro-framework for Reagent
Reframe
re-frame is a pattern for writing SPAs in ClojureScript, using Reagent.
Being a functional framework, it is about data, and the (pure) functions which
transform that data.
It is a loop
Architecturally, re-frame implements "a perpetual loop".
To build an app, you hang pure functions on certain parts of this loop, and re-frame
looks after the conveyance of data around the loop, into and out of the transforming
functions you provide - hence a tag line of "Derived Values, Flowing".
Om / Om-next
ClojureScript interface to Facebook's React
Om / Om-next
Om allows users to represent their UIs simply as EDN. Because ClojureScript data is immutable data, Om can always rapidly
re-render the UI from the root. Thus Om UIs are out of the box snapshotable and undoable and these operations have no
implementation complexity and little overhead.
See for yourself.
Unique Features
Om supports features not currently present in React:
● Global state management facilities built in
● Components may have arbitrary data dependencies, not limited to props & state
● Component construction can be intercepted via :instrument. Simplifies debugging components and generic editors.
● Provides stream of all application state change deltas via :tx-listen. Simplifies synchronization online and offline.
● Customizable semantics. Fine grained control over how components store state, even for components outside of your control.
Simplifies using Om components outside the Om framework, debugging, and adding event hooks not anticipated by original
component designer.
Om core functions
om.core/IRender
- Render a Om component into the DOM
- uses reify to provide a specific implementation of the om/IRender interface
om.dom/div attributes content
- creates a <div> tag in react
- all react tags need to be wrapped in a div in order to be rendered
- om.dom/… has all the other tags too - h1, h2, p, a … (sablono can be used instead)
#js
- converts clojure maps into Javascript objects
- nest #js functions to to create JS objects - eg. for inline styles
Om Cursors
Cursors are a fundamental part of Om. They let components refer to pieces of
the app state without knowing where they are in the state tree. This makes
updating the app state simple, as the cursor is already pointing to the correct
part of the app state.
cursors are like maps, but cursors also let you write to them
A cursor is an atom & a path to a location in the atom
appstate :entries 0
Rum
A micro-framework for Reagent
Rum
Rum is a client/server library for HTML UI. In ClojureScript, it works as React wrapper, in Clojure, it is a static HTML
generator.
- Simple semantics: Rum is arguably smaller, simpler and more straightforward than React itself.
- Decomplected: Rum is a library, not a framework. Use only the parts you need, throw away or replace what you don’t
need, combine different approaches in a single app, or even combine Rum with other frameworks.
- No enforced state model: Unlike Om, Reagent or Quiescent, Rum does not dictate where to keep your state. Instead, it
works well with any storage: persistent data structures, atoms, DataScript, JavaScript objects, localStorage or any custom
solution you can think of.
- Extensible: the API is stable and explicitly defined, including the API between Rum internals. It lets you build custom
behaviours that change components in significant ways.
- Minimal codebase: You can become a Rum expert just by reading its source code (~900 lines).
ClojureScript Demo
Interactive development
Figwheel (flappy birds example)
Take your own journey into Clojure
@jr0cket
@Heroku
@SalesforceDevs
#Trailhead
In a galaxy far, far away… London, UK
Clojure - Functional Web
Immutability & composable functions for Web Apps
Ring - simplifying communication
Ring takes requests over HTTP and converts them into a map (think JSON)
Ring - creating an embedded server
Compojure - simplifying routing
Compojure routes requests based on path & request type
Compojure - defining routes
Hiccup - html from Clojure
Ring - embedded server & dependencies

Mais conteúdo relacionado

Mais procurados

Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
Keith Bennett
 

Mais procurados (20)

Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
 
Serving QML applications over the network
Serving QML applications over the networkServing QML applications over the network
Serving QML applications over the network
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
A Tour of PostgREST
A Tour of PostgRESTA Tour of PostgREST
A Tour of PostgREST
 
Play framework
Play frameworkPlay framework
Play framework
 
Angular Extreme Performance - V2
Angular Extreme Performance - V2Angular Extreme Performance - V2
Angular Extreme Performance - V2
 
Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.
 
React native
React nativeReact native
React native
 
Vue next
Vue nextVue next
Vue next
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash Course
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
Let's migrate to Swift 3.0
Let's migrate to Swift 3.0Let's migrate to Swift 3.0
Let's migrate to Swift 3.0
 
GWT 2 Is Smarter Than You
GWT 2 Is Smarter Than YouGWT 2 Is Smarter Than You
GWT 2 Is Smarter Than You
 
Functional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix APIFunctional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix API
 
G pars
G parsG pars
G pars
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 

Semelhante a Introduction to Functional Reactive Web with Clojurescript

Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
Ritesh Kumar
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
Flipkart
 

Semelhante a Introduction to Functional Reactive Web with Clojurescript (20)

ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Daniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého SchizmaDaniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého Schizma
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
 
Building reusable components as micro frontends with glimmer js and webcompo...
Building reusable components as micro frontends  with glimmer js and webcompo...Building reusable components as micro frontends  with glimmer js and webcompo...
Building reusable components as micro frontends with glimmer js and webcompo...
 
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
 
React Workshop
React WorkshopReact Workshop
React Workshop
 
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 

Mais de John Stevenson

Mais de John Stevenson (20)

ClojureX Conference 2017 - 10 amazing years of Clojure
ClojureX Conference 2017 - 10 amazing years of ClojureClojureX Conference 2017 - 10 amazing years of Clojure
ClojureX Conference 2017 - 10 amazing years of Clojure
 
Confessions of a developer community builder
Confessions of a developer community builderConfessions of a developer community builder
Confessions of a developer community builder
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
Communication improbable
Communication improbableCommunication improbable
Communication improbable
 
Getting into public speaking at conferences
Getting into public speaking at conferencesGetting into public speaking at conferences
Getting into public speaking at conferences
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojure
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
 
Guiding people into Clojure
Guiding people into ClojureGuiding people into Clojure
Guiding people into Clojure
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
Get Functional Programming with Clojure
Get Functional Programming with ClojureGet Functional Programming with Clojure
Get Functional Programming with Clojure
 
So you want to run a developer event, are you crazy?
So you want to run a developer event, are you crazy?So you want to run a developer event, are you crazy?
So you want to run a developer event, are you crazy?
 
Trailhead live - Overview of Salesforce App Cloud
Trailhead live - Overview of Salesforce App CloudTrailhead live - Overview of Salesforce App Cloud
Trailhead live - Overview of Salesforce App Cloud
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
 
Introducing the Salesforce platform
Introducing the Salesforce platformIntroducing the Salesforce platform
Introducing the Salesforce platform
 
Dreamforce14 Metadata Management with Git Version Control
Dreamforce14 Metadata Management with Git Version ControlDreamforce14 Metadata Management with Git Version Control
Dreamforce14 Metadata Management with Git Version Control
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Salesforce Summer of Hacks London - Introduction
Salesforce Summer of Hacks London - IntroductionSalesforce Summer of Hacks London - Introduction
Salesforce Summer of Hacks London - Introduction
 
Heroku Introduction: Scaling customer facing apps & services
Heroku Introduction: Scaling customer facing apps & servicesHeroku Introduction: Scaling customer facing apps & services
Heroku Introduction: Scaling customer facing apps & services
 
Developers guide to the Salesforce1 Platform
Developers guide to the Salesforce1 PlatformDevelopers guide to the Salesforce1 Platform
Developers guide to the Salesforce1 Platform
 
Developer week EMEA - Salesforce1 Mobile App overview
Developer week EMEA - Salesforce1 Mobile App overviewDeveloper week EMEA - Salesforce1 Mobile App overview
Developer week EMEA - Salesforce1 Mobile App overview
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Introduction to Functional Reactive Web with Clojurescript

  • 1. Introduction to Functional Reactive Web by John Stevenson @jr0cket practicalli.github.io/clojurescript
  • 2. @jr0cket Speaker, author, conference organiser & community obsessed developer. Love Clojure, Emacs, Cats, Cycling & Agile development. @Heroku @SalesforceDevs #Trailhead In a galaxy far, far away…
  • 3. Why Functional Reactive Web it's not just because it's really fun...
  • 4. Complex languages … are simply not easy to understand @jr0cket Josh Smith - Tweet Original Gif
  • 5. The Complexity Iceberg - @krisajenkins ● complexity is very dangerous when hidden ● You can't know what a function does for certain if it has side effects
  • 7. Pure Functions The results of the function are purely determined by its initial output and its own code - no external influence, a function only uses local values - referential transparency (the function can be replaced by its value)
  • 8. Impure Functions - side causes The results of the function are purely determined by its initial output and its own code - behaviour externally influenced and non-deterministic
  • 9. Eliminating Side Effects Functional programming is about eliminating side effects where you can, controlling them where you can't - @krisajenkins The features in Functional Programming come from a desire to reduce side effects
  • 10. ClojureScript - Functional Web Immutability & composable functions for Web Apps
  • 11.
  • 12.
  • 13. jQuery over all JavaScript frameworks
  • 14.
  • 15. Google Closure tools & libraries
  • 16.
  • 17. ClojureScript Quickstart Peeks under the covers of how to build and run Clojurescript generated JavaScript
  • 18.
  • 19.
  • 21. Clojurescript Environments Nashorn - built into JVM, access Java classes - Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM Browser-REPL - built into modern browsers (Chrome, Firefox, etc) - commonly used for client side web apps Node.js - great for command line utilities and microservices!
  • 22. Common Clojurescript Tooling Figwheel (leiningen plugin) - defacto tool for client side web apps - live reload and so much more... Figwheel-sidecar - connecting Emacs to figwheel
  • 23. Full-stack projects: Chestnut https://github.com/plexus/chestnut - leiningen template for Clojure/ClojureScript apps based - with Om, Reagent, or Rum - instant reloading of Clojure, ClojureScript, and CSS - browser-connected REPL included lein new chestnut project-name
  • 24. Self-hosted Clojurescript Environments Instant startup times, great for command line tools Lumo (cross-platform) - https://github.com/anmonteiro/lumo Plank (Mac & Linux) - http://planck-repl.org/
  • 27. React Basics React provides an efficient way to update the view
  • 28. What React Provides React is only the view You DO NOT GET any of the following: An event system (other than vanilla DOM events) Any AJAX capabilities whatsoever Any form of a data layer Promises Any application framework at all Any idea how implement the above
  • 29. How React Works (Simplified) Your view triggers an event - a user types a name in a text field That event updates a model Then the model triggers an event And the view responds to that model's event by re-rendering with the latest data. This one way data flow / decoupled observer pattern is designed to guarantee that your source of truth always stays in your stores / models
  • 30. JSX JSX is a preprocessor step that adds XML syntax to JavaScript. You can definitely use React without JSX but JSX makes React a lot more elegant. Just like XML, JSX tags have a tag name, attributes, and children. If an attribute value is enclosed in quotes, the value is a string.
  • 31. Reactive Frameworks All the varieties of life, plus all the Javascript varieties too...
  • 32. Javascript & Clojurescript frameworks Javascript ● React.js via cljsjs ● Vue.js ??? Clojurescript ● Om / Om-next ● Reagent / Reframe ● Rum More at https://clojurescript.org/community/libraries
  • 34. Reagent Reagent provides a minimalistic interface between ClojureScript and React. It allows you to define efficient React components using nothing but plain ClojureScript functions and data, that describe your UI using a Hiccup-like syntax. The goal of Reagent is to make it possible to define arbitrarily complex UIs using just a couple of basic concepts, and to be fast enough by default that you rarely have to care about performance.
  • 35. Reagent Core functions reagent.core/render - Render a Reagent component into the DOM - First argument is either a vector (Reagent Hiccup syntax) or a React element reagent.core/atom - Like clojure.core/atom, plus it tracks components that deref atom & re-renders them
  • 36. Reagent Helper functions clj->js - convert values from clojurescript to javascript js->clj - transforms JavaScript arrays into ClojureScript vectors, and JavaScript objects into ClojureScript maps
  • 38. Reframe re-frame is a pattern for writing SPAs in ClojureScript, using Reagent. Being a functional framework, it is about data, and the (pure) functions which transform that data. It is a loop Architecturally, re-frame implements "a perpetual loop". To build an app, you hang pure functions on certain parts of this loop, and re-frame looks after the conveyance of data around the loop, into and out of the transforming functions you provide - hence a tag line of "Derived Values, Flowing".
  • 39. Om / Om-next ClojureScript interface to Facebook's React
  • 40. Om / Om-next Om allows users to represent their UIs simply as EDN. Because ClojureScript data is immutable data, Om can always rapidly re-render the UI from the root. Thus Om UIs are out of the box snapshotable and undoable and these operations have no implementation complexity and little overhead. See for yourself. Unique Features Om supports features not currently present in React: ● Global state management facilities built in ● Components may have arbitrary data dependencies, not limited to props & state ● Component construction can be intercepted via :instrument. Simplifies debugging components and generic editors. ● Provides stream of all application state change deltas via :tx-listen. Simplifies synchronization online and offline. ● Customizable semantics. Fine grained control over how components store state, even for components outside of your control. Simplifies using Om components outside the Om framework, debugging, and adding event hooks not anticipated by original component designer.
  • 41. Om core functions om.core/IRender - Render a Om component into the DOM - uses reify to provide a specific implementation of the om/IRender interface om.dom/div attributes content - creates a <div> tag in react - all react tags need to be wrapped in a div in order to be rendered - om.dom/… has all the other tags too - h1, h2, p, a … (sablono can be used instead) #js - converts clojure maps into Javascript objects - nest #js functions to to create JS objects - eg. for inline styles
  • 42. Om Cursors Cursors are a fundamental part of Om. They let components refer to pieces of the app state without knowing where they are in the state tree. This makes updating the app state simple, as the cursor is already pointing to the correct part of the app state. cursors are like maps, but cursors also let you write to them A cursor is an atom & a path to a location in the atom appstate :entries 0
  • 44. Rum Rum is a client/server library for HTML UI. In ClojureScript, it works as React wrapper, in Clojure, it is a static HTML generator. - Simple semantics: Rum is arguably smaller, simpler and more straightforward than React itself. - Decomplected: Rum is a library, not a framework. Use only the parts you need, throw away or replace what you don’t need, combine different approaches in a single app, or even combine Rum with other frameworks. - No enforced state model: Unlike Om, Reagent or Quiescent, Rum does not dictate where to keep your state. Instead, it works well with any storage: persistent data structures, atoms, DataScript, JavaScript objects, localStorage or any custom solution you can think of. - Extensible: the API is stable and explicitly defined, including the API between Rum internals. It lets you build custom behaviours that change components in significant ways. - Minimal codebase: You can become a Rum expert just by reading its source code (~900 lines).
  • 47. Take your own journey into Clojure
  • 49. Clojure - Functional Web Immutability & composable functions for Web Apps
  • 50. Ring - simplifying communication Ring takes requests over HTTP and converts them into a map (think JSON)
  • 51. Ring - creating an embedded server
  • 52. Compojure - simplifying routing Compojure routes requests based on path & request type
  • 54. Hiccup - html from Clojure
  • 55. Ring - embedded server & dependencies