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
2-Functions.pdf
YekoyeTigabuYeko
 
ZIP
Mojolicious
Marcus Ramberg
 
PDF
Know your platform. 7 things every scala developer should know about jvm
Pawel Szulc
 
PDF
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Bram Adams
 
PDF
Asynchronous programming patterns in Perl
deepfountainconsulting
 
PDF
Performance measurement and tuning
AOE
 
PPTX
ql.io at NodePDX
Subbu Allamaraju
 
PDF
DevOps with Serverless
Yan Cui
 
KEY
Deploying Next Gen Systems with Zero Downtime
Twilio Inc
 
PDF
Benchmarking at Parse
Travis Redman
 
PDF
Advanced Benchmarking at Parse
MongoDB
 
PDF
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Boxed Ice
 
PPT
Friend this-new&delete
Shehzad Rizwan
 
PDF
MLBlock
Nat Weerawan
 
PDF
The Unicorn's Travel to the Microcosm
Andrey Karpov
 
PDF
The Basic Concept Of IOC
Carl Lu
 
PPTX
ECMAScript 6 and the Node Driver
MongoDB
 
PDF
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Srinivasa Rao
 
PDF
Complex Made Simple: Sleep Better with TorqueBox
bobmcwhirter
 
PDF
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Igalia
 
2-Functions.pdf
YekoyeTigabuYeko
 
Mojolicious
Marcus Ramberg
 
Know your platform. 7 things every scala developer should know about jvm
Pawel Szulc
 
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Bram Adams
 
Asynchronous programming patterns in Perl
deepfountainconsulting
 
Performance measurement and tuning
AOE
 
ql.io at NodePDX
Subbu Allamaraju
 
DevOps with Serverless
Yan Cui
 
Deploying Next Gen Systems with Zero Downtime
Twilio Inc
 
Benchmarking at Parse
Travis Redman
 
Advanced Benchmarking at Parse
MongoDB
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Boxed Ice
 
Friend this-new&delete
Shehzad Rizwan
 
MLBlock
Nat Weerawan
 
The Unicorn's Travel to the Microcosm
Andrey Karpov
 
The Basic Concept Of IOC
Carl Lu
 
ECMAScript 6 and the Node Driver
MongoDB
 
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Srinivasa Rao
 
Complex Made Simple: Sleep Better with TorqueBox
bobmcwhirter
 
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Igalia
 
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)

PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
Import Data Form Excel to Tally Services
Tally xperts
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 

Minimal MVC in JavaScript