SlideShare a Scribd company logo
MINIMAL MVC IN JAVASCRIPT
MOSKY
MOSKY
2
MOSKY
• Python Charmer at Pinkoi
2
MOSKY
• Python Charmer at Pinkoi
• An author of some Python packages
2
MOSKY
• Python Charmer at Pinkoi
• An author of some Python packages
• A speaker of some confs, PyCon TW/JP mostly
2
MOSKY
• Python Charmer at Pinkoi
• An author of some Python packages
• A speaker of some confs, PyCon TW/JP mostly
• A Python instructor
2
MOSKY
• Python Charmer at Pinkoi
• An author of some Python packages
• A speaker of some confs, PyCon TW/JP mostly
• A Python instructor
• mosky.tw
2
MOSKY
3
MOSKY
• “Uh … Python …?”
3
MOSKY
• “Uh … Python …?”
• Yes, but, today I am going to talk about JavaScript.
3
MOSKY
• “Uh … Python …?”
• Yes, but, today I am going to talk about JavaScript.
• kind of thinking FE from BE aspect.
3
OUTLINE
4
OUTLINE
• What is MVC?
4
OUTLINE
• What is MVC?
• Status Quo
4
OUTLINE
• What is MVC?
• Status Quo
• Make It Better in Minimal Cost
4
OUTLINE
• What is MVC?
• Status Quo
• Make It Better in Minimal Cost
• Conclusion
4
WHAT IS MVC?
6
6
Model
6
View
Model
6
View
Model
Controller
6
View
Model
Controller
User
6
View
Model
Controller
User Uses
6
View
Model
Controller
User
Manipulates
Uses
6
View
Model
Controller
User
Update Manipulates
Uses
6
View
Model
Controller
User
Update
Sees
Manipulates
Uses
6
View
Model
Controller
User
Update
Sees
Manipulates
Uses
Sync
7
7
7
Manipulates
7
Manipulates
Updates
8
View
Model
Controller
User
Update
Sees
Manipulates
Uses
Sync
STATUS QUO
10
10
DOM

(View)
JS

(Controller)
User
10
DOM

(View)
JS

(Controller)
User Uses
10
DOM

(View)
JS

(Controller)
User
Data
Uses
10
DOM

(View)
JS

(Controller)
User
Data
Uses
Sync
10
DOM

(View)
JS

(Controller)
User
Data
Uses
Sync
Update
10
DOM

(View)
JS

(Controller)
UserSees
Data
Uses
Sync
Update
UPDATE FROM SERVER DATA
UPDATE FROM SERVER DATA
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data from Server
UPDATE FROM SERVER DATA
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data from Server
K1
M
Show to User
UPDATE FROM SERVER DATA
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data from Server
K1
M
Show to User
1:1
UPDATE FROM SERVER DATA
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data from Server
K1
M
Show to User
1:1
N:1
UPDATE FROM SERVER DATA
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data from Server
K1
M
Show to User
1:1
N:1
Nothing
GET DATA FROM DOM
GET DATA FROM DOM
K1
M
After Modifying
GET DATA FROM DOM
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data to Server
K1
M
After Modifying
GET DATA FROM DOM
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data to Server
K1
M
After Modifying
1:1
GET DATA FROM DOM
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data to Server
K1
M
After Modifying
1:1
N:1
GET DATA FROM DOM
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data to Server
K1
M
After Modifying
1:1
N:1
Nothing
GET DATA FROM DOM
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data to Server
K1
M
After Modifying
1:1
N:1
Nothing
Code, code, code!
GET DATA FROM DOM
{	
k1: "…",	
k2: "…",	
k3: "…"	
}
Data to Server
K1
M
After Modifying
1:1
N:1
Nothing
Code, code, code!
From nothing!
13
DOM

(View)
JS

(Controller)
UserSees
Data
Uses
Sync
Update
MAKE IT BETTER

IN MINIMAL COST
15
View Controller
UserSees Uses
15
View Controller
UserSees Uses
ModelUpdate Manipulates
Sync
15
View Controller
UserSees Uses
ModelUpdate Manipulates
Sync
Make all 1:1!
THE RECIPE
16
THE RECIPE
• Use Class in JavaScript;
16
THE RECIPE
• Use Class in JavaScript;
• Write 3 methods as Model, View, and Controller
16
THE RECIPE
• Use Class in JavaScript;
• Write 3 methods as Model, View, and Controller
• Make function call as message passing
16
THE RECIPE
• Use Class in JavaScript;
• Write 3 methods as Model, View, and Controller
• Make function call as message passing
• Message is what changed.
16
THE RECIPE
• Use Class in JavaScript;
• Write 3 methods as Model, View, and Controller
• Make function call as message passing
• Message is what changed.
• And the util-level libs you love.
16
THE RECIPE
• Use Class in JavaScript;
• Write 3 methods as Model, View, and Controller
• Make function call as message passing
• Message is what changed.
• And the util-level libs you love.
• (My favor is just JQuery and Underscore.js)
16
THE CONSTRUCTOR
var Clock = function (obj) {	
!
/* Model */	
this._model = {};	
!
/* View */	
this.$view = $(Clock.template);	
this.$i = $this.view.find('.i');	
this.$o = $this.view.find('.o');	
// ...	
!
!
/* Controller */	
var _this = this;	
this.$view.on('change', '.i',
function () {	
_this.controller('i-changed');	
});	
// ...	
!
// Apply defaults	
this.model(obj);	
};	
17
THE MODEL
Clock.prototype.model = function (model_changes) {	
!
// First, optionally filter the fake changes out.	
!
// Second, asyncly send the changes to server;	
// and update model/view by the response.	
!
// Finally, update the changes into this._model.	
!
this.view(view_changes);	
};	
18
THE VIEW
Clock.prototype.view = function (view_changes) {	
!
// Pattern I	
if (view_changes.o !== undefined) {	
this.$o.val(view_changes.o);	
}	
!
// Pattern II	
this.$n.val(this._model.o);	
};
19
THE CONTROLLER
Clock.prototype.controller = function (event_name) {	
switch (event_name) {	
case 'i-changed':	
this.model({o: _this.$i.val()});	
break;	
}	
};	
!
!
20
21
View
Model
Controller
User
Update
Sees
Manipulates
Uses
Sync
REAL CASES
22
REAL CASES
• The Memo App
22
REAL CASES
• The Memo App
• https://github.com/moskytw/memo-app/blob/
master/memo/static/memo.js
22
REAL CASES
• The Memo App
• https://github.com/moskytw/memo-app/blob/
master/memo/static/memo.js
• The Web for ZIPCodeTW
22
REAL CASES
• The Memo App
• https://github.com/moskytw/memo-app/blob/
master/memo/static/memo.js
• The Web for ZIPCodeTW
• https://github.com/moskytw/zipcodetw/blob/
dev/web/static/finder.js
22
REAL CASES
• The Memo App
• https://github.com/moskytw/memo-app/blob/
master/memo/static/memo.js
• The Web for ZIPCodeTW
• https://github.com/moskytw/zipcodetw/blob/
dev/web/static/finder.js
• http://zipcode.mosky.tw/
22
CONCLUSION
CONCLUSION
24
CONCLUSION
• MVC is a powerful pattern, and not hard.
24
CONCLUSION
• MVC is a powerful pattern, and not hard.
• Add model unit to simplify problem.
24
CONCLUSION
• MVC is a powerful pattern, and not hard.
• Add model unit to simplify problem.
• Don’t be limited by the frameworks!
24
THE LAST THING!
PYCON APAC 2014 (IN TAIWAN)
REGISTRATIONS ARE OPEN!
CONCLUSION
27
CONCLUSION
• MVC is a powerful pattern, and not hard.
• Add model unit to simplify problem.
• Don’t be limited by the frameworks!
27
CONCLUSION
• MVC is a powerful pattern, and not hard.
• Add model unit to simplify problem.
• Don’t be limited by the frameworks!
• mosky.tw
27
CONCLUSION
• MVC is a powerful pattern, and not hard.
• Add model unit to simplify problem.
• Don’t be limited by the frameworks!
• mosky.tw
• Any questions?
27

More Related Content

What's hot (20)

KEY
Lock? We don't need no stinkin' locks!
Michael Barker
 
PDF
Asynchronous I/O in Python 3
Feihong Hsu
 
PPTX
iSoligorsk #3 2013
Friedrich Boeckh
 
PPTX
Async programming and python
Chetan Giridhar
 
PDF
Beyond JVM - YOW! Sydney 2013
Charles Nutter
 
PDF
Effective Benchmarks
Workhorse Computing
 
PDF
Unit Testing Lots of Perl
Workhorse Computing
 
PDF
How to inspect a RUNNING perl process
Masaaki HIROSE
 
PDF
Golang Performance : microbenchmarks, profilers, and a war story
Aerospike
 
PDF
Perl Dist::Surveyor 2011
Tim Bunce
 
PDF
Python, do you even async?
Saúl Ibarra Corretgé
 
PDF
What you need to remember when you upload to CPAN
charsbar
 
PDF
Event loop
codepitbull
 
PDF
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce
 
PDF
Profiling and optimizing go programs
Badoo Development
 
PPTX
Sphinx autodoc - automated api documentation - PyCon.KR 2015
Takayuki Shimizukawa
 
PDF
Coroutines for Kotlin Multiplatform in Practise
Christian Melchior
 
PPT
On UnQLite
charsbar
 
PDF
Introduction to clojure
Abbas Raza
 
PDF
Go Profiling - John Graham-Cumming
Cloudflare
 
Lock? We don't need no stinkin' locks!
Michael Barker
 
Asynchronous I/O in Python 3
Feihong Hsu
 
iSoligorsk #3 2013
Friedrich Boeckh
 
Async programming and python
Chetan Giridhar
 
Beyond JVM - YOW! Sydney 2013
Charles Nutter
 
Effective Benchmarks
Workhorse Computing
 
Unit Testing Lots of Perl
Workhorse Computing
 
How to inspect a RUNNING perl process
Masaaki HIROSE
 
Golang Performance : microbenchmarks, profilers, and a war story
Aerospike
 
Perl Dist::Surveyor 2011
Tim Bunce
 
Python, do you even async?
Saúl Ibarra Corretgé
 
What you need to remember when you upload to CPAN
charsbar
 
Event loop
codepitbull
 
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce
 
Profiling and optimizing go programs
Badoo Development
 
Sphinx autodoc - automated api documentation - PyCon.KR 2015
Takayuki Shimizukawa
 
Coroutines for Kotlin Multiplatform in Practise
Christian Melchior
 
On UnQLite
charsbar
 
Introduction to clojure
Abbas Raza
 
Go Profiling - John Graham-Cumming
Cloudflare
 

Viewers also liked (7)

PDF
Introduction to Clime
Mosky Liu
 
PDF
Programming with Python - Adv.
Mosky Liu
 
PDF
Boost Maintainability
Mosky Liu
 
PDF
ZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
Mosky Liu
 
PDF
Beyond the Style Guides
Mosky Liu
 
PDF
Programming with Python - Basic
Mosky Liu
 
PDF
Simple Belief - Mosky @ TEDxNTUST 2015
Mosky Liu
 
Introduction to Clime
Mosky Liu
 
Programming with Python - Adv.
Mosky Liu
 
Boost Maintainability
Mosky Liu
 
ZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
Mosky Liu
 
Beyond the Style Guides
Mosky Liu
 
Programming with Python - Basic
Mosky Liu
 
Simple Belief - Mosky @ TEDxNTUST 2015
Mosky Liu
 
Ad

Similar to Minimal MVC in JavaScript (20)

PDF
MVC pattern for widgets
Behnam Taraghi
 
PDF
Viking academy backbone.js
Bert Wijnants
 
PPTX
Introduction to Knockoutjs
jhoguet
 
PDF
Just a View: An Introduction To Model-View-Controller Pattern
Aaron Nordyke
 
PDF
Introduction to Backbone.js
Jonathan Weiss
 
PDF
JS and patterns
David Rodenas
 
PPTX
Javascript for Wep Apps
Michael Puckett
 
PPTX
Planbox Backbone MVC
Acquisio
 
KEY
[Coscup 2012] JavascriptMVC
Alive Kuo
 
PDF
MVS: An angular MVC
David Rodenas
 
KEY
Sugarcoating your frontend one ViewModel at a time
Einar Ingebrigtsen
 
PDF
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Ravi Bhadauria
 
PPT
Mvc architecture
Surbhi Panhalkar
 
PPT
Vanjs backbone-powerpoint
Michael Yagudaev
 
PPTX
JavaScript Framework Smackdown
meghantaylor
 
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
Jiby John
 
PPTX
Mvc pattern and implementation in java fair
Tech_MX
 
PPTX
MV* presentation frameworks in Javascript: en garde, pret, allez!
Roberto Messora
 
PDF
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 
PDF
Javascript Web Applications Otx Alex Maccaw
fahradzereit93
 
MVC pattern for widgets
Behnam Taraghi
 
Viking academy backbone.js
Bert Wijnants
 
Introduction to Knockoutjs
jhoguet
 
Just a View: An Introduction To Model-View-Controller Pattern
Aaron Nordyke
 
Introduction to Backbone.js
Jonathan Weiss
 
JS and patterns
David Rodenas
 
Javascript for Wep Apps
Michael Puckett
 
Planbox Backbone MVC
Acquisio
 
[Coscup 2012] JavascriptMVC
Alive Kuo
 
MVS: An angular MVC
David Rodenas
 
Sugarcoating your frontend one ViewModel at a time
Einar Ingebrigtsen
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Ravi Bhadauria
 
Mvc architecture
Surbhi Panhalkar
 
Vanjs backbone-powerpoint
Michael Yagudaev
 
JavaScript Framework Smackdown
meghantaylor
 
jQquerysummit - Large-scale JavaScript Application Architecture
Jiby John
 
Mvc pattern and implementation in java fair
Tech_MX
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
Roberto Messora
 
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 
Javascript Web Applications Otx Alex Maccaw
fahradzereit93
 
Ad

More from Mosky Liu (6)

PDF
Statistical Regression With Python
Mosky Liu
 
PDF
Data Science With Python
Mosky Liu
 
PDF
Hypothesis Testing With Python
Mosky Liu
 
PDF
Dive into Pinkoi 2013
Mosky Liu
 
PDF
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
Mosky Liu
 
PDF
MoSQL: More than SQL, but less than ORM
Mosky Liu
 
Statistical Regression With Python
Mosky Liu
 
Data Science With Python
Mosky Liu
 
Hypothesis Testing With Python
Mosky Liu
 
Dive into Pinkoi 2013
Mosky Liu
 
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
Mosky Liu
 
MoSQL: More than SQL, but less than ORM
Mosky Liu
 

Recently uploaded (20)

PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Executive Business Intelligence Dashboards
vandeslie24
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 

Minimal MVC in JavaScript