SlideShare a Scribd company logo
1 of 51
Download to read offline
elm-d3: Front-end
Development without
Frameworks
Spiros Eliopoulos (@seliopou)
June 30, 2014
NYC D3.js Meetup
What is Elm?
• Elm is a functional-reactive programming language for
the web.
• It kind of looks like Haskell or OCaml and is statically-
typed like them, but it’s less scary and compiles to
JavaScript.
• It models inputs as time-varying values called
Signals.!
• You can lift pure functions to Signals to build up
complex applications from basic inputs.
What is D3?
• Preaching to the choir.
• Assumed.
Let’s get on the same
page about MVC.
Model is Information
• The model describes the entire state of the
application, all in one place.
• It has a concrete type: m, i.e, data m = { … }
• While bits of state may be otherwise strewn about
the application, the model is the authoritative
record of state. In other words, you should never
read the random bits.
View is Computation
• To display an interface, you have to produce some
representation of the interface that the underlying
system can use to render the interface, e.g., HTML.
• The representation has a type r.
• The view is a function from the model to the
representation: m -> r.
Controller is Computation
• The controller mediates user interactions and
model updates. It handles events by updating the
model accordingly.
• Events have a concrete type e.
• An event handler is a function from an event and
model to an updated model: e -> m -> m.!
• A controller turns a stream of events into a signal of
models: Stream e -> Signal m
A “complete” MVC application.
view m = …
handler e m = …
controller = … handler …
!
main : Signal Element
main = lift view (controller events)
An even more “complete” MVC application.
view m = …
handler e m = …
controller = folde initModel handler
!
main : Signal Element
main = lift view (controller events)
An even more “complete” MVC application.
view m = render w h d3_view m
handler e m = …
controller = folde initModel handler
!
main : Signal Element
main = lift view (controller events)
Goal I: Use Elm to create
models, event handlers,
and controllers.
Goal II: Use D3.js to
create declarative,
compseable views.
Part Ia
A Basic Operation
An example operation.
d3.selectAll(“div”)
Shorthand for this.
d3.select(document).selectAll(“div”)
More generally.
context.selectAll(“div”)
Remove free variables so it works in isolation.
function(context) {
return context.selectAll(“div”);
}
Parameterize by the element name.
var selectAll = function(elt) {
return function(context) {
return context.selectAll(elt);
}
}
Using it.
selectAll(“div”)(d3.select(document))
Part Ib
Another Basic Operation
Another example operation.
context.attr(“class”, “box”);
Get rid of free variables
var attr = function(name, val) {
return function(context) {
return context.attr(name, val);
}
}
Using it.
!
attr(“class”,“box”)(d3.select(“div”))
Part Ic
Last Basic Operation
Data binding for good measure.
var bind = function(val) {
return function(context) {
return context.data(val);
};
}
Part Id
So what?
…
Part II
Combining Operations
How do you write an operation
that will set the class string
of every <div> to “box”?
Regular D3.js.
d3.selectAll(“div”)
.attr(“class”, “box”);
Using basic operations.
var div_op = function(context) {
return attr(“class”, “box”)
(selectAll(“div”)(context);
}
Ugly.
What’s happening?
This code has to be read from the inside out.
var div_op = function(context) {
return attr(“class”, “box”)
(selectAll(“div”)(context);
}
Method-chaining
operations is now
function application.
Making method chaining explicit.
var chain = function(op1, op2) {
return function(context) {
return op2(op1(context));
};
}
For good measure, making sequencing explicit.
var seq = function(op1, op2) {
return function(context) {
op1(context);
return op2(context);
};
}
Composing operations.
var div_op =
chain(selectAll(“div”),
attr(“class”, “box”));
Better. Understandable.
Also more general.
Still not great to
read or write.
Part III
Writing D3 in Elm
Wouldn’t this be nice?
div_op : Selection a
div_op =
selectAll “div”
|. str attr “class” “box”
Why Is This Nice?
• This is Elm code: it’s type-safe.
• |. is the method chaining
operation: concise and no
code inversion.
• It’s compositional: take basic
operations and combine them
to create a “bigger” operation.
• It’s reusable: The new
operation is just another value
that you can compose with
other operations.
div_op : Selection a
div_op =
selectAll “div”
|. str attr “class” “box”
!
div_op’ : Selection Int
div_op’ =
div_op
|. attr “width” (d i -> show d)
Selection a
• This is the type of a D3 operation in Elm.
• The a is the type of data that the operation expects to be
bound to the parent selection it’s applied to.
• If a is a type variable, then the operation does not
inspect the data and can be used in all contexts.
• If a is a concrete type, such as Int, that limits the other
operations it can be composed with.
• The render function from before is what does the initial
data binding of the model to the root of the DOM tree.
Wouldn’t this be nice?
circles : Widget [Point] Point
circles =
selectAll "circle"
|= List.tail
|- enter <.> append “circle”
|. num attr "r" 1.5
|. str attr "fill" "black"
|- update
|. fun attr "cx" (p _ -> show p.x)
|. fun attr "cy" (p _ -> show p.y)
Widget a b
• This is the type of a D3 data bind, introduced by
the |= operation.
• The a is the type of operations that the data bind
can be composed with.
• The b is the type of operations that can be
composed with the data bind.
• You turn a Widget a b into a Selection a
using the embed function.
Wouldn’t this be nice too?
voronoi : Widget [Point] [Point]
voronoi =
selectAll "path"
|= Voronoi.cells
|- enter <.> append "path"
|- update
|. fun attr "d" (d _ -> path d)
|. fun attr "class" (_ i ->
"q" ++ (show (mod i 9)) ++ "-9")
Defining the view (svg function elided).
view : Dims -> Margins -> Selection [Point]
view dims margins =
svg dims margins
|. seq (embed voronoi) (embed circles)
Part IV
Writing Applications
using elm-d3
https://github.com/seliopou/elm-d3

More Related Content

What's hot

Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScriptCodemotion
 
Functional programming in Javascript
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in JavascriptKnoldus Inc.
 
An introduction to property based testing
An introduction to property based testingAn introduction to property based testing
An introduction to property based testingScott Wlaschin
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerRaúl Raja Martínez
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScripttmont
 
Functions in c++
Functions in c++Functions in c++
Functions in c++Maaz Hasan
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Scott Wlaschin
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingBurhan Ahmed
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlabharman kaur
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1Shameer Ahmed Koya
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptWebF
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascriptguest4d57e6
 
Function class in c++
Function class in c++Function class in c++
Function class in c++Kumar
 

What's hot (20)

Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
 
Functional programming in Javascript
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in Javascript
 
An introduction to property based testing
An introduction to property based testingAn introduction to property based testing
An introduction to property based testing
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic Programmer
 
Java script
Java scriptJava script
Java script
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Time for Functions
Time for FunctionsTime for Functions
Time for Functions
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
 
Overloading
OverloadingOverloading
Overloading
 

Viewers also liked

React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit TestingEswara Kumar Palakollu
 
Waldorf Education
Waldorf EducationWaldorf Education
Waldorf EducationxMerodi
 
ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는Taegon Kim
 
Reverse Engineering
Reverse EngineeringReverse Engineering
Reverse Engineeringdswanson
 
GigaSpaces XAP in Five Minutes
GigaSpaces XAP in Five MinutesGigaSpaces XAP in Five Minutes
GigaSpaces XAP in Five MinutesNati Shalom
 
Financial Statements, Cash Flows, Taxes, and the Language of Finance
Financial Statements, Cash Flows, Taxes, and the Language of FinanceFinancial Statements, Cash Flows, Taxes, and the Language of Finance
Financial Statements, Cash Flows, Taxes, and the Language of FinanceMaged Elsakka
 
GigaSpaces - Getting Ready For The Cloud
GigaSpaces - Getting Ready For The CloudGigaSpaces - Getting Ready For The Cloud
GigaSpaces - Getting Ready For The Cloudgigaspaces
 
From APM to Full Stack with Blue Medora [FutureStack16]
From APM to Full Stack with Blue Medora [FutureStack16]From APM to Full Stack with Blue Medora [FutureStack16]
From APM to Full Stack with Blue Medora [FutureStack16]New Relic
 
Unit Test JavaScript
Unit Test JavaScriptUnit Test JavaScript
Unit Test JavaScriptDan Vitoriano
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
Hadoop and Cassandra at Rackspace
Hadoop and Cassandra at RackspaceHadoop and Cassandra at Rackspace
Hadoop and Cassandra at RackspaceStu Hood
 

Viewers also liked (20)

React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 
Waldorf Education
Waldorf EducationWaldorf Education
Waldorf Education
 
ReactJs
ReactJsReactJs
ReactJs
 
Oprah Winfrey
Oprah WinfreyOprah Winfrey
Oprah Winfrey
 
ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는
 
Elon Musk
Elon MuskElon Musk
Elon Musk
 
Bill Gates, Who is he?
Bill Gates, Who is he?Bill Gates, Who is he?
Bill Gates, Who is he?
 
Reverse Engineering
Reverse EngineeringReverse Engineering
Reverse Engineering
 
Chess
ChessChess
Chess
 
Product management
Product managementProduct management
Product management
 
Product Management
Product ManagementProduct Management
Product Management
 
Personal Development
Personal DevelopmentPersonal Development
Personal Development
 
GigaSpaces XAP in Five Minutes
GigaSpaces XAP in Five MinutesGigaSpaces XAP in Five Minutes
GigaSpaces XAP in Five Minutes
 
Financial Statements, Cash Flows, Taxes, and the Language of Finance
Financial Statements, Cash Flows, Taxes, and the Language of FinanceFinancial Statements, Cash Flows, Taxes, and the Language of Finance
Financial Statements, Cash Flows, Taxes, and the Language of Finance
 
Shamanism
ShamanismShamanism
Shamanism
 
GigaSpaces - Getting Ready For The Cloud
GigaSpaces - Getting Ready For The CloudGigaSpaces - Getting Ready For The Cloud
GigaSpaces - Getting Ready For The Cloud
 
From APM to Full Stack with Blue Medora [FutureStack16]
From APM to Full Stack with Blue Medora [FutureStack16]From APM to Full Stack with Blue Medora [FutureStack16]
From APM to Full Stack with Blue Medora [FutureStack16]
 
Unit Test JavaScript
Unit Test JavaScriptUnit Test JavaScript
Unit Test JavaScript
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
Hadoop and Cassandra at Rackspace
Hadoop and Cassandra at RackspaceHadoop and Cassandra at Rackspace
Hadoop and Cassandra at Rackspace
 

Similar to elm-d3 @ NYC D3.js Meetup (30 June, 2014)

The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Soham Kulkarni
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipseanshunjain
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35Bilal Ahmed
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutesJos Dirksen
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScriptChengHui Weng
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummaryAmal Khailtash
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderAndres Almiray
 

Similar to elm-d3 @ NYC D3.js Meetup (30 June, 2014) (20)

The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

elm-d3 @ NYC D3.js Meetup (30 June, 2014)

  • 1. elm-d3: Front-end Development without Frameworks Spiros Eliopoulos (@seliopou) June 30, 2014 NYC D3.js Meetup
  • 2. What is Elm? • Elm is a functional-reactive programming language for the web. • It kind of looks like Haskell or OCaml and is statically- typed like them, but it’s less scary and compiles to JavaScript. • It models inputs as time-varying values called Signals.! • You can lift pure functions to Signals to build up complex applications from basic inputs.
  • 3. What is D3? • Preaching to the choir. • Assumed.
  • 4. Let’s get on the same page about MVC.
  • 5. Model is Information • The model describes the entire state of the application, all in one place. • It has a concrete type: m, i.e, data m = { … } • While bits of state may be otherwise strewn about the application, the model is the authoritative record of state. In other words, you should never read the random bits.
  • 6. View is Computation • To display an interface, you have to produce some representation of the interface that the underlying system can use to render the interface, e.g., HTML. • The representation has a type r. • The view is a function from the model to the representation: m -> r.
  • 7. Controller is Computation • The controller mediates user interactions and model updates. It handles events by updating the model accordingly. • Events have a concrete type e. • An event handler is a function from an event and model to an updated model: e -> m -> m.! • A controller turns a stream of events into a signal of models: Stream e -> Signal m
  • 8. A “complete” MVC application. view m = … handler e m = … controller = … handler … ! main : Signal Element main = lift view (controller events)
  • 9. An even more “complete” MVC application. view m = … handler e m = … controller = folde initModel handler ! main : Signal Element main = lift view (controller events)
  • 10. An even more “complete” MVC application. view m = render w h d3_view m handler e m = … controller = folde initModel handler ! main : Signal Element main = lift view (controller events)
  • 11. Goal I: Use Elm to create models, event handlers, and controllers.
  • 12. Goal II: Use D3.js to create declarative, compseable views.
  • 13. Part Ia A Basic Operation
  • 17. Remove free variables so it works in isolation. function(context) { return context.selectAll(“div”); }
  • 18. Parameterize by the element name. var selectAll = function(elt) { return function(context) { return context.selectAll(elt); } }
  • 22. Get rid of free variables var attr = function(name, val) { return function(context) { return context.attr(name, val); } }
  • 24. Part Ic Last Basic Operation
  • 25. Data binding for good measure. var bind = function(val) { return function(context) { return context.data(val); }; }
  • 27.
  • 29. How do you write an operation that will set the class string of every <div> to “box”?
  • 31. Using basic operations. var div_op = function(context) { return attr(“class”, “box”) (selectAll(“div”)(context); }
  • 33. This code has to be read from the inside out. var div_op = function(context) { return attr(“class”, “box”) (selectAll(“div”)(context); }
  • 35. Making method chaining explicit. var chain = function(op1, op2) { return function(context) { return op2(op1(context)); }; }
  • 36. For good measure, making sequencing explicit. var seq = function(op1, op2) { return function(context) { op1(context); return op2(context); }; }
  • 37. Composing operations. var div_op = chain(selectAll(“div”), attr(“class”, “box”));
  • 39. Still not great to read or write.
  • 41. Wouldn’t this be nice? div_op : Selection a div_op = selectAll “div” |. str attr “class” “box”
  • 42. Why Is This Nice? • This is Elm code: it’s type-safe. • |. is the method chaining operation: concise and no code inversion. • It’s compositional: take basic operations and combine them to create a “bigger” operation. • It’s reusable: The new operation is just another value that you can compose with other operations. div_op : Selection a div_op = selectAll “div” |. str attr “class” “box” ! div_op’ : Selection Int div_op’ = div_op |. attr “width” (d i -> show d)
  • 43. Selection a • This is the type of a D3 operation in Elm. • The a is the type of data that the operation expects to be bound to the parent selection it’s applied to. • If a is a type variable, then the operation does not inspect the data and can be used in all contexts. • If a is a concrete type, such as Int, that limits the other operations it can be composed with. • The render function from before is what does the initial data binding of the model to the root of the DOM tree.
  • 44. Wouldn’t this be nice? circles : Widget [Point] Point circles = selectAll "circle" |= List.tail |- enter <.> append “circle” |. num attr "r" 1.5 |. str attr "fill" "black" |- update |. fun attr "cx" (p _ -> show p.x) |. fun attr "cy" (p _ -> show p.y)
  • 45.
  • 46. Widget a b • This is the type of a D3 data bind, introduced by the |= operation. • The a is the type of operations that the data bind can be composed with. • The b is the type of operations that can be composed with the data bind. • You turn a Widget a b into a Selection a using the embed function.
  • 47. Wouldn’t this be nice too? voronoi : Widget [Point] [Point] voronoi = selectAll "path" |= Voronoi.cells |- enter <.> append "path" |- update |. fun attr "d" (d _ -> path d) |. fun attr "class" (_ i -> "q" ++ (show (mod i 9)) ++ "-9")
  • 48. Defining the view (svg function elided). view : Dims -> Margins -> Selection [Point] view dims margins = svg dims margins |. seq (embed voronoi) (embed circles)
  • 50.