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

PDF
Concurrency in Python
PDF
Learning Git with Workflows
PDF
Learning Python from Data
PDF
Graph-Tool in Practice
PDF
Elegant concurrency
PDF
Practicing Python 3
PDF
Syncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
PDF
How do event loops work in Python?
Concurrency in Python
Learning Git with Workflows
Learning Python from Data
Graph-Tool in Practice
Elegant concurrency
Practicing Python 3
Syncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
How do event loops work in Python?

What's hot (20)

KEY
Lock? We don't need no stinkin' locks!
PDF
Asynchronous I/O in Python 3
PPTX
iSoligorsk #3 2013
PPTX
Async programming and python
PDF
Beyond JVM - YOW! Sydney 2013
PDF
Effective Benchmarks
PDF
Unit Testing Lots of Perl
PDF
How to inspect a RUNNING perl process
PDF
Golang Performance : microbenchmarks, profilers, and a war story
PDF
Perl Dist::Surveyor 2011
PDF
Python, do you even async?
PDF
What you need to remember when you upload to CPAN
PDF
Event loop
PDF
PL/Perl - New Features in PostgreSQL 9.0 201012
PDF
Profiling and optimizing go programs
PPTX
Sphinx autodoc - automated api documentation - PyCon.KR 2015
PDF
Coroutines for Kotlin Multiplatform in Practise
PPT
On UnQLite
PDF
Introduction to clojure
PDF
Go Profiling - John Graham-Cumming
Lock? We don't need no stinkin' locks!
Asynchronous I/O in Python 3
iSoligorsk #3 2013
Async programming and python
Beyond JVM - YOW! Sydney 2013
Effective Benchmarks
Unit Testing Lots of Perl
How to inspect a RUNNING perl process
Golang Performance : microbenchmarks, profilers, and a war story
Perl Dist::Surveyor 2011
Python, do you even async?
What you need to remember when you upload to CPAN
Event loop
PL/Perl - New Features in PostgreSQL 9.0 201012
Profiling and optimizing go programs
Sphinx autodoc - automated api documentation - PyCon.KR 2015
Coroutines for Kotlin Multiplatform in Practise
On UnQLite
Introduction to clojure
Go Profiling - John Graham-Cumming
Ad

Viewers also liked (7)

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

Similar to Minimal MVC in JavaScript (20)

PDF
MVC pattern for widgets
PDF
Viking academy backbone.js
PPTX
Introduction to Knockoutjs
PDF
Just a View: An Introduction To Model-View-Controller Pattern
PDF
Introduction to Backbone.js
PDF
JS and patterns
PPTX
Javascript for Wep Apps
PPTX
Planbox Backbone MVC
KEY
[Coscup 2012] JavascriptMVC
PDF
MVS: An angular MVC
KEY
Sugarcoating your frontend one ViewModel at a time
PDF
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
PPT
Mvc architecture
PPT
Vanjs backbone-powerpoint
PPTX
JavaScript Framework Smackdown
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
PPTX
Mvc pattern and implementation in java fair
PPTX
MV* presentation frameworks in Javascript: en garde, pret, allez!
PDF
Javascript MVC & Backbone Tips & Tricks
PDF
Javascript Web Applications Otx Alex Maccaw
MVC pattern for widgets
Viking academy backbone.js
Introduction to Knockoutjs
Just a View: An Introduction To Model-View-Controller Pattern
Introduction to Backbone.js
JS and patterns
Javascript for Wep Apps
Planbox Backbone MVC
[Coscup 2012] JavascriptMVC
MVS: An angular MVC
Sugarcoating your frontend one ViewModel at a time
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Mvc architecture
Vanjs backbone-powerpoint
JavaScript Framework Smackdown
jQquerysummit - Large-scale JavaScript Application Architecture
Mvc pattern and implementation in java fair
MV* presentation frameworks in Javascript: en garde, pret, allez!
Javascript MVC & Backbone Tips & Tricks
Javascript Web Applications Otx Alex Maccaw

More from Mosky Liu (6)

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

Recently uploaded (20)

PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
E-Commerce Website Development Companyin india
PPTX
CNN LeNet5 Architecture: Neural Networks
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PPTX
Cybersecurity: Protecting the Digital World
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PDF
Workplace Software and Skills - OpenStax
PDF
Microsoft Office 365 Crack Download Free
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
Guide to Food Delivery App Development.pdf
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
PPTX
Lecture 5 Software Requirement Engineering
PDF
Internet Download Manager IDM Crack powerful download accelerator New Version...
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
PPTX
Trending Python Topics for Data Visualization in 2025
How Tridens DevSecOps Ensures Compliance, Security, and Agility
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
How to Use SharePoint as an ISO-Compliant Document Management System
E-Commerce Website Development Companyin india
CNN LeNet5 Architecture: Neural Networks
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
Cybersecurity: Protecting the Digital World
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
Workplace Software and Skills - OpenStax
Microsoft Office 365 Crack Download Free
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Guide to Food Delivery App Development.pdf
Wondershare Recoverit Full Crack New Version (Latest 2025)
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
Lecture 5 Software Requirement Engineering
Internet Download Manager IDM Crack powerful download accelerator New Version...
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
Trending Python Topics for Data Visualization in 2025

Minimal MVC in JavaScript