SlideShare a Scribd company logo
1 of 67
Download to read offline
SproutCore
Why?
building large apps in jQuery
?
?
View (DOM Manipulation)
Model (.data)
Controller (.bind)
View (DOM Manipulation)
jQuery
jQuery
jQuery
Following 187
Following 188
$(".follow-me").live("click", function() {
var link = $(this).parent().prev();
var count =
parseInt($("#following span.count").text());
var newLink = $("<li class='user'>")
.append(link.clone());
$("#following").prepend(newLink);
$("#following span.count").text(count + 1);
});
D E F G
Following 187
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
D E F G
Following 187
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
Edge cases
Start with less than 4
D E F
Following 187
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
Edge cases
Start with less than 4
Unfollowing
A D E F
Following 188
Who to follow
A
wycats · Unfollow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
What's
wrong?
Views need to
know about
each other
There are lots of views
There are lots of views
More complex
apps
==
more spaghetti
What's the
right way?
Model objects
User
guid
username
gravatar
isFollowed
self-
contained
views
D E F G
Following 187
following.length
following[N]
[1][0] [2] [3]
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
A.isFollowed
B.isFollowed
C.isFollowed
users
[0]
[1]
[2]
D E F G
Following 187
following
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
recommendations
wired
together by
the page
Twitter.following
User
isFollowedChanged: function() {
var followed = this.get('isFollowed');
if(followed) {
Twitter.following.unshiftObject(this);
} else {
Twitter.following.removeObject(this);
}
}.observes('isFollowed')
D E F G
Following 187
following
Users
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
recommendations
Twitter.recommendations
Users
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
recommendations
Twitter.recommendations
Users
click =>
user.set('isFollowed', true)
What's
Happening
Here?
D E F G
Following 187
following
Who to follow
A
wycats · Follow
Yehuda Katz
B
okito · Follow
Charles Jolley
C
wifelette · Follow
Leah Silber
recommendations
Totally
Isolated
Views
Totally
Isolated
Models
User
guid
username
gravatar
isFollowed
isFollowedChanged
Glued Together
By the App
SC.MainPage.append({
pickFollowers: Twitter.PickFollowers.design({
recommendationsBinding:
"Twitter.recommendations"
}),
listFollowers: Twitter.FollowerList.design({
followingBinding: "Twitter.following"
})
});
Views?
SC.TemplateView
Twitter.FollowersList = SC.TemplateView.extend({
// display property
following: [],
template: "followers_list",
});
creates
render
method for
you
<ul>
{{#bind following}}
<li data-guid="{{guid}}">
<a href="#!/{{username}}">
<img src="{{gravatar}}" />
</a>
</li>
{{/bind}}
</ul>
Mustache++
Handlebars.js
{{#bind following}}
“Listen to changes in the
following Array. If an
element is added, render a
new <li>. If an element is
removed, remove it.
Syntax and
impl are a
work in
progress
Works for
simple
properties
<div class="post">
<h1>{{bind title}}</h1>
<div class="body">{{bind body}}</div>
</div>
What about
getting
remote data?
Twitter.following = [];
$.getJSON("/following", function(json) {
var users = json.users.map(function(post) {
return Twitter.User.create(post);
});
Twitter.set('following', users);
});
Twitter.User?
Twitter.User = SC.Object.extend({
// documentation
isFollowed: false,
username: null,
gravatar: null,
isFollowedChanged: function() {
var followed = this.get('isFollowed');
if(followed) {
Twitter.following.unshiftObject(this);
} else {
Twitter.following.removeObject(this);
}
}.observes('isFollowed')
});
To Recap
Benefits:
Isolation
$(".follow-me").live("click", function() {
var link = $(this).parent().prev();
var count =
parseInt($("#following span.count").text());
var newLink = $("<li class='user'>")
.append(link.clone());
$("#following").prepend(newLink);
$("#following span.count").text(count + 1);
});
$(".follow-me").live("click", function() {
var link = $(this).parent().prev();
var count =
parseInt($("#following span.count").text());
var newLink = $("<li class='user'>")
.append(link.clone());
$("#following").prepend(newLink);
$("#following span.count").text(count + 1);
});
X
Makes totally
rewriting
parts of the
view feasible
Makes totally
rewriting
parts of the
view trivial
Keeps data
model
concerns out
of the view
Makes
revising large
areas of the
view simpler
I Haven't
Touched on
Controllers
This is a very
simple
example
Controllers
add view
concerns to
objects
e.g.
ArrayController
has 'selection'
Mockup Ideas
amber-mockups.strobeapp.com
Thanks!

More Related Content

Viewers also liked

Intro to jQuery - LUGOR - Part 1
Intro to jQuery - LUGOR - Part 1Intro to jQuery - LUGOR - Part 1
Intro to jQuery - LUGOR - Part 1
Ralph Whitbeck
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
Yehuda Katz
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 

Viewers also liked (10)

Testing Your Sproutcore Presentation
Testing Your Sproutcore PresentationTesting Your Sproutcore Presentation
Testing Your Sproutcore Presentation
 
Intro to jQuery - LUGOR - Part 1
Intro to jQuery - LUGOR - Part 1Intro to jQuery - LUGOR - Part 1
Intro to jQuery - LUGOR - Part 1
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days Toronto
 
Sprout core for publishers
Sprout core for publishersSprout core for publishers
Sprout core for publishers
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
 
Appnovation One Sheet
Appnovation One SheetAppnovation One Sheet
Appnovation One Sheet
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Writing Fast Client-Side Code: Lessons Learned from SproutCore
Writing Fast Client-Side Code: Lessons Learned from SproutCoreWriting Fast Client-Side Code: Lessons Learned from SproutCore
Writing Fast Client-Side Code: Lessons Learned from SproutCore
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Using Open Technologies to Enable Digital Transformation in the Enterprise
Using Open Technologies to Enable Digital Transformation in the EnterpriseUsing Open Technologies to Enable Digital Transformation in the Enterprise
Using Open Technologies to Enable Digital Transformation in the Enterprise
 

Similar to SproutCore: Amber

Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
Angel Ruiz
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
guest5d87aa6
 
7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages
Salesforce Developers
 

Similar to SproutCore: Amber (20)

Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJS
 
Spiffy Applications With JavaScript
Spiffy Applications With JavaScriptSpiffy Applications With JavaScript
Spiffy Applications With JavaScript
 
Diigo
DiigoDiigo
Diigo
 
With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solr
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
WordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp ChicagoWordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp Chicago
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Rendering SEO Manifesto - Why we need to go beyond JavaScript SEO
Rendering SEO Manifesto - Why we need to go beyond JavaScript SEORendering SEO Manifesto - Why we need to go beyond JavaScript SEO
Rendering SEO Manifesto - Why we need to go beyond JavaScript SEO
 
Proposed PHP function: is_literal()
Proposed PHP function: is_literal()Proposed PHP function: is_literal()
Proposed PHP function: is_literal()
 
Testing at Both Ends of the Triangle.
Testing at Both Ends of the Triangle.Testing at Both Ends of the Triangle.
Testing at Both Ends of the Triangle.
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009
 

More from Yehuda Katz (13)

Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
Organizing jQuery Projects Without OO
Organizing jQuery Projects Without OOOrganizing jQuery Projects Without OO
Organizing jQuery Projects Without OO
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Making your oss project more like rails
Making your oss project more like railsMaking your oss project more like rails
Making your oss project more like rails
 
Vaporware To Awesome
Vaporware To AwesomeVaporware To Awesome
Vaporware To Awesome
 
Merb Day Keynote
Merb Day KeynoteMerb Day Keynote
Merb Day Keynote
 
Testing Merb
Testing MerbTesting Merb
Testing Merb
 
Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
Merb Camp Keynote
Merb Camp KeynoteMerb Camp Keynote
Merb Camp Keynote
 
Merb
MerbMerb
Merb
 
DataMapper
DataMapperDataMapper
DataMapper
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web Frameworks
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

SproutCore: Amber